From 72ec4e980b5a0b40df96cee9060efd8652b52960 Mon Sep 17 00:00:00 2001 From: Packit Service Date: Dec 09 2020 23:29:39 +0000 Subject: Changes after running %prep ignore: true --- diff --git a/buildtools/makeman b/buildtools/makeman index dc8e45c..0a373f3 100755 --- a/buildtools/makeman +++ b/buildtools/makeman @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/libexec/platform-python # # makeman -- compile netpbm's stereotyped HTML to troff markup # diff --git a/converter/other/jbig/libjbig/ANNOUNCE b/converter/other/jbig/libjbig/ANNOUNCE deleted file mode 100644 index 15ce550..0000000 --- a/converter/other/jbig/libjbig/ANNOUNCE +++ /dev/null @@ -1,172 +0,0 @@ - -JBIG-KIT lossless image compression library -------------------------------------------- - -by Markus Kuhn - - -The latest release of JBIG-KIT can be downloaded from - - http://www.cl.cam.ac.uk/~mgk25/jbigkit/ - -JBIG-KIT implements a highly effective data compression algorithm for -bi-level high-resolution images such as fax pages or scanned -documents. - -JBIG-KIT provides two variants of a portable library of compression -and decompression functions with a documented interface. You can very -easily include into your image or document processing software. In -addition, JBIG-KIT provides ready-to-use compression and decompression -programs with a simple command line interface (similar to the -converters found in Jef Poskanzer's PBM graphics file conversion -package). - -JBIG-KIT implements the specification - - International Standard ISO/IEC 11544:1993 and ITU-T Recommendation - T.82(1993), "Information technology - Coded representation of picture - and audio information - progressive bi-level image compression", - , - -which is commonly referred to as the "JBIG1 standard". JBIG (Joint -Bi-level Image experts Group) is the committee which developed this -international standard for the lossless compression of images using -arithmetic coding. Like the well-known compression algorithms JPEG and -MPEG, JBIG has also been developed and published by the International -Organization for Standardization (ISO) and the International -Telecommunication Union (ITU). See also - - http://www.jpeg.org/jbig/ - http://www.iso.ch/ - http://www.itu.int/ - -The JBIG compression algorithm offers the following features: - - - Close to state-of-the-art lossless compression ratio for high - resolution bi-level images. - - - About 1.1 to 1.5 times better compression ratio on typical - scanned documents compared to G4 fax compression (ITU-T T.6), - which has been the best compression algorithm for scanned - documents available prior to JBIG. - - - Up to 30 times better compression of scanned images with dithered - images compared to G4 fax compression. - - - About 2 times better compression on typical 300 dpi documents - compared to 'gzip -9' on raw bitmaps. - - - About 3-4 times better compression than GIF on typical 300 dpi - documents. - - - Even much better competitive compression results on computer - generated images which are free of scanning distortions. - - - JBIG supports hierarchical "progressive" encoding, that means it is - possible to encode a low resolution image first, followed by - resolution enhancement data. This allows, for instance, a document - browser to display already a good 75 dpi low resolution version of - an image, while the data necessary to reconstruct the full 300 dpi - version for laser printer reproduction is still arriving (say - over a slow network link or mass storage medium). - - - The various resolution layers of a JBIG image in progressive - encoding mode together require not much more space than a - normal non-progressive mode encoded image (which JBIG also - supports). - - - The progressive encoding mode utilizes a quite sophisticated - resolution reduction algorithm which offers high quality low - resolution versions that preserve the shape of characters as well - as the integrity of thin lines and dithered images. - - - JBIG supports multiple bit planes and can this way also be used - for grayscale and color images, although the main field of - application is compression of bi-level images, i.e. images with - only two different pixel values. For grayscale images with up to - 6 bit per pixel, JBIG performs superior to JPEG's lossless - mode. - -JBIG-KIT can be used as free software under the GNU General Public -License. Other license arrangements more suitable for commercial -applications are available as well, please contact the author for -details. JBIG-KIT provides two portable libraries implemented in -ANSI/ISO C for encoding and decoding JBIG data streams, along with -documentation. The first library, jbig.c, implements nearly all of the -options that the JBIG standard provides, but keeps the entire -uncompressed image in memory. The second library, jbig85.c, implements -only the ITU-R T.85 subset of the standard that black/white fax -machines use (single bit per pixel, no "progressive" encoding), and -keeps only three lines of the uncompressed image in memory, making it -particularly attractive for low-memory embedded applications. - -The libraries are not intended for 8-bit or 16-bit machine -architectures (e.g., old MS-DOS C compilers). For maximum performance, -a 32-bit processor is required (64-bit systems work too, of course). -On architectures with 16-bit pointer arithmetic, the full-featured -jbig.c library can process only very small images. - -Special features of the full-featured jbig.c variant: - - - Fully reentrant multithread-capable design (no global or static - variables, isolated malloc()/free() calls, etc.) - - - Capable of handling incomplete and growing JBIG data streams in - order to allow earliest display of low resolution versions - - - Capable of handling several incoming data streams simultaneously - in one single process and thread - - - Especially designed with applications in mind that want to display - incoming data as early as possible (e.g., similar to the way in - which Netscape Navigator handles incoming GIF images) - - - Implements all JBIG features and options including progressive and - sequential encoding, multiple bit planes, user specified - resolution reduction and deterministic prediction tables, adaptive - template changes for optimal performance on half-tone images, - deterministic prediction, typical prediction in lowest and - differential layers, various stripe orderings, etc; only the SEQ - and HITOLO options are currently not supported by the decoder - (they are normally never required, but could be added later in - case of user requirements) - - - Suitable for fax applications, satisfies ITU-T T.85 profile - - - Efficient code, optimized utilization of 32-bit processor - registers - - - Very easy to use documented C library interface - - - Included Gray code conversion routines for efficient encoding - of grayscale images - - - Ready-to-use pbmtojbg and jbgtopbm converters. - -Special features of the light-weight jbig85.c variant: - - - Suitable for low-memory embedded applications - - - Implements only the JBIG1 subset defined in the ITU-T T.85 - profile (single bit plane, no differential layers) - - - Requires only three pixel rows of the uncompressed image to be - kept in memory - - - Handles all NEWLEN modes of operation required by ITU-T T.85 with - just a single pass over the data, automatically performing the - necessary lookahead after the last stripe - - - Codec buffers only a few bytes of arithmetic-codec data and outputs - resulting bytes or lines as soon as they are available. - -I will try to provide free support and maintenance for this software -for the foreseeable future, depending on my available time. - -Happy compressing ... - -Markus Kuhn - --- -Markus Kuhn, Computer Laboratory, University of Cambridge -http://www.cl.cam.ac.uk/~mgk25/ || CB3 0FD, Great Britain diff --git a/converter/other/jbig/libjbig/COPYING b/converter/other/jbig/libjbig/COPYING deleted file mode 100644 index a43ea21..0000000 --- a/converter/other/jbig/libjbig/COPYING +++ /dev/null @@ -1,339 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 675 Mass Ave, Cambridge, MA 02139, USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -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 Program or any portion -of it, thus forming a work based on the Program, 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) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -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 Program, 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 Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) 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; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, 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 executable. However, as a -special exception, the source code 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. - -If distribution of executable or 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 counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program 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. - - 5. 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 Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program 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 to -this License. - - 7. 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 Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program 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 Program. - -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. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program 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. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies 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 Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, 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 - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. 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 PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - Appendix: How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) 19yy - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 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., 675 Mass Ave, Cambridge, MA 02139, USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) 19yy name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/converter/other/jbig/libjbig/Makefile b/converter/other/jbig/libjbig/Makefile deleted file mode 100644 index 2e57490..0000000 --- a/converter/other/jbig/libjbig/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -ifeq ($(SRCDIR)x,x) - SRCDIR = $(CURDIR)/../../../.. - BUILDDIR = $(SRCDIR) -endif -SUBDIR = converter/other/jbig/libjbig -VPATH=.:$(SRCDIR)/$(SUBDIR) - -include $(BUILDDIR)/config.mk - -LIBJBIG_OBJECTS = jbig.o jbig_ar.o - -OBJECTS = $(LIBJBIG_OBJECTS) -MERGE_OBJECTS = $(LIBJBIG_OBJECTS) - -COMP_INCLUDES = -I$(SRCDIR)/$(SUBDIR)/include - -all: libjbig.a - -include $(SRCDIR)/common.mk - -libjbig.a: $(LIBJBIG_OBJECTS) - $(AR) -rc $@ $^ - $(RANLIB) $@ - diff --git a/converter/other/jbig/libjbig/include/jbig.h b/converter/other/jbig/libjbig/include/jbig.h deleted file mode 100644 index 6799410..0000000 --- a/converter/other/jbig/libjbig/include/jbig.h +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Header file for the portable JBIG compression library - * - * Copyright 1995-2014 -- Markus Kuhn -- http://www.cl.cam.ac.uk/~mgk25/ - */ - -#ifndef JBG_H -#define JBG_H - -#include -#include "jbig_ar.h" - -/* - * JBIG-KIT version number - */ - -#define JBG_VERSION "2.1" -#define JBG_VERSION_MAJOR 2 -#define JBG_VERSION_MINOR 1 - -/* - * JBIG-KIT licence agreement reference code: - * If you use JBIG-KIT under a commercial licence, please replace - * below the letters GPL with the reference code that you received - * with your licence agreement. (This code is typically a letter "A" - * followed by four decimal digits, e.g. "A1234".) - */ - -#define JBG_LICENCE "GPL" - -/* - * Buffer block for SDEs which are temporarily stored by encoder - */ - -#define JBG_BUFSIZE 4000 - -struct jbg_buf { - unsigned char d[JBG_BUFSIZE]; /* one block of a buffer list */ - int len; /* length of the data in this block */ - struct jbg_buf *next; /* pointer to next block */ - struct jbg_buf *previous; /* pointer to previous block * - * (unused in freelist) */ - struct jbg_buf *last; /* only used in list head: final block of list */ - struct jbg_buf **free_list; /* pointer to pointer to head of free list */ -}; - -/* - * Maximum number of ATMOVEs per stripe that decoder can handle - */ - -#define JBG_ATMOVES_MAX 64 - -/* - * Option and order flags - */ - -#define JBG_HITOLO 0x08 -#define JBG_SEQ 0x04 -#define JBG_ILEAVE 0x02 -#define JBG_SMID 0x01 - -#define JBG_LRLTWO 0x40 -#define JBG_VLENGTH 0x20 -#define JBG_TPDON 0x10 -#define JBG_TPBON 0x08 -#define JBG_DPON 0x04 -#define JBG_DPPRIV 0x02 -#define JBG_DPLAST 0x01 - -/* encoding options that will not be indicated in the header */ - -#define JBG_DELAY_AT 0x100 /* Delay ATMOVE until the first line of the next - * stripe. Option available for compatibility - * with conformance test example in clause 7.2. */ - -#define JBG_SDRST 0x200 /* Use SDRST instead of SDNORM. This option is - * there for anyone who needs to generate - * test data that covers the SDRST cases. */ - -/* - * Possible error code return values - */ - -#define JBG_EOK (0 << 4) -#define JBG_EOK_INTR (1 << 4) -#define JBG_EAGAIN (2 << 4) -#define JBG_ENOMEM (3 << 4) -#define JBG_EABORT (4 << 4) -#define JBG_EMARKER (5 << 4) -#define JBG_EINVAL (6 << 4) -#define JBG_EIMPL (7 << 4) -#define JBG_ENOCONT (8 << 4) - -/* - * Status of a JBIG encoder - */ - -struct jbg_enc_state { - int d; /* resolution layer of the input image */ - unsigned long xd, yd; /* size of the input image (resolution layer d) */ - unsigned long yd1; /* BIH announced height of image, use yd1 != yd to - emulate T.85-style NEWLEN height updates for tests */ - int planes; /* number of different bitmap planes */ - int dl; /* lowest resolution layer in the next BIE */ - int dh; /* highest resolution layer in the next BIE */ - unsigned long l0; /* number of lines per stripe at lowest * - * resolution layer 0 */ - unsigned long stripes; /* number of stripes required (determ. by l0) */ - unsigned char **lhp[2]; /* pointers to lower/higher resolution images */ - int *highres; /* index [plane] of highres image in lhp[] */ - int order; /* SDE ordering parameters */ - int options; /* encoding parameters */ - unsigned mx, my; /* maximum ATMOVE window size */ - int *tx; /* array [plane] with x-offset of adaptive template pixel */ - char *dppriv; /* optional private deterministic prediction table */ - char *res_tab; /* table for the resolution reduction algorithm */ - struct jbg_buf ****sde; /* array [stripe][layer][plane] pointers to * - * buffers for stored SDEs */ - struct jbg_arenc_state *s; /* array [planes] for arithm. encoder status */ - struct jbg_buf *free_list; /* list of currently unused SDE block buffers */ - void (*data_out)(unsigned char *start, size_t len, void *file); - /* data write callback */ - void *file; /* parameter passed to data_out() */ - char *tp; /* buffer for temp. values used by diff. typical prediction */ - unsigned char *comment; /* content of comment marker segment to be added - at next opportunity (will be reset to NULL - as soon as comment has been written) */ - unsigned long comment_len; /* length of data pointed to by comment */ -}; - - -/* - * Status of a JBIG decoder - */ - -struct jbg_dec_state { - /* data from BIH */ - int d; /* resolution layer of the full image */ - int dl; /* first resolution layer in this BIE */ - unsigned long xd, yd; /* size of the full image (resolution layer d) */ - int planes; /* number of different bitmap planes */ - unsigned long l0; /* number of lines per stripe at lowest * - * resolution layer 0 */ - unsigned long stripes; /* number of stripes required (determ. by l0) */ - int order; /* SDE ordering parameters */ - int options; /* encoding parameters */ - int mx, my; /* maximum ATMOVE window size */ - char *dppriv; /* optional private deterministic prediction table */ - - /* loop variables */ - unsigned long ii[3]; /* current stripe, layer, plane (outer loop first) */ - - /* - * Pointers to array [planes] of lower/higher resolution images. - * lhp[d & 1] contains image of layer d. - */ - unsigned char **lhp[2]; - - /* status information */ - int **tx, **ty; /* array [plane][layer-dl] with x,y-offset of AT pixel */ - struct jbg_ardec_state **s; /* array [plane][layer-dl] for arithmetic * - * decoder status */ - int **reset; /* array [plane][layer-dl] remembers if previous stripe * - * in that plane/resolution ended with SDRST. */ - unsigned long bie_len; /* number of bytes read so far */ - unsigned char buffer[20]; /* used to store BIH or marker segments fragm. */ - int buf_len; /* number of bytes in buffer */ - unsigned long comment_skip; /* remaining bytes of a COMMENT segment */ - unsigned long x; /* x position of next pixel in current SDE */ - unsigned long i; /* line in current SDE (first line of each stripe is 0) */ - int at_moves; /* number of AT moves in the current stripe */ - unsigned long at_line[JBG_ATMOVES_MAX]; /* lines at which an * - * AT move will happen */ - int at_tx[JBG_ATMOVES_MAX], at_ty[JBG_ATMOVES_MAX]; /* ATMOVE offsets in * - * current stripe */ - unsigned long line_h1, line_h2, line_h3; /* variables of decode_pscd */ - unsigned long line_l1, line_l2, line_l3; - int pseudo; /* flag for TPBON/TPDON: next pixel is pseudo pixel */ - int **lntp; /* flag [plane][layer-dl] for TP: line is not typical */ - - unsigned long xmax, ymax; /* if possible abort before image gets * - * larger than this size */ - int dmax; /* abort after this layer */ -}; - - -/* some macros (too trivial for a function) */ - -#define jbg_dec_getplanes(s) ((s)->planes) - - -/* function prototypes */ - -void jbg_enc_init(struct jbg_enc_state *s, unsigned long x, unsigned long y, - int planes, unsigned char **p, - void (*data_out)(unsigned char *start, size_t len, - void *file), - void *file); -int jbg_enc_lrlmax(struct jbg_enc_state *s, unsigned long mwidth, - unsigned long mheight); -void jbg_enc_layers(struct jbg_enc_state *s, int d); -int jbg_enc_lrange(struct jbg_enc_state *s, int dl, int dh); -void jbg_enc_options(struct jbg_enc_state *s, int order, int options, - unsigned long l0, int mx, int my); -void jbg_enc_out(struct jbg_enc_state *s); -void jbg_enc_free(struct jbg_enc_state *s); - -void jbg_dec_init(struct jbg_dec_state *s); -void jbg_dec_maxsize(struct jbg_dec_state *s, unsigned long xmax, - unsigned long ymax); -int jbg_dec_in(struct jbg_dec_state *s, unsigned char *data, size_t len, - size_t *cnt); -unsigned long jbg_dec_getwidth(const struct jbg_dec_state *s); -unsigned long jbg_dec_getheight(const struct jbg_dec_state *s); -unsigned char *jbg_dec_getimage(const struct jbg_dec_state *s, int plane); -unsigned long jbg_dec_getsize(const struct jbg_dec_state *s); -void jbg_dec_merge_planes(const struct jbg_dec_state *s, int use_graycode, - void (*data_out)(unsigned char *start, size_t len, - void *file), void *file); -unsigned long jbg_dec_getsize_merged(const struct jbg_dec_state *s); -void jbg_dec_free(struct jbg_dec_state *s); - -const char *jbg_strerror(int errnum); -void jbg_int2dppriv(unsigned char *dptable, const char *internal); -void jbg_dppriv2int(char *internal, const unsigned char *dptable); -unsigned long jbg_ceil_half(unsigned long x, int n); -void jbg_split_planes(unsigned long x, unsigned long y, int has_planes, - int encode_planes, - const unsigned char *src, unsigned char **dest, - int use_graycode); -int jbg_newlen(unsigned char *bie, size_t len); - -#endif /* JBG_H */ diff --git a/converter/other/jbig/libjbig/include/jbig_ar.h b/converter/other/jbig/libjbig/include/jbig_ar.h deleted file mode 100644 index d58b1ae..0000000 --- a/converter/other/jbig/libjbig/include/jbig_ar.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Header file for the arithmetic encoder and decoder of - * the portable JBIG compression library - * - * Markus Kuhn -- http://www.cl.cam.ac.uk/~mgk25/jbigkit/ - */ - -#ifndef JBG_AR_H -#define JBG_AR_H - -/* - * Status of arithmetic encoder - */ - -struct jbg_arenc_state { - unsigned char st[4096]; /* probability status for contexts, MSB = MPS */ - unsigned long c; /* register C: base of coding intervall, * - * layout as in Table 23 */ - unsigned long a; /* register A: normalized size of coding interval */ - long sc; /* number of buffered 0xff values that might still overflow */ - int ct; /* bit shift counter, determines when next byte will be written */ - int buffer; /* buffer for most recent output byte != 0xff */ - void (*byte_out)(int, void *); /* function that receives all PSCD bytes */ - void *file; /* parameter passed to byte_out */ -}; - -/* - * Status of arithmetic decoder - */ - -struct jbg_ardec_state { - unsigned char st[4096]; /* probability status for contexts, MSB = MPS */ - unsigned long c; /* register C: base of coding intervall, * - * layout as in Table 25 */ - unsigned long a; /* register A: normalized size of coding interval */ - unsigned char *pscd_ptr; /* pointer to next PSCD data byte */ - unsigned char *pscd_end; /* pointer to byte after PSCD */ - int ct; /* bit-shift counter, determines when next byte will be read; - * special value -1 signals that zero-padding has started */ - int startup; /* boolean flag that controls initial fill of s->c */ - int nopadding; /* boolean flag that triggers return -2 between - * reaching PSCD end and decoding the first symbol - * that might never have been encoded in the first - * place */ -}; - -void arith_encode_init(struct jbg_arenc_state *s, int reuse_st); -void arith_encode_flush(struct jbg_arenc_state *s); -void arith_encode(struct jbg_arenc_state *s, int cx, int pix); -void arith_decode_init(struct jbg_ardec_state *s, int reuse_st); -int arith_decode(struct jbg_ardec_state *s, int cx); - -#endif /* JBG_AR_H */ diff --git a/converter/other/jbig/libjbig/jbig.c b/converter/other/jbig/libjbig/jbig.c deleted file mode 100644 index ba9c645..0000000 --- a/converter/other/jbig/libjbig/jbig.c +++ /dev/null @@ -1,3283 +0,0 @@ -/* - * Portable JBIG image compression library - * - * Copyright 1995-2014 -- Markus Kuhn -- http://www.cl.cam.ac.uk/~mgk25/ - * - * This module implements a portable standard C encoder and decoder - * using the JBIG1 lossless bi-level image compression algorithm - * specified in International Standard ISO 11544:1993 and - * ITU-T Recommendation T.82. See the file jbig.txt for usage - * instructions and application examples. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 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., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * If you want to use this program under different license conditions, - * then contact the author for an arrangement. - */ - -#ifdef DEBUG -#include -#endif - -#include -#include -#include - -#include "jbig.h" - -#define MX_MAX 127 - /* maximal mx offset for adaptive template in the encoder */ - -#define TPB2CX 0x195 /* contexts for TP special pixels */ -#define TPB3CX 0x0e5 -#define TPDCX 0xc3f - -/* marker codes */ -#define MARKER_STUFF 0x00 -#define MARKER_RESERVE 0x01 -#define MARKER_SDNORM 0x02 -#define MARKER_SDRST 0x03 -#define MARKER_ABORT 0x04 -#define MARKER_NEWLEN 0x05 -#define MARKER_ATMOVE 0x06 -#define MARKER_COMMENT 0x07 -#define MARKER_ESC 0xff - -/* loop array indices */ -#define STRIPE 0 -#define LAYER 1 -#define PLANE 2 - -/* special jbg_buf pointers (instead of NULL) */ -#define SDE_DONE ((struct jbg_buf *) -1) -#define SDE_TODO ((struct jbg_buf *) 0) - -/* object code version id */ - -const char jbg_version[] = - "JBIG-KIT " JBG_VERSION " -- (c) 1995-2014 Markus Kuhn -- " - "Licence: " JBG_LICENCE "\n"; - -/* - * The following array specifies for each combination of the 3 - * ordering bits, which ii[] variable represents which dimension - * of s->sde. - */ -static const int iindex[8][3] = { - { 2, 1, 0 }, /* no ordering bit set */ - { -1, -1, -1}, /* SMID -> illegal combination */ - { 2, 0, 1 }, /* ILEAVE */ - { 1, 0, 2 }, /* SMID + ILEAVE */ - { 0, 2, 1 }, /* SEQ */ - { 1, 2, 0 }, /* SEQ + SMID */ - { 0, 1, 2 }, /* SEQ + ILEAVE */ - { -1, -1, -1 } /* SEQ + SMID + ILEAVE -> illegal combination */ -}; - -#define _(String) String /* to mark translatable string for GNU gettext */ - -/* - * Array with English ASCII error messages that correspond - * to return values from public functions in this library. - */ -static const char *errmsg[] = { - _("All OK"), /* JBG_EOK */ - _("Reached specified image size"), /* JBG_EOK_INTR */ - _("Unexpected end of input data stream"), /* JBG_EAGAIN */ - _("Not enough memory available"), /* JBG_ENOMEM */ - _("ABORT marker segment encountered"), /* JBG_EABORT */ - _("Unknown marker segment encountered"), /* JBG_EMARKER */ - _("Input data stream contains invalid data"), /* JBG_EINVAL */ - _("Input data stream uses unimplemented JBIG features"), /* JBG_EIMPL */ - _("Incremental BIE does not continue previous one") /* JBG_ENOCONT */ -}; - - -/* - * The following three functions are the only places in this code, were - * C library memory management functions are called. The whole JBIG - * library has been designed in order to allow multi-threaded - * execution. No static or global variables are used, so all fuctions - * are fully reentrant. However if you want to use this multi-thread - * capability and your malloc, realloc and free are not reentrant, - * then simply add the necessary semaphores or mutex primitives below. - * In contrast to C's malloc() and realloc(), but like C's calloc(), - * these functions take two parameters nmemb and size that are multiplied - * before being passed on to the corresponding C function. - * This we can catch all overflows during a size_t multiplication a - * a single place. - */ - -#ifndef SIZE_MAX -#define SIZE_MAX ((size_t) -1) /* largest value of size_t */ -#endif - -static void *checked_malloc(size_t nmemb, size_t size) -{ - void *p; - - /* Full manual exception handling is ugly here for performance - * reasons. If an adequate handling of lack of memory is required, - * then use C++ and throw a C++ exception instead of abort(). */ - - /* assert that nmemb * size <= SIZE_MAX */ - if (size > SIZE_MAX / nmemb) - abort(); - - p = malloc(nmemb * size); - - if (!p) - abort(); - -#if 0 - fprintf(stderr, "%p = malloc(%lu * %lu)\n", p, - (unsigned long) nmemb, (unsigned long) size); -#endif - - return p; -} - - -static void *checked_realloc(void *ptr, size_t nmemb, size_t size) -{ - void *p; - - /* Full manual exception handling is ugly here for performance - * reasons. If an adequate handling of lack of memory is required, - * then use C++ and throw a C++ exception here instead of abort(). */ - - /* assert that nmemb * size <= SIZE_MAX */ - if (size > SIZE_MAX / nmemb) - abort(); - - p = realloc(ptr, nmemb * size); - - if (!p) - abort(); - -#if 0 - fprintf(stderr, "%p = realloc(%p, %lu * %lu)\n", p, ptr, - (unsigned long) nmemb, (unsigned long) size); -#endif - - return p; -} - - -static void checked_free(void *ptr) -{ - free(ptr); - -#if 0 - fprintf(stderr, "free(%p)\n", ptr); -#endif - -} - - - - -/* - * Memory management for buffers which are used for temporarily - * storing SDEs by the encoder. - * - * The following functions manage a set of struct jbg_buf storage - * containers were each can keep JBG_BUFSIZE bytes. The jbg_buf - * containers can be linked to form linear double-chained lists for - * which a number of operations are provided. Blocks which are - * tempoarily not used any more are returned to a freelist which each - * encoder keeps. Only the destructor of the encoder actually returns - * the block via checked_free() to the stdlib memory management. - */ - - -/* - * Allocate a new buffer block and initialize it. Try to get it from - * the free_list, and if it is empty, call checked_malloc(). - */ -static struct jbg_buf *jbg_buf_init(struct jbg_buf **free_list) -{ - struct jbg_buf *new_block; - - /* Test whether a block from the free list is available */ - if (*free_list) { - new_block = *free_list; - *free_list = new_block->next; - } else { - /* request a new memory block */ - new_block = (struct jbg_buf *) checked_malloc(1, sizeof(struct jbg_buf)); - } - new_block->len = 0; - new_block->next = NULL; - new_block->previous = NULL; - new_block->last = new_block; - new_block->free_list = free_list; - - return new_block; -} - - -/* - * Return an entire free_list to the memory management of stdlib. - * This is only done by jbg_enc_free(). - */ -static void jbg_buf_free(struct jbg_buf **free_list) -{ - struct jbg_buf *tmp; - - while (*free_list) { - tmp = (*free_list)->next; - checked_free(*free_list); - *free_list = tmp; - } - - return; -} - - -/* - * Append a single byte to a single list that starts with the block - * *(struct jbg_buf *) head. The type of *head is void here in order to - * keep the interface of the arithmetic encoder gereric, which uses this - * function as a call-back function in order to deliver single bytes - * for a PSCD. - */ -static void jbg_buf_write(int b, void *head) -{ - struct jbg_buf *now; - - now = ((struct jbg_buf *) head)->last; - if (now->len < JBG_BUFSIZE - 1) { - now->d[now->len++] = b; - return; - } - now->next = jbg_buf_init(((struct jbg_buf *) head)->free_list); - now->next->previous = now; - now->next->d[now->next->len++] = b; - ((struct jbg_buf *) head)->last = now->next; - - return; -} - - -/* - * Remove any trailing zero bytes from the end of a linked jbg_buf list, - * however make sure that no zero byte is removed which directly - * follows a 0xff byte (i.e., keep MARKER_ESC MARKER_STUFF sequences - * intact). This function is used to remove any redundant final zero - * bytes from a PSCD. - */ -static void jbg_buf_remove_zeros(struct jbg_buf *head) -{ - struct jbg_buf *last; - - while (1) { - /* remove trailing 0x00 in last block of list until this block is empty */ - last = head->last; - while (last->len && last->d[last->len - 1] == 0) - last->len--; - /* if block became really empty, remove it in case it is not the - * only remaining block and then loop to next block */ - if (last->previous && !last->len) { - head->last->next = *head->free_list; - *head->free_list = head->last; - head->last = last->previous; - head->last->next = NULL; - } else - break; - } - - /* - * If the final non-zero byte is 0xff (MARKER_ESC), then we just have - * removed a MARKER_STUFF and we will append it again now in order - * to preserve PSCD status of byte stream. - */ - if (head->last->len && head->last->d[head->last->len - 1] == MARKER_ESC) - jbg_buf_write(MARKER_STUFF, head); - - return; -} - - -/* - * The jbg_buf list which starts with block *new_prefix is concatenated - * with the list which starts with block **start and *start will then point - * to the first block of the new list. - */ -static void jbg_buf_prefix(struct jbg_buf *new_prefix, struct jbg_buf **start) -{ - new_prefix->last->next = *start; - new_prefix->last->next->previous = new_prefix->last; - new_prefix->last = new_prefix->last->next->last; - *start = new_prefix; - - return; -} - - -/* - * Send the contents of a jbg_buf list that starts with block **head to - * the call back function data_out and return the blocks of the jbg_buf - * list to the freelist from which these jbg_buf blocks have been taken. - * After the call, *head == NULL. - */ -static void jbg_buf_output(struct jbg_buf **head, - void (*data_out)(unsigned char *start, - size_t len, void *file), - void *file) -{ - struct jbg_buf *tmp; - - while (*head) { - data_out((*head)->d, (*head)->len, file); - tmp = (*head)->next; - (*head)->next = *(*head)->free_list; - *(*head)->free_list = *head; - *head = tmp; - } - - return; -} - - -/* - * Calculate y = ceil(x/2) applied n times, which is equivalent to - * y = ceil(x/(2^n)). This function is used to - * determine the number of pixels per row or column after n resolution - * reductions. E.g. X[d-1] = jbg_ceil_half(X[d], 1) and X[0] = - * jbg_ceil_half(X[d], d) as defined in clause 6.2.3 of T.82. - */ -unsigned long jbg_ceil_half(unsigned long x, int n) -{ - unsigned long mask; - - assert(n >= 0 && n < 32); - mask = (1UL << n) - 1; /* the lowest n bits are 1 here */ - return (x >> n) + ((mask & x) != 0); -} - - -/* - * Set L0 (the number of lines in a stripe at lowest resolution) - * to a default value, such that there are about 35 stripes, as - * suggested in Annex C of ITU-T T.82, without exceeding the - * limit 128/2^D suggested in Annex A. - */ -static void jbg_set_default_l0(struct jbg_enc_state *s) -{ - s->l0 = jbg_ceil_half(s->yd, s->d) / 35; /* 35 stripes/image */ - while ((s->l0 << s->d) > 128) /* but <= 128 lines/stripe */ - --s->l0; - if (s->l0 < 2) s->l0 = 2; -} - - -/* - * Calculate the number of stripes, as defined in clause 6.2.3 of T.82. - */ -static unsigned long jbg_stripes(unsigned long l0, unsigned long yd, - unsigned long d) -{ - unsigned long y0 = jbg_ceil_half(yd, d); - - return y0 / l0 + (y0 % l0 != 0); -} - - -/* - * Resolution reduction table given by ITU-T T.82 Table 17 - */ - -static char jbg_resred[4096] = { - 0,0,0,1,0,0,0,1,0,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,0,1,1,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1, - 0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1, - 0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1, - 1,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,0,1,0,0,0,1,1,0,0,0,0,0,1,0,1,0,0,1,1,1,0,1,1, - 0,0,0,1,0,0,0,1,0,0,1,0,0,0,1,1,0,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,1,1,1,0,1,0,1,0,0,1,1,1,0,1,1,0,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,0,1,0,1,0,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,0,1,0,1,0,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1, - 1,0,0,1,0,0,1,1,0,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1, - 0,0,1,1,0,0,0,1,0,0,0,1,0,0,1,1,0,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,1,0,1,1,0,1,1,1,1,1,1,0,1,1,1,0, - 0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,1,0,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1, - 0,0,0,1,0,0,0,1,0,1,1,0,1,0,1,1,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1, - 1,1,1,0,1,0,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1, - 1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,0,1,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,1,1,1,1,1,1, - 0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,1,1,1,0,1,0,1,0,1,1,0,1,0,1,1,0,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,0,1,0,1,0,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,1,1,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,1,0,1,0,0,1,0,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,1,0,0,1,1,1,1,1,1,0,1,1,1,1,0,1,1, - 1,0,0,1,0,0,1,0,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0, - 0,0,1,0,1,1,1,1,0,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0, - 0,0,0,0,1,0,0,1,0,0,1,1,0,1,1,1,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,1,1,0,1,0,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,0,1,1,1,0,1,0,1,0,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1, - 0,0,1,0,0,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,1, - 0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,1,0,0,1,0,0,1,1, - 0,0,0,0,0,0,0,1,0,1,1,1,0,1,0,1,0,0,1,0,0,0,0,1,0,1,0,1,0,1,0,1, - 0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,1,0,0,0,0,0,0,0,1,1,1,1,0,1,1,1, - 0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,1,0,1,0,1,1,0,0,0,1,0,0,1,1, - 0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,1,1,1,0,0,1,1, - 0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1, - 0,0,1,0,0,1,1,1,0,0,0,0,1,0,0,1,0,0,0,1,1,1,1,0,1,0,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,1,0, - 0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,1,1,1,0,1,1,1, - 0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,1,1,0,1,0,0,0,1,1,0,1,0,0,0,0,1,1,1,1,0,0,1,1,1,0,1,1,0,0,1,1, - 0,0,0,0,0,0,0,0,1,1,0,1,0,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1, - 0,0,1,1,0,0,1,1,0,0,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,1,0,0,0,1,0,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1, - 0,0,0,1,0,0,1,0,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,0,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1, - 0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,0,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1, - 0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1, - 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,0,1,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,1,1,0,1,1, - 0,0,0,1,0,0,0,1,0,0,1,0,0,0,1,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,1,1,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1,1,1,0,1,1,1, - 0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1, - 0,0,0,0,1,0,0,1,0,0,1,1,0,0,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1, - 1,0,1,0,1,0,0,1,1,0,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,0,1,1,0,1,1,1, - 0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,1,1,0,1,1,0,1,1,1,1, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,1,0,1,0,1,0,1,1,0,1,0,1,0,0,0,1,1,1,1,1,1,1,1,1, - 1,1,1,0,1,0,0,0,1,1,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1, - 1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,0,1,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,1,1,0,1,1, - 0,0,1,1,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,1,0,0,1,1,0,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,1,1,1,0,1,0,1,0,0,1,0,1,0,0,1,0,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,1,0,1,0,0,0,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1, - 1,0,0,0,1,0,0,0,0,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,1,1,1,0,1,1,0, - 0,0,1,1,1,1,1,1,0,0,0,0,1,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,1,1,0,1,1,1,1,1,1,1, - 0,0,0,0,1,0,0,0,0,0,0,1,0,0,1,1,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1, - 0,0,1,0,1,0,1,1,0,0,1,0,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1, - 0,0,1,0,1,0,1,1,0,1,1,1,1,1,1,1,0,0,1,1,1,0,1,1,0,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,1, - 0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1, - 0,0,0,0,0,0,0,1,0,1,1,1,0,1,0,1,0,0,1,0,0,0,0,1,0,1,0,1,0,1,0,1, - 0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,1,0,1,0,0,1,1, - 0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,0,1,0,0,1,0,0,0,0,0,0,0,1, - 0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,1, - 0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,1,1, - 1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,1,1,0,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0, - 0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,1, - 0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1, - 0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1, - 0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,1,0,0,0,1,0,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,1, - 0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,0,0,0,1,1,0,0,0,1,0,1,1,1,0,1,1,1 -}; - -/* - * Deterministic prediction tables given by ITU-T T.82 tables - * 19 to 22. The table below is organized differently, the - * index bits are permutated for higher efficiency. - */ - -static char jbg_dptable[256 + 512 + 2048 + 4096] = { - /* phase 0: offset=0 */ - 0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2, - 0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,2,2,2,2,2,2,0,2,2,2,2,2,2,2, - 0,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,2,2,2,2,2,2,0,2,0,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - /* phase 1: offset=256 */ - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2, - 0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,2,2,2,2,2,0,2,0,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2, - 0,2,2,2,2,1,2,1,2,2,2,2,1,1,1,1,2,0,2,0,2,2,2,2,0,2,0,2,2,2,2,2, - 0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,2,2,2,2,0,2,2,2,2,2,2,2, - 0,2,0,2,2,2,2,2,2,2,2,2,2,0,2,0,2,2,0,0,2,2,2,2,2,0,0,2,2,2,2,2, - 0,2,2,2,2,1,2,1,2,2,2,2,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1, - 1,2,1,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,1,1,2,2,2,2,2,0,2,2,2,2,2,2, - 2,2,2,2,2,0,2,0,2,2,2,2,0,0,0,0,0,2,0,2,2,2,2,2,0,2,2,2,2,2,2,2, - 0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,0,2,2,2,2,0,2,0,2,2,2,2,2, - 2,2,2,2,2,1,1,1,2,2,2,2,1,1,1,1,1,2,1,2,2,2,2,2,2,2,2,2,2,2,2,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,0,1,2,0,2,0,2,2,2,2,2,0,2,0,2,2,2,2,1, - 0,2,0,2,2,1,2,1,2,2,2,2,1,1,1,1,0,0,0,0,2,2,2,2,0,2,0,2,2,2,2,1, - 2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,2,2,0,0,0,2,2,2,2,2, - 2,2,2,2,2,1,2,1,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2,1,2,1,2,2,2,2,1, - 2,2,2,2,2,2,2,2,0,2,0,2,2,1,2,2,2,2,2,2,2,2,2,2,0,0,0,2,2,2,2,2, - /* phase 2: offset=768 */ - 2,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,2,2,2,2,1,1,1,1, - 0,2,2,2,2,1,2,1,2,2,2,2,1,2,1,2,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1, - 2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,0,2,2,1,2,1,2,2,2,2,2,1,1,1, - 2,0,2,2,2,1,2,1,0,2,2,2,1,2,1,2,2,2,2,0,2,2,2,2,0,2,0,2,2,2,2,2, - 0,2,0,0,1,1,1,1,2,2,2,2,1,1,1,1,0,2,0,2,1,1,1,1,2,2,2,2,1,1,1,1, - 2,2,0,2,2,2,1,2,2,2,2,2,1,2,1,2,2,2,0,2,2,1,2,1,0,2,0,2,1,1,1,1, - 2,0,0,2,2,2,2,2,0,2,0,2,2,0,2,0,2,0,2,0,2,2,2,1,2,2,0,2,1,1,2,1, - 2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,2,2,2,2,1,1,1,1, - 0,0,0,0,2,2,2,2,0,0,0,0,2,2,2,2,0,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,0,2,2,2,2,1,0,2,2,2,1,1,1,1,2,0,2,2,2,2,2,2,0,2,0,2,2,1,2,1, - 2,0,2,0,2,2,2,2,0,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,2,2, - 0,2,2,2,1,2,1,2,2,2,2,2,2,2,2,2,0,2,2,2,2,2,1,2,2,2,2,2,2,2,2,2, - 2,2,0,2,2,2,2,2,2,2,2,2,2,2,0,2,2,0,0,2,2,1,2,1,0,2,2,2,1,1,1,1, - 2,2,2,0,2,2,2,2,2,2,0,2,2,0,2,0,2,1,2,2,2,2,2,2,1,2,1,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,0,2,2,2,1, - 0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,2,1,1,1,2,2,2,2,1,1,1,1, - 2,2,2,1,2,2,2,2,2,2,1,2,0,0,0,0,2,2,0,2,2,1,2,2,2,2,2,2,1,1,1,1, - 2,0,0,0,2,2,2,2,0,2,2,2,2,2,2,0,2,2,2,0,2,2,2,2,2,0,0,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,0,2,2,1,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,1, - 0,2,0,2,2,1,1,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2, - 2,0,2,0,2,1,2,1,0,2,0,2,2,2,1,2,2,0,2,0,2,2,2,2,0,2,0,2,2,2,1,2, - 2,2,2,0,2,2,2,2,2,2,0,2,2,2,2,2,2,2,1,2,2,2,2,2,2,0,1,2,2,2,2,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1, - 0,2,2,2,1,2,1,2,2,2,2,2,2,2,2,2,0,2,2,2,2,2,1,2,2,2,2,2,2,2,2,2, - 2,0,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,2,2,1,2,1,0,2,2,2,1,1,1,1, - 2,0,2,0,2,1,2,2,0,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,0,2,2,1,2,2, - 2,0,2,2,2,2,2,2,2,0,2,2,2,2,2,2,2,0,2,0,2,2,2,2,0,0,0,0,2,1,2,1, - 2,2,2,2,2,2,2,0,2,2,2,2,2,2,2,0,2,2,2,2,2,1,2,0,0,2,2,2,1,2,2,2, - 0,0,2,0,2,2,2,2,0,2,0,2,2,0,2,0,1,1,1,2,2,2,2,2,2,2,2,2,2,1,1,1, - 2,2,2,2,2,2,2,2,2,0,2,2,2,2,2,1,2,2,2,2,2,2,2,2,2,0,2,0,2,2,2,1, - 2,2,0,0,2,2,2,2,2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,2,2,2,2,1,1,1,1, - 0,2,2,2,1,2,1,2,2,2,2,2,2,2,2,2,0,2,2,2,2,2,1,2,2,2,2,2,2,2,2,2, - 2,0,0,2,2,2,2,2,0,2,0,2,2,2,2,2,1,0,1,2,2,2,2,1,0,2,2,2,1,1,1,1, - 2,2,2,2,2,2,2,2,2,2,0,2,2,0,2,0,2,1,2,2,2,2,2,2,2,2,0,2,2,1,2,2, - 0,2,0,0,1,1,1,1,0,2,2,2,1,1,1,1,2,2,2,2,2,2,2,2,2,0,2,2,1,2,1,1, - 2,2,0,2,2,1,2,2,2,2,2,2,1,2,2,2,2,0,2,2,2,2,2,2,0,2,0,2,1,2,1,1, - 2,0,2,0,2,2,2,2,0,2,0,2,2,1,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,1, - 2,2,2,2,2,2,2,2,2,0,2,2,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1, - 0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 0,2,2,2,2,0,2,0,2,2,2,2,0,0,0,0,2,2,2,2,2,1,1,2,2,2,2,2,1,2,2,2, - 2,0,2,2,2,1,2,1,0,2,2,2,2,2,1,2,2,0,2,0,2,2,2,2,0,2,0,2,2,1,2,2, - 0,2,0,0,2,2,2,2,1,2,2,2,2,2,2,0,2,1,2,2,2,2,2,2,1,2,2,2,2,2,2,2, - 0,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,2,1,0,2,2, - 0,0,0,2,2,1,1,1,2,2,2,2,1,2,2,2,2,0,2,0,2,2,2,1,2,2,2,2,1,2,1,2, - 0,0,0,0,2,2,2,2,2,2,0,2,2,1,2,2,2,1,2,1,2,2,2,2,1,2,1,2,0,2,2,2, - 2,0,2,0,2,2,2,2,2,0,2,2,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1, - 0,2,2,2,1,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,1,2,2,2,2,2,0,2,2,1,2,2,0,0,0,2,2,2,2,2,1,2,2,0,2,2,2,1,2,1,2, - 2,0,2,0,2,2,2,2,0,2,0,2,2,1,2,2,0,2,0,0,2,2,2,2,2,2,2,2,2,1,2,2, - 2,2,2,2,2,2,2,2,2,0,2,2,2,2,2,1,2,2,2,2,2,2,2,2,2,0,2,0,2,2,2,1, - 1,2,0,2,2,1,2,1,2,2,2,2,1,2,2,2,2,0,2,0,2,2,2,2,2,0,2,2,1,1,1,1, - 0,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,0,2,2,1,2,1, - 2,2,0,0,2,2,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1, - 2,2,2,0,2,2,2,2,2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,1,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,2, - 2,0,2,0,2,2,2,2,2,1,1,2,2,2,2,2,2,2,2,2,2,2,2,1,0,2,0,2,2,2,1,2, - 2,0,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2, - 2,0,2,0,2,2,2,2,2,0,2,0,2,2,2,2,2,0,2,0,2,2,2,2,0,0,0,0,2,1,2,1, - 2,2,2,2,2,1,2,1,0,2,0,2,2,2,2,2,2,0,2,0,2,2,2,2,0,2,0,2,2,2,2,1, - 2,0,2,0,2,2,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,0, - 2,0,2,0,2,2,2,1,2,2,2,0,2,2,2,1,2,0,2,0,2,2,2,2,0,0,0,2,2,2,2,1, - 2,0,2,0,2,2,2,2,2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,2, - /* phase 3: offset=2816 */ - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1, - 0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,1,2,1,2,0,2,0,1,2,1,2,0,2,0,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,0,2,2,2,1,2,0,2,2,2,1,2,2,2,2,0,2,0,2,1,2,1,0,0,0,0,1,1,1,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,0,2,2,2,1,2, - 2,2,2,1,2,2,2,0,1,1,1,1,0,0,0,0,2,2,2,2,2,2,2,2,2,0,2,0,2,1,2,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,0,0,0,0,1,1,1,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,0,2,1,2,1,0,0,0,0,1,1,1,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,1,2,0,2,0,2, - 2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,0,2,0,2,1,2,1,2,0,2,0,2,1,2,1, - 2,0,0,0,2,1,1,1,0,0,0,0,1,1,1,1,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2, - 2,0,2,2,2,1,2,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,0,0,2,0,1,1,2,1, - 2,2,2,0,2,2,2,1,2,1,2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1, - 0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,2,0,2,0,2,1,2,1,0,0,0,0,1,1,1,1, - 2,0,0,2,2,1,1,2,2,2,2,2,2,2,2,2,2,1,2,1,2,0,2,0,2,1,1,1,2,0,0,0, - 2,1,2,1,2,0,2,0,1,2,1,2,0,2,0,2,2,2,2,0,2,2,2,1,2,0,2,0,2,1,2,1, - 2,0,2,0,2,1,2,1,0,0,0,0,1,1,1,1,2,2,2,2,2,2,2,2,2,0,2,0,2,1,2,1, - 2,2,2,2,2,2,2,2,2,0,0,0,2,1,1,1,2,2,2,2,2,2,2,2,2,0,2,0,2,1,2,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2, - 0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2, - 2,0,0,0,2,1,1,1,0,0,0,0,1,1,1,1,2,0,2,0,2,1,2,1,0,0,2,0,1,1,2,1, - 2,2,1,2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,0,0,0,2,1,1,1, - 2,2,2,1,2,2,2,0,2,1,1,1,2,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,1,2,1,2,0,2,0,1,2,1,2,0,2,0,2, - 2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1, - 2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,2,1,1,1,0,0,0,0,1,1,1,1, - 2,0,2,2,2,1,2,2,0,0,2,0,1,1,2,1,2,1,2,1,2,0,2,0,2,2,2,2,2,2,2,2, - 2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,0,0,0,0,1,1,1,1, - 2,0,0,0,2,1,1,1,0,0,0,0,1,1,1,1,2,2,2,2,2,2,2,2,2,1,0,2,2,0,1,2, - 2,2,2,1,2,2,2,0,2,1,1,1,2,0,0,0,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1, - 2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1, - 0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,0,2,2,2,2,2,2,2,2,2,2, - 2,1,2,1,2,0,2,0,1,2,1,1,0,2,0,0,0,0,2,1,1,1,2,0,0,0,0,0,1,1,1,1, - 2,2,2,2,2,2,2,2,1,2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,0,2,1,2,1,2,0,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,0,2,2,2,1,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,1,2,2,2,0,2,2,2,2,0,2,2,2,1,2,2,2,0,0,2,2,1,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2, - 0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,0,2,2,2,2,2,2,2,2,2, - 2,0,2,0,2,1,2,1,0,0,0,0,1,1,1,1,2,2,2,2,2,2,2,2,0,0,0,0,1,1,1,1, - 2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,0,0,0,2,1,1,1, - 2,2,2,0,2,2,2,1,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2, - 2,0,2,2,2,1,2,2,2,0,2,0,2,1,2,1,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1, - 2,1,2,1,2,0,2,0,1,2,1,2,0,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,1,2,1,2,0,2,0,1,2,1,1,0,2,0,0,2,0,2,2,2,1,2,2,0,2,1,2,1,2,0,2, - 2,2,2,1,2,2,2,0,2,2,1,2,2,2,0,2,2,1,2,2,2,0,2,2,2,2,0,2,2,2,1,2, - 0,0,2,0,1,1,2,1,0,0,1,0,1,1,0,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,0,2,2,2,1,1,2,2,2,0,2,2,2,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1, - 2,2,2,2,2,2,2,2,2,1,2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1, - 2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,0,0,2,2,1,1,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2, - 0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,0,2,2,2,2,2,2,2,2,2, - 2,0,0,0,2,1,1,1,0,0,0,0,1,1,1,1,2,2,2,1,2,2,2,0,2,1,2,1,2,0,2,0, - 2,1,2,2,2,0,2,2,2,2,2,2,2,2,2,2,0,2,0,0,1,2,1,1,2,0,0,0,2,1,1,1, - 2,2,2,2,2,2,2,2,2,1,1,1,2,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,0,2,2,2,1,2,2,0,2,2,2,1,2,2,1,2,1,2,0,2,0,2,0,2,2,2,1,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,0,2,2,2,1,1,1,2,0,0,0, - 2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,0,2,0,0,1,2,1,1, - 2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,0,2,2,2,1,2,2,2, - 2,1,2,1,2,0,2,0,2,1,2,2,2,0,2,2,2,2,2,0,2,2,2,1,2,0,2,0,2,1,2,1, - 2,0,2,0,2,1,2,1,0,2,0,2,1,2,1,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2, - 2,2,2,2,2,2,2,2,0,2,0,2,1,2,1,2,2,2,2,2,2,2,2,2,0,1,0,0,1,0,1,1, - 2,2,2,2,2,2,2,2,2,1,2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,2,2,1,2,2,2,0,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,1,2,2,1,0,2,0,2,2,2,1,2,2,2, - 2,2,2,2,2,2,2,2,1,2,2,2,0,2,2,2,2,2,2,0,2,2,2,1,2,2,0,2,2,2,1,2, - 2,0,2,0,2,1,2,1,0,2,0,2,1,2,1,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2, - 0,2,0,0,1,2,1,1,2,0,0,0,2,1,1,1,2,2,2,2,2,2,2,2,1,0,1,2,0,1,0,2, - 2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,2,1,2,2,2,0,2,2,1,1,2,2,0,0,2,2, - 0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,1,2,1,2,0,2,0,2,1,2,2,2,0,2,2,2,0,2,2,2,1,2,2,0,2,2,2,1,2,2,2, - 0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,1,2,2,2,0,2,2,2, - 2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,0,2,1,2,1,2, - 0,0,0,0,1,1,1,1,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,1,2,0,2,0,2,2,0,2,2,2,1,2, - 2,0,2,0,2,1,2,1,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2, - 0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,1,2,2,2,0,1,1,2,1,0,0,2,0,2,0,2,2,2,1,2,2,0,2,2,2,1,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,0,2,2,2,2,0,2,2,2,1,2, - 2,0,2,0,2,1,2,1,0,2,0,2,1,2,1,2,2,2,2,2,2,2,2,2,2,1,2,2,2,0,2,2, - 0,2,0,0,1,2,1,1,0,2,0,2,1,2,1,2,2,2,2,2,2,2,2,2,0,0,0,2,1,1,1,2, - 2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1, - 2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,0,0,2,1,1,1,2,0,0,2,2,2,1,2,2,2, - 2,1,2,1,2,0,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,0,0,1,2,1,1, - 0,0,2,2,1,1,2,2,0,2,1,2,1,2,0,2,2,1,2,1,2,0,2,0,1,2,1,2,0,2,0,2, - 2,2,2,2,2,2,2,2,1,2,1,2,0,2,0,2,2,2,2,2,2,2,2,2,2,0,2,0,2,1,2,1, - 2,2,0,0,2,2,1,1,2,2,0,0,2,2,1,1,2,2,2,2,2,2,2,2,2,2,0,0,2,2,1,1, - 2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,0,2,0,0,1,2,1,1, - 2,2,2,0,2,2,2,1,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,1,1,1,2,0,0,0,2, - 2,2,2,2,2,2,2,2,1,1,1,2,0,0,0,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,2, - 2,0,2,0,2,1,2,1,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,0,0,0,2,1,1,1, - 2,0,2,2,2,1,2,2,0,2,2,2,1,2,2,2,2,0,2,0,2,1,2,1,2,2,2,2,2,2,2,2, - 2,0,2,0,2,1,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,0,2,0,2,1,2,1,2,1,2,0,2,0,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,0,2,0,2,1,2,1,1,2,1,2,0,2,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,1,2,1,2,0,2,0,2,2,1,2,1,2,0,2,0,2,2,2,2,2,2,2,2, - 2,0,2,1,2,1,2,0,0,2,1,2,1,2,0,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1, - 2,0,2,0,2,1,2,1,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,0,2,0,2,1,2,1, - 2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,1,2,1,2,0,2,0,1,1,1,2,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1, - 2,0,2,0,2,1,2,1,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, -}; - - -/* - * Initialize the status struct for the encoder. - */ -void jbg_enc_init(struct jbg_enc_state *s, unsigned long x, unsigned long y, - int planes, unsigned char **p, - void (*data_out)(unsigned char *start, size_t len, - void *file), - void *file) -{ - unsigned long l, lx; - int i; - - assert(x > 0 && y > 0 && planes > 0 && planes < 256); - s->xd = x; - s->yd = y; - s->yd1 = y; /* This is the hight initially announced in BIH. To provoke - generation of NEWLEN for T.85 compatibility tests, - overwrite with new value s->yd1 > s->yd */ - s->planes = planes; - s->data_out = data_out; - s->file = file; - - s->d = 0; - s->dl = 0; - s->dh = s->d; - jbg_set_default_l0(s); - s->mx = 8; - s->my = 0; - s->order = JBG_ILEAVE | JBG_SMID; - s->options = JBG_TPBON | JBG_TPDON | JBG_DPON; - s->comment = NULL; - s->dppriv = jbg_dptable; - s->res_tab = jbg_resred; - - s->highres = (int *) checked_malloc(planes, sizeof(int)); - s->lhp[0] = p; - s->lhp[1] = (unsigned char **) - checked_malloc(planes, sizeof(unsigned char *)); - for (i = 0; i < planes; i++) { - s->highres[i] = 0; - s->lhp[1][i] = (unsigned char *) - checked_malloc(jbg_ceil_half(y, 1), jbg_ceil_half(x, 1+3)); - } - - s->free_list = NULL; - s->s = (struct jbg_arenc_state *) - checked_malloc(s->planes, sizeof(struct jbg_arenc_state)); - s->tx = (int *) checked_malloc(s->planes, sizeof(int)); - lx = jbg_ceil_half(x, 1); - s->tp = (char *) checked_malloc(lx, sizeof(char)); - for (l = 0; l < lx; s->tp[l++] = 2) ; - s->sde = NULL; - - return; -} - - -/* - * This function selects the number of differential layers based on - * the maximum size requested for the lowest resolution layer. If - * possible, a number of differential layers is selected, which will - * keep the size of the lowest resolution layer below or equal to the - * given width x and height y. However not more than 6 differential - * resolution layers will be used. In addition, a reasonable value for - * l0 (height of one stripe in the lowest resolution layer) is - * selected, which obeys the recommended limitations for l0 in annex A - * and C of the JBIG standard. The selected number of resolution layers - * is returned. - */ -int jbg_enc_lrlmax(struct jbg_enc_state *s, unsigned long x, - unsigned long y) -{ - for (s->d = 0; s->d < 6; s->d++) - if (jbg_ceil_half(s->xd, s->d) <= x && jbg_ceil_half(s->yd, s->d) <= y) - break; - s->dl = 0; - s->dh = s->d; - jbg_set_default_l0(s); - return s->d; -} - - -/* - * As an alternative to jbg_enc_lrlmax(), the following function allows - * to specify the number of layers directly. The stripe height and layer - * range is also adjusted automatically here. - */ -void jbg_enc_layers(struct jbg_enc_state *s, int d) -{ - if (d < 0 || d > 31) - return; - s->d = d; - s->dl = 0; - s->dh = s->d; - jbg_set_default_l0(s); - return; -} - - -/* - * Specify the highest and lowest resolution layers which will be - * written to the output file. Call this function not before - * jbg_enc_layers() or jbg_enc_lrlmax(), because these two functions - * reset the lowest and highest resolution layer to default values. - * Negative values are ignored. The total number of layers is returned. - */ -int jbg_enc_lrange(struct jbg_enc_state *s, int dl, int dh) -{ - if (dl >= 0 && dl <= s->d) s->dl = dl; - if (dh >= s->dl && dh <= s->d) s->dh = dh; - - return s->d; -} - - -/* - * The following function allows to specify the bits describing the - * options of the format as well as the maximum AT movement window and - * the number of layer 0 lines per stripes. - */ -void jbg_enc_options(struct jbg_enc_state *s, int order, int options, - unsigned long l0, int mx, int my) -{ - if (order >= 0 && order <= 0x0f) s->order = order; - if (options >= 0) s->options = options; - if (l0 > 0) s->l0 = l0; - if (mx >= 0 && mx < 128) s->mx = mx; - if (my >= 0 && my < 256) s->my = my; - - return; -} - - -/* - * This function actually does all the tricky work involved in producing - * a SDE, which is stored in the appropriate s->sde[][][] element - * for later output in the correct order. - */ -static void encode_sde(struct jbg_enc_state *s, - long stripe, int layer, int plane) -{ - unsigned char *hp, *lp1, *lp2, *p0, *p1, *q1, *q2; - unsigned long hl, ll, hx, hy, lx, ly, hbpl, lbpl; - unsigned long line_h0 = 0, line_h1 = 0; - unsigned long line_h2, line_h3, line_l1, line_l2, line_l3; - struct jbg_arenc_state *se; - unsigned long y; /* current line number in highres image */ - unsigned long i; /* current line number within highres stripe */ - unsigned long j; /* current column number in highres image */ - long o; - unsigned a, p, t; - int ltp, ltp_old, cx; - unsigned long c_all, c[MX_MAX + 1], cmin, cmax, clmin, clmax; - int tmax, at_determined; - int new_tx; - long new_tx_line = -1; - int reset; - struct jbg_buf *new_jbg_buf; - -#ifdef DEBUG - static long tp_lines, tp_exceptions, tp_pixels, dp_pixels; - static long encoded_pixels; -#endif - - /* return immediately if this stripe has already been encoded */ - if (s->sde[stripe][layer][plane] != SDE_TODO) - return; - -#ifdef DEBUG - if (stripe == 0) - tp_lines = tp_exceptions = tp_pixels = dp_pixels = encoded_pixels = 0; - fprintf(stderr, "encode_sde: s/d/p = %2ld/%2d/%2d\n", - stripe, layer, plane); -#endif - - /* number of lines per stripe in highres image */ - hl = s->l0 << layer; - /* number of lines per stripe in lowres image */ - ll = hl >> 1; - /* current line number in highres image */ - y = stripe * hl; - /* number of pixels in highres image */ - hx = jbg_ceil_half(s->xd, s->d - layer); - hy = jbg_ceil_half(s->yd, s->d - layer); - /* number of pixels in lowres image */ - lx = jbg_ceil_half(hx, 1); - ly = jbg_ceil_half(hy, 1); - /* bytes per line in highres and lowres image */ - hbpl = jbg_ceil_half(hx, 3); - lbpl = jbg_ceil_half(lx, 3); - /* pointer to first image byte of highres stripe */ - hp = s->lhp[s->highres[plane]][plane] + stripe * hl * hbpl; - lp2 = s->lhp[1 - s->highres[plane]][plane] + stripe * ll * lbpl; - lp1 = lp2 + lbpl; - - /* check whether we can refer to any state of a previous stripe */ - reset = (stripe == 0) || (s->options & JBG_SDRST); - - /* initialize arithmetic encoder */ - se = s->s + plane; - arith_encode_init(se, !reset); - s->sde[stripe][layer][plane] = jbg_buf_init(&s->free_list); - se->byte_out = jbg_buf_write; - se->file = s->sde[stripe][layer][plane]; - - /* initialize adaptive template movement algorithm */ - c_all = 0; - for (t = 0; t <= s->mx; t++) - c[t] = 0; - if (stripe == 0) /* the SDRST case is handled at the end */ - s->tx[plane] = 0; - new_tx = -1; - at_determined = 0; /* we haven't yet decided the template move */ - if (s->mx == 0) - at_determined = 1; - - /* initialize typical prediction */ - ltp = 0; - if (reset) - ltp_old = 0; - else { - ltp_old = 1; - p1 = hp - hbpl; - if (y > 1) { - q1 = p1 - hbpl; - while (p1 < hp && (ltp_old = (*p1++ == *q1++)) != 0) ; - } else - while (p1 < hp && (ltp_old = (*p1++ == 0)) != 0) ; - } - - if (layer == 0) { - - /* - * Encode lowest resolution layer - */ - - for (i = 0; i < hl && y < hy; i++, y++) { - - /* check whether it is worth to perform an ATMOVE */ - if (!at_determined && c_all > 2048) { - cmin = clmin = 0xffffffffL; - cmax = clmax = 0; - tmax = 0; - for (t = (s->options & JBG_LRLTWO) ? 5 : 3; t <= s->mx; t++) { - if (c[t] > cmax) cmax = c[t]; - if (c[t] < cmin) cmin = c[t]; - if (c[t] > c[tmax]) tmax = t; - } - clmin = (c[0] < cmin) ? c[0] : cmin; - clmax = (c[0] > cmax) ? c[0] : cmax; - if (c_all - cmax < (c_all >> 3) && - cmax - c[s->tx[plane]] > c_all - cmax && - cmax - c[s->tx[plane]] > (c_all >> 4) && - /* ^ T.82 said < here, fixed in Cor.1/25 */ - cmax - (c_all - c[s->tx[plane]]) > c_all - cmax && - cmax - (c_all - c[s->tx[plane]]) > (c_all >> 4) && - cmax - cmin > (c_all >> 2) && - (s->tx[plane] || clmax - clmin > (c_all >> 3))) { - /* we have decided to perform an ATMOVE */ - new_tx = tmax; - if (!(s->options & JBG_DELAY_AT)) { - new_tx_line = i; - s->tx[plane] = new_tx; - } -#ifdef DEBUG - fprintf(stderr, "ATMOVE: line=%ld, tx=%d, c_all=%ld\n", - i, new_tx, c_all); -#endif - } - at_determined = 1; - } - assert(s->tx[plane] >= 0); /* i.e., tx can safely be cast to unsigned */ - - /* typical prediction */ - if (s->options & JBG_TPBON) { - ltp = 1; - p1 = hp; - if (i > 0 || !reset) { - q1 = hp - hbpl; - while (q1 < hp && (ltp = (*p1++ == *q1++)) != 0) ; - } else - while (p1 < hp + hbpl && (ltp = (*p1++ == 0)) != 0) ; - arith_encode(se, (s->options & JBG_LRLTWO) ? TPB2CX : TPB3CX, - ltp == ltp_old); -#ifdef DEBUG - tp_lines += ltp; -#endif - ltp_old = ltp; - if (ltp) { - /* skip next line */ - hp += hbpl; - continue; - } - } - - /* - * Layout of the variables line_h1, line_h2, line_h3, which contain - * as bits the neighbour pixels of the currently coded pixel X: - * - * 76543210765432107654321076543210 line_h3 - * 76543210765432107654321076543210 line_h2 - * 76543210765432107654321X76543210 line_h1 - */ - - line_h1 = line_h2 = line_h3 = 0; - if (i > 0 || !reset) line_h2 = (long)*(hp - hbpl) << 8; - if (i > 1 || !reset) line_h3 = (long)*(hp - hbpl - hbpl) << 8; - - /* encode line */ - for (j = 0; j < hx; hp++) { - line_h1 |= *hp; - if (j < hbpl * 8 - 8 && (i > 0 || !reset)) { - line_h2 |= *(hp - hbpl + 1); - if (i > 1 || !reset) - line_h3 |= *(hp - hbpl - hbpl + 1); - } - if (s->options & JBG_LRLTWO) { - /* two line template */ - do { - line_h1 <<= 1; line_h2 <<= 1; line_h3 <<= 1; - if (s->tx[plane]) { - if ((unsigned) s->tx[plane] > j) - a = 0; - else { - o = (j - s->tx[plane]) - (j & ~7L); - a = (hp[o >> 3] >> (7 - (o & 7))) & 1; - a <<= 4; - } - assert(s->tx[plane] > 23 || - a == ((line_h1 >> (4 + s->tx[plane])) & 0x010)); - arith_encode(se, (((line_h2 >> 10) & 0x3e0) | a | - ((line_h1 >> 9) & 0x00f)), - (line_h1 >> 8) & 1); - } - else - arith_encode(se, (((line_h2 >> 10) & 0x3f0) | - ((line_h1 >> 9) & 0x00f)), - (line_h1 >> 8) & 1); -#ifdef DEBUG - encoded_pixels++; -#endif - /* statistics for adaptive template changes */ - if (!at_determined && j >= s->mx && j < hx-2) { - p = (line_h1 & 0x100) != 0; /* current pixel value */ - c[0] += ((line_h2 & 0x4000) != 0) == p; /* default position */ - assert(!(((line_h2 >> 6) ^ line_h1) & 0x100) == - (((line_h2 & 0x4000) != 0) == p)); - for (t = 5; t <= s->mx && t <= j; t++) { - o = (j - t) - (j & ~7L); - a = (hp[o >> 3] >> (7 - (o & 7))) & 1; - assert(t > 23 || - (a == p) == !(((line_h1 >> t) ^ line_h1) & 0x100)); - c[t] += a == p; - } - for (; t <= s->mx; t++) { - c[t] += 0 == p; - } - ++c_all; - } - } while (++j & 7 && j < hx); - } else { - /* three line template */ - do { - line_h1 <<= 1; line_h2 <<= 1; line_h3 <<= 1; - if (s->tx[plane]) { - if ((unsigned) s->tx[plane] > j) - a = 0; - else { - o = (j - s->tx[plane]) - (j & ~7L); - a = (hp[o >> 3] >> (7 - (o & 7))) & 1; - a <<= 2; - } - assert(s->tx[plane] > 23 || - a == ((line_h1 >> (6 + s->tx[plane])) & 0x004)); - arith_encode(se, (((line_h3 >> 8) & 0x380) | - ((line_h2 >> 12) & 0x078) | a | - ((line_h1 >> 9) & 0x003)), - (line_h1 >> 8) & 1); - } else - arith_encode(se, (((line_h3 >> 8) & 0x380) | - ((line_h2 >> 12) & 0x07c) | - ((line_h1 >> 9) & 0x003)), - (line_h1 >> 8) & 1); -#ifdef DEBUG - encoded_pixels++; -#endif - /* statistics for adaptive template changes */ - if (!at_determined && j >= s->mx && j < hx-2) { - p = (line_h1 & 0x100) != 0; /* current pixel value */ - c[0] += ((line_h2 & 0x4000) != 0) == p; /* default position */ - assert(!(((line_h2 >> 6) ^ line_h1) & 0x100) == - (((line_h2 & 0x4000) != 0) == p)); - for (t = 3; t <= s->mx && t <= j; t++) { - o = (j - t) - (j & ~7L); - a = (hp[o >> 3] >> (7 - (o & 7))) & 1; - assert(t > 23 || - (a == p) == !(((line_h1 >> t) ^ line_h1) & 0x100)); - c[t] += a == p; - } - for (; t <= s->mx; t++) { - c[t] += 0 == p; - } - ++c_all; - } - } while (++j & 7 && j < hx); - } /* if (s->options & JBG_LRLTWO) */ - } /* for (j = ...) */ - } /* for (i = ...) */ - - } else { - - /* - * Encode differential layer - */ - - for (i = 0; i < hl && y < hy; i++, y++) { - - /* check whether it is worth to perform an ATMOVE */ - if (!at_determined && c_all > 2048) { - cmin = clmin = 0xffffffffL; - cmax = clmax = 0; - tmax = 0; - for (t = 3; t <= s->mx; t++) { - if (c[t] > cmax) cmax = c[t]; - if (c[t] < cmin) cmin = c[t]; - if (c[t] > c[tmax]) tmax = t; - } - clmin = (c[0] < cmin) ? c[0] : cmin; - clmax = (c[0] > cmax) ? c[0] : cmax; - if (c_all - cmax < (c_all >> 3) && - cmax - c[s->tx[plane]] > c_all - cmax && - cmax - c[s->tx[plane]] > (c_all >> 4) && - /* ^ T.82 said < here, fixed in Cor.1/25 */ - cmax - (c_all - c[s->tx[plane]]) > c_all - cmax && - cmax - (c_all - c[s->tx[plane]]) > (c_all >> 4) && - cmax - cmin > (c_all >> 2) && - (s->tx[plane] || clmax - clmin > (c_all >> 3))) { - /* we have decided to perform an ATMOVE */ - new_tx = tmax; - if (!(s->options & JBG_DELAY_AT)) { - new_tx_line = i; - s->tx[plane] = new_tx; - } -#ifdef DEBUG - fprintf(stderr, "ATMOVE: line=%ld, tx=%d, c_all=%ld\n", - i, new_tx, c_all); -#endif - } - at_determined = 1; - } - - if ((i >> 1) >= ll - 1 || (y >> 1) >= ly - 1) - lp1 = lp2; - - /* typical prediction */ - if (s->options & JBG_TPDON && (i & 1) == 0) { - q1 = lp1; q2 = lp2; - p0 = p1 = hp; - if (i < hl - 1 && y < hy - 1) - p0 = hp + hbpl; - if (i > 1 || !reset) - line_l3 = (long)*(q2 - lbpl) << 8; - else - line_l3 = 0; - line_l2 = (long)*q2 << 8; - line_l1 = (long)*q1 << 8; - ltp = 1; - for (j = 0; j < lx && ltp; q1++, q2++) { - if (j < lbpl * 8 - 8) { - if (i > 1 || !reset) - line_l3 |= *(q2 - lbpl + 1); - line_l2 |= *(q2 + 1); - line_l1 |= *(q1 + 1); - } - do { - if ((j >> 2) < hbpl) { - line_h1 = *(p1++); - line_h0 = *(p0++); - } - do { - line_l3 <<= 1; - line_l2 <<= 1; - line_l1 <<= 1; - line_h1 <<= 2; - line_h0 <<= 2; - cx = (((line_l3 >> 15) & 0x007) | - ((line_l2 >> 12) & 0x038) | - ((line_l1 >> 9) & 0x1c0)); - if (cx == 0x000) - if ((line_h1 & 0x300) == 0 && (line_h0 & 0x300) == 0) - s->tp[j] = 0; - else { - ltp = 0; -#ifdef DEBUG - tp_exceptions++; -#endif - } - else if (cx == 0x1ff) - if ((line_h1 & 0x300) == 0x300 && (line_h0 & 0x300) == 0x300) - s->tp[j] = 1; - else { - ltp = 0; -#ifdef DEBUG - tp_exceptions++; -#endif - } - else - s->tp[j] = 2; - } while (++j & 3 && j < lx); - } while (j & 7 && j < lx); - } /* for (j = ...) */ - arith_encode(se, TPDCX, !ltp); -#ifdef DEBUG - tp_lines += ltp; -#endif - } - - - /* - * Layout of the variables line_h1, line_h2, line_h3, which contain - * as bits the high resolution neighbour pixels of the currently coded - * highres pixel X: - * - * 76543210 76543210 76543210 76543210 line_h3 - * 76543210 76543210 76543210 76543210 line_h2 - * 76543210 76543210 7654321X 76543210 line_h1 - * - * Layout of the variables line_l1, line_l2, line_l3, which contain - * the low resolution pixels near the currently coded pixel as bits. - * The lowres pixel in which the currently coded highres pixel is - * located is marked as Y: - * - * 76543210 76543210 76543210 76543210 line_l3 - * 76543210 7654321Y 76543210 76543210 line_l2 - * 76543210 76543210 76543210 76543210 line_l1 - */ - - - line_h1 = line_h2 = line_h3 = line_l1 = line_l2 = line_l3 = 0; - if (i > 0 || !reset) line_h2 = (long)*(hp - hbpl) << 8; - if (i > 1 || !reset) { - line_h3 = (long)*(hp - hbpl - hbpl) << 8; - line_l3 = (long)*(lp2 - lbpl) << 8; - } - line_l2 = (long)*lp2 << 8; - line_l1 = (long)*lp1 << 8; - - /* encode line */ - for (j = 0; j < hx; lp1++, lp2++) { - if ((j >> 1) < lbpl * 8 - 8) { - if (i > 1 || !reset) - line_l3 |= *(lp2 - lbpl + 1); - line_l2 |= *(lp2 + 1); - line_l1 |= *(lp1 + 1); - } - do { /* ... while (j & 15 && j < hx) */ - - assert(hp - (s->lhp[s->highres[plane]][plane] + - (stripe * hl + i) * hbpl) - == (ptrdiff_t) j >> 3); - - assert(lp2 - (s->lhp[1-s->highres[plane]][plane] + - (stripe * ll + (i>>1)) * lbpl) - == (ptrdiff_t) j >> 4); - - line_h1 |= *hp; - if (j < hbpl * 8 - 8) { - if (i > 0 || !reset) { - line_h2 |= *(hp - hbpl + 1); - if (i > 1 || !reset) - line_h3 |= *(hp - hbpl - hbpl + 1); - } - } - do { /* ... while (j & 7 && j < hx) */ - line_l1 <<= 1; line_l2 <<= 1; line_l3 <<= 1; - if (ltp && s->tp[j >> 1] < 2) { - /* pixel are typical and have not to be encoded */ - line_h1 <<= 2; line_h2 <<= 2; line_h3 <<= 2; -#ifdef DEBUG - do { - ++tp_pixels; - } while (++j & 1 && j < hx); -#else - j += 2; -#endif - } else - do { /* ... while (++j & 1 && j < hx) */ - line_h1 <<= 1; line_h2 <<= 1; line_h3 <<= 1; - - /* deterministic prediction */ - if (s->options & JBG_DPON) { - if ((y & 1) == 0) { - if ((j & 1) == 0) { - /* phase 0 */ - if (s->dppriv[((line_l3 >> 16) & 0x003) | - ((line_l2 >> 14) & 0x00c) | - ((line_h1 >> 5) & 0x010) | - ((line_h2 >> 10) & 0x0e0)] < 2) { -#ifdef DEBUG - ++dp_pixels; -#endif - continue; - } - } else { - /* phase 1 */ - if (s->dppriv[(((line_l3 >> 16) & 0x003) | - ((line_l2 >> 14) & 0x00c) | - ((line_h1 >> 5) & 0x030) | - ((line_h2 >> 10) & 0x1c0)) + 256] < 2) { -#ifdef DEBUG - ++dp_pixels; -#endif - continue; - } - } - } else { - if ((j & 1) == 0) { - /* phase 2 */ - if (s->dppriv[(((line_l3 >> 16) & 0x003) | - ((line_l2 >> 14) & 0x00c) | - ((line_h1 >> 5) & 0x010) | - ((line_h2 >> 10) & 0x0e0) | - ((line_h3 >> 7) & 0x700)) + 768] < 2) { -#ifdef DEBUG - ++dp_pixels; -#endif - continue; - } - } else { - /* phase 3 */ - if (s->dppriv[(((line_l3 >> 16) & 0x003) | - ((line_l2 >> 14) & 0x00c) | - ((line_h1 >> 5) & 0x030) | - ((line_h2 >> 10) & 0x1c0) | - ((line_h3 >> 7) & 0xe00)) + 2816] < 2) { -#ifdef DEBUG - ++dp_pixels; -#endif - continue; - } - } - } - } - - /* determine context */ - if (s->tx[plane]) { - if ((unsigned) s->tx[plane] > j) - a = 0; - else { - o = (j - s->tx[plane]) - (j & ~7L); - a = (hp[o >> 3] >> (7 - (o & 7))) & 1; - a <<= 4; - } - assert(s->tx[plane] > 23 || - a == ((line_h1 >> (4 + s->tx[plane])) & 0x010)); - cx = (((line_h1 >> 9) & 0x003) | a | - ((line_h2 >> 13) & 0x00c) | - ((line_h3 >> 11) & 0x020)); - } else - cx = (((line_h1 >> 9) & 0x003) | - ((line_h2 >> 13) & 0x01c) | - ((line_h3 >> 11) & 0x020)); - if (j & 1) - cx |= (((line_l2 >> 9) & 0x0c0) | - ((line_l1 >> 7) & 0x300)) | (1UL << 10); - else - cx |= (((line_l2 >> 10) & 0x0c0) | - ((line_l1 >> 8) & 0x300)); - cx |= (y & 1) << 11; - - arith_encode(se, cx, (line_h1 >> 8) & 1); -#ifdef DEBUG - encoded_pixels++; -#endif - - /* statistics for adaptive template changes */ - if (!at_determined && j >= s->mx) { - c[0] += !(((line_h2 >> 6) ^ line_h1) & 0x100); - for (t = 3; t <= s->mx; t++) - c[t] += !(((line_h1 >> t) ^ line_h1) & 0x100); - ++c_all; - } - - } while (++j & 1 && j < hx); - } while (j & 7 && j < hx); - hp++; - } while (j & 15 && j < hx); - } /* for (j = ...) */ - - /* low resolution pixels are used twice */ - if ((i & 1) == 0) { - lp1 -= lbpl; - lp2 -= lbpl; - } - - } /* for (i = ...) */ - } - - arith_encode_flush(se); - jbg_buf_remove_zeros(s->sde[stripe][layer][plane]); - jbg_buf_write(MARKER_ESC, s->sde[stripe][layer][plane]); - jbg_buf_write((s->options & JBG_SDRST) ? MARKER_SDRST : MARKER_SDNORM, - s->sde[stripe][layer][plane]); - if (s->options & JBG_SDRST) - s->tx[plane] = 0; - - /* add ATMOVE */ - if (new_tx != -1) { - if (s->options & JBG_DELAY_AT) { - /* ATMOVE will become active at the first line of the next stripe */ - s->tx[plane] = new_tx; - jbg_buf_write(MARKER_ESC, s->sde[stripe][layer][plane]); - jbg_buf_write(MARKER_ATMOVE, s->sde[stripe][layer][plane]); - jbg_buf_write(0, s->sde[stripe][layer][plane]); - jbg_buf_write(0, s->sde[stripe][layer][plane]); - jbg_buf_write(0, s->sde[stripe][layer][plane]); - jbg_buf_write(0, s->sde[stripe][layer][plane]); - jbg_buf_write(s->tx[plane], s->sde[stripe][layer][plane]); - jbg_buf_write(0, s->sde[stripe][layer][plane]); - } else { - /* ATMOVE has already become active during this stripe - * => we have to prefix the SDE data with an ATMOVE marker */ - new_jbg_buf = jbg_buf_init(&s->free_list); - jbg_buf_write(MARKER_ESC, new_jbg_buf); - jbg_buf_write(MARKER_ATMOVE, new_jbg_buf); - jbg_buf_write((new_tx_line >> 24) & 0xff, new_jbg_buf); - jbg_buf_write((new_tx_line >> 16) & 0xff, new_jbg_buf); - jbg_buf_write((new_tx_line >> 8) & 0xff, new_jbg_buf); - jbg_buf_write(new_tx_line & 0xff, new_jbg_buf); - jbg_buf_write(new_tx, new_jbg_buf); - jbg_buf_write(0, new_jbg_buf); - jbg_buf_prefix(new_jbg_buf, &s->sde[stripe][layer][plane]); - } - } - -#if 0 - if (stripe == s->stripes - 1) - fprintf(stderr, "tp_lines = %ld, tp_exceptions = %ld, tp_pixels = %ld, " - "dp_pixels = %ld, encoded_pixels = %ld\n", - tp_lines, tp_exceptions, tp_pixels, dp_pixels, encoded_pixels); -#endif - - return; -} - - -/* - * Create the next lower resolution version of an image - */ -static void resolution_reduction(struct jbg_enc_state *s, int plane, - int higher_layer) -{ - unsigned long hl, ll, hx, hy, lx, ly, hbpl, lbpl; - unsigned char *hp1, *hp2, *hp3, *lp; - unsigned long line_h1, line_h2, line_h3, line_l2; - unsigned long y; /* current line number in lowres image */ - unsigned long i; /* current line number within lowres stripe */ - unsigned long j; /* current column number in lowres image */ - int pix, k, l; - - /* number of lines per stripe in highres image */ - hl = s->l0 << higher_layer; - /* number of lines per stripe in lowres image */ - ll = hl >> 1; - /* number of pixels in highres image */ - hx = jbg_ceil_half(s->xd, s->d - higher_layer); - hy = jbg_ceil_half(s->yd, s->d - higher_layer); - /* number of pixels in lowres image */ - lx = jbg_ceil_half(hx, 1); - ly = jbg_ceil_half(hy, 1); - /* bytes per line in highres and lowres image */ - hbpl = jbg_ceil_half(hx, 3); - lbpl = jbg_ceil_half(lx, 3); - /* pointers to first image bytes */ - hp2 = s->lhp[s->highres[plane]][plane]; - hp1 = hp2 + hbpl; - hp3 = hp2 - hbpl; - lp = s->lhp[1 - s->highres[plane]][plane]; - -#ifdef DEBUG - fprintf(stderr, "resolution_reduction: plane = %d, higher_layer = %d\n", - plane, higher_layer); -#endif - - /* - * Layout of the variables line_h1, line_h2, line_h3, which contain - * as bits the high resolution neighbour pixels of the currently coded - * lowres pixel /\: - * \/ - * - * 76543210 76543210 76543210 76543210 line_h3 - * 76543210 76543210 765432/\ 76543210 line_h2 - * 76543210 76543210 765432\/ 76543210 line_h1 - * - * Layout of the variable line_l2, which contains the low resolution - * pixels near the currently coded pixel as bits. The lowres pixel - * which is currently coded is marked as X: - * - * 76543210 76543210 76543210 76543210 line_l2 - * X - */ - - for (y = 0; y < ly;) { - for (i = 0; i < ll && y < ly; i++, y++) { - if (2*y + 1 >= hy) - hp1 = hp2; - pix = 0; - line_h1 = line_h2 = line_h3 = line_l2 = 0; - for (j = 0; j < lbpl * 8; j += 8) { - *lp = 0; - if (i > 0 || (y > 0 && !(s->options & JBG_SDRST))) - line_l2 |= *(lp-lbpl); - for (k = 0; k < 8 && j + k < lx; k += 4) { - if (((j + k) >> 2) < hbpl) { - if (i > 0 || (y > 0 && !(s->options & JBG_SDRST))) - line_h3 |= *hp3; - ++hp3; - line_h2 |= *(hp2++); - line_h1 |= *(hp1++); - } - for (l = 0; l < 4 && j + k + l < lx; l++) { - line_h3 <<= 2; - line_h2 <<= 2; - line_h1 <<= 2; - line_l2 <<= 1; - pix = s->res_tab[((line_h1 >> 8) & 0x007) | - ((line_h2 >> 5) & 0x038) | - ((line_h3 >> 2) & 0x1c0) | - (pix << 9) | ((line_l2 << 2) & 0xc00)]; - *lp = (*lp << 1) | pix; - } - } - ++lp; - } - *(lp - 1) <<= lbpl * 8 - lx; - hp1 += hbpl; - hp2 += hbpl; - hp3 += hbpl; - } - } - -#ifdef DEBUG - { - FILE *f; - char fn[50]; - - sprintf(fn, "dbg_d=%02d.pbm", higher_layer - 1); - f = fopen(fn, "wb"); - fprintf(f, "P4\n%lu %lu\n", lx, ly); - fwrite(s->lhp[1 - s->highres[plane]][plane], 1, lbpl * ly, f); - fclose(f); - } -#endif - - return; -} - - -/* - * This function is called inside the three loops of jbg_enc_out() in - * order to write the next SDE. It has first to generate the required - * SDE and all SDEs which have to be encoded before this SDE can be - * created. The problem here is that if we want to output a lower - * resolution layer, we have to apply the resolution reduction - * algorithm first to get it. As we try to safe as much memory as - * possible, the resolution reduction will overwrite previous higher - * resolution bitmaps. Consequently, we have to encode and buffer SDEs - * which depend on higher resolution layers before we can start the - * resolution reduction. All the logic about which SDE has to be - * encoded before resolution reduction is allowed is handled - * here. This approach may be a bit more complex than alternative ways - * of doing it, but it minimizes the amount of temporary memory used. - */ -static void output_sde(struct jbg_enc_state *s, - unsigned long stripe, int layer, int plane) -{ - int lfcl; /* lowest fully coded layer */ - long i; - unsigned long u; - - assert(s->sde[stripe][layer][plane] != SDE_DONE); - - if (s->sde[stripe][layer][plane] != SDE_TODO) { -#ifdef DEBUG - fprintf(stderr, "writing SDE: s/d/p = %2lu/%2d/%2d\n", - stripe, layer, plane); -#endif - jbg_buf_output(&s->sde[stripe][layer][plane], s->data_out, s->file); - s->sde[stripe][layer][plane] = SDE_DONE; - return; - } - - /* Determine the smallest resolution layer in this plane for which - * not yet all stripes have been encoded into SDEs. This layer will - * have to be completely coded, before we can apply the next - * resolution reduction step. */ - lfcl = 0; - for (i = s->d; i >= 0; i--) - if (s->sde[s->stripes - 1][i][plane] == SDE_TODO) { - lfcl = i + 1; - break; - } - if (lfcl > s->d && s->d > 0 && stripe == 0) { - /* perform the first resolution reduction */ - resolution_reduction(s, plane, s->d); - } - /* In case HITOLO is not used, we have to encode and store the higher - * resolution layers first, although we do not need them right now. */ - while (lfcl - 1 > layer) { - for (u = 0; u < s->stripes; u++) - encode_sde(s, u, lfcl - 1, plane); - --lfcl; - s->highres[plane] ^= 1; - if (lfcl > 1) - resolution_reduction(s, plane, lfcl - 1); - } - - encode_sde(s, stripe, layer, plane); - -#ifdef DEBUG - fprintf(stderr, "writing SDE: s/d/p = %2lu/%2d/%2d\n", stripe, layer, plane); -#endif - jbg_buf_output(&s->sde[stripe][layer][plane], s->data_out, s->file); - s->sde[stripe][layer][plane] = SDE_DONE; - - if (stripe == s->stripes - 1 && layer > 0 && - s->sde[0][layer-1][plane] == SDE_TODO) { - s->highres[plane] ^= 1; - if (layer > 1) - resolution_reduction(s, plane, layer - 1); - } - - return; -} - - -/* - * Convert the table which controls the deterministic prediction - * process from the internal format into the representation required - * for the 1728 byte long DPTABLE element of a BIH. - * - * The bit order of the DPTABLE format (see also ITU-T T.82 figure 13) is - * - * high res: 4 5 6 low res: 0 1 - * 7 8 9 2 3 - * 10 11 12 - * - * were 4 table entries are packed into one byte, while we here use - * internally an unpacked 6912 byte long table indexed by the following - * bit order: - * - * high res: 7 6 5 high res: 8 7 6 low res: 1 0 - * (phase 0) 4 . . (phase 1) 5 4 . 3 2 - * . . . . . . - * - * high res: 10 9 8 high res: 11 10 9 - * (phase 2) 7 6 5 (phase 3) 8 7 6 - * 4 . . 5 4 . - */ -void jbg_int2dppriv(unsigned char *dptable, const char *internal) -{ - int i, j, k; - int trans0[ 8] = { 1, 0, 3, 2, 7, 6, 5, 4 }; - int trans1[ 9] = { 1, 0, 3, 2, 8, 7, 6, 5, 4 }; - int trans2[11] = { 1, 0, 3, 2, 10, 9, 8, 7, 6, 5, 4 }; - int trans3[12] = { 1, 0, 3, 2, 11, 10, 9, 8, 7, 6, 5, 4 }; - - for (i = 0; i < 1728; dptable[i++] = 0) ; - -#define FILL_TABLE1(offset, len, trans) \ - for (i = 0; i < len; i++) { \ - k = 0; \ - for (j = 0; i >> j; j++) \ - k |= ((i >> j) & 1) << trans[j]; \ - dptable[(i + offset) >> 2] |= \ - (internal[k + offset] & 3) << ((3 - (i&3)) << 1); \ - } - - FILL_TABLE1( 0, 256, trans0); - FILL_TABLE1( 256, 512, trans1); - FILL_TABLE1( 768, 2048, trans2); - FILL_TABLE1(2816, 4096, trans3); - - return; -} - - -/* - * Convert the table which controls the deterministic prediction - * process from the 1728 byte long DPTABLE format into the 6912 byte long - * internal format. - */ -void jbg_dppriv2int(char *internal, const unsigned char *dptable) -{ - int i, j, k; - int trans0[ 8] = { 1, 0, 3, 2, 7, 6, 5, 4 }; - int trans1[ 9] = { 1, 0, 3, 2, 8, 7, 6, 5, 4 }; - int trans2[11] = { 1, 0, 3, 2, 10, 9, 8, 7, 6, 5, 4 }; - int trans3[12] = { 1, 0, 3, 2, 11, 10, 9, 8, 7, 6, 5, 4 }; - -#define FILL_TABLE2(offset, len, trans) \ - for (i = 0; i < len; i++) { \ - k = 0; \ - for (j = 0; i >> j; j++) \ - k |= ((i >> j) & 1) << trans[j]; \ - internal[k + offset] = \ - (dptable[(i + offset) >> 2] >> ((3 - (i & 3)) << 1)) & 3; \ - } - - FILL_TABLE2( 0, 256, trans0); - FILL_TABLE2( 256, 512, trans1); - FILL_TABLE2( 768, 2048, trans2); - FILL_TABLE2(2816, 4096, trans3); - - return; -} - - -/* - * Encode one full BIE and pass the generated data to the specified - * call-back function - */ -void jbg_enc_out(struct jbg_enc_state *s) -{ - unsigned long bpl; - unsigned char buf[20]; - unsigned long xd, yd, y; - long ii[3], is[3], ie[3]; /* generic variables for the 3 nested loops */ - unsigned long stripe; - int layer, plane; - int order; - unsigned char dpbuf[1728]; - - /* some sanity checks */ - s->order &= JBG_HITOLO | JBG_SEQ | JBG_ILEAVE | JBG_SMID; - order = s->order & (JBG_SEQ | JBG_ILEAVE | JBG_SMID); - if (iindex[order][0] < 0) - s->order = order = JBG_SMID | JBG_ILEAVE; - if (s->options & JBG_DPON && s->dppriv != jbg_dptable) - s->options |= JBG_DPPRIV; - if (s->mx > MX_MAX) - s->mx = MX_MAX; - s->my = 0; - if (s->mx && s->mx < ((s->options & JBG_LRLTWO) ? 5U : 3U)) - s->mx = 0; - if (s->d > 255 || s->d < 0 || s->dh > s->d || s->dh < 0 || - s->dl < 0 || s->dl > s->dh || s->planes < 0 || s->planes > 255) - return; - /* prevent uint32 overflow: s->l0 * 2 ^ s->d < 2 ^ 32 */ - if (s->d > 31 || (s->d != 0 && s->l0 >= (1UL << (32 - s->d)))) - return; - if (s->yd1 < s->yd) - s->yd1 = s->yd; - if (s->yd1 > s->yd) - s->options |= JBG_VLENGTH; - - /* ensure correct zero padding of bitmap at the final byte of each line */ - if (s->xd & 7) { - bpl = jbg_ceil_half(s->xd, 3); /* bytes per line */ - for (plane = 0; plane < s->planes; plane++) - for (y = 0; y < s->yd; y++) - s->lhp[0][plane][y * bpl + bpl - 1] &= ~((1 << (8 - (s->xd & 7))) - 1); - } - - /* prepare BIH */ - buf[0] = s->dl; - buf[1] = s->dh; - buf[2] = s->planes; - buf[3] = 0; - xd = jbg_ceil_half(s->xd, s->d - s->dh); - yd = jbg_ceil_half(s->yd1, s->d - s->dh); - buf[4] = xd >> 24; - buf[5] = (xd >> 16) & 0xff; - buf[6] = (xd >> 8) & 0xff; - buf[7] = xd & 0xff; - buf[8] = yd >> 24; - buf[9] = (yd >> 16) & 0xff; - buf[10] = (yd >> 8) & 0xff; - buf[11] = yd & 0xff; - buf[12] = s->l0 >> 24; - buf[13] = (s->l0 >> 16) & 0xff; - buf[14] = (s->l0 >> 8) & 0xff; - buf[15] = s->l0 & 0xff; - buf[16] = s->mx; - buf[17] = s->my; - buf[18] = s->order; - buf[19] = s->options & 0x7f; - -#if 0 - /* sanitize L0 (if it was set to 0xffffffff for T.85-style NEWLEN tests) */ - if (s->l0 > (s->yd >> s->d)) - s->l0 = s->yd >> s->d; -#endif - - /* calculate number of stripes that will be required */ - s->stripes = jbg_stripes(s->l0, s->yd, s->d); - - /* allocate buffers for SDE pointers */ - if (s->sde == NULL) { - s->sde = (struct jbg_buf ****) - checked_malloc(s->stripes, sizeof(struct jbg_buf ***)); - for (stripe = 0; stripe < s->stripes; stripe++) { - s->sde[stripe] = (struct jbg_buf ***) - checked_malloc(s->d + 1, sizeof(struct jbg_buf **)); - for (layer = 0; layer < s->d + 1; layer++) { - s->sde[stripe][layer] = (struct jbg_buf **) - checked_malloc(s->planes, sizeof(struct jbg_buf *)); - for (plane = 0; plane < s->planes; plane++) - s->sde[stripe][layer][plane] = SDE_TODO; - } - } - } - - /* output BIH */ - s->data_out(buf, 20, s->file); - if ((s->options & (JBG_DPON | JBG_DPPRIV | JBG_DPLAST)) == - (JBG_DPON | JBG_DPPRIV)) { - /* write private table */ - jbg_int2dppriv(dpbuf, s->dppriv); - s->data_out(dpbuf, 1728, s->file); - } - -#if 0 - /* - * Encode everything first. This is a simple-minded alternative to - * all the tricky on-demand encoding logic in output_sde() for - * debugging purposes. - */ - for (layer = s->dh; layer >= s->dl; layer--) { - for (plane = 0; plane < s->planes; plane++) { - if (layer > 0) - resolution_reduction(s, plane, layer); - for (stripe = 0; stripe < s->stripes; stripe++) - encode_sde(s, stripe, layer, plane); - s->highres[plane] ^= 1; - } - } -#endif - - /* - * Generic loops over all SDEs. Which loop represents layer, plane and - * stripe depends on the option flags. - */ - - /* start and end value for each loop */ - is[iindex[order][STRIPE]] = 0; - ie[iindex[order][STRIPE]] = s->stripes - 1; - is[iindex[order][LAYER]] = s->dl; - ie[iindex[order][LAYER]] = s->dh; - is[iindex[order][PLANE]] = 0; - ie[iindex[order][PLANE]] = s->planes - 1; - - for (ii[0] = is[0]; ii[0] <= ie[0]; ii[0]++) - for (ii[1] = is[1]; ii[1] <= ie[1]; ii[1]++) - for (ii[2] = is[2]; ii[2] <= ie[2]; ii[2]++) { - - stripe = ii[iindex[order][STRIPE]]; - if (s->order & JBG_HITOLO) - layer = s->dh - (ii[iindex[order][LAYER]] - s->dl); - else - layer = ii[iindex[order][LAYER]]; - plane = ii[iindex[order][PLANE]]; - - /* output comment marker segment if there is any pending */ - if (s->comment) { - buf[0] = MARKER_ESC; - buf[1] = MARKER_COMMENT; - buf[2] = s->comment_len >> 24; - buf[3] = (s->comment_len >> 16) & 0xff; - buf[4] = (s->comment_len >> 8) & 0xff; - buf[5] = s->comment_len & 0xff; - s->data_out(buf, 6, s->file); - s->data_out(s->comment, s->comment_len, s->file); - s->comment = NULL; - } - - output_sde(s, stripe, layer, plane); - - /* - * When we generate a NEWLEN test case (s->yd1 > s->yd), output - * NEWLEN after last stripe if we have only a single - * resolution layer or plane (see ITU-T T.85 profile), otherwise - * output NEWLEN before last stripe. - */ - if (s->yd1 > s->yd && - (stripe == s->stripes - 1 || - (stripe == s->stripes - 2 && - (s->dl != s->dh || s->planes > 1)))) { - s->yd1 = s->yd; - yd = jbg_ceil_half(s->yd, s->d - s->dh); - buf[0] = MARKER_ESC; - buf[1] = MARKER_NEWLEN; - buf[2] = yd >> 24; - buf[3] = (yd >> 16) & 0xff; - buf[4] = (yd >> 8) & 0xff; - buf[5] = yd & 0xff; - s->data_out(buf, 6, s->file); -#ifdef DEBUG - fprintf(stderr, "NEWLEN: yd=%lu\n", yd); -#endif - if (stripe == s->stripes - 1) { - buf[1] = MARKER_SDNORM; - s->data_out(buf, 2, s->file); - } - } - - } - - return; -} - - -void jbg_enc_free(struct jbg_enc_state *s) -{ - unsigned long stripe; - int layer, plane; - -#ifdef DEBUG - fprintf(stderr, "jbg_enc_free(%p)\n", (void *) s); -#endif - - /* clear buffers for SDEs */ - if (s->sde) { - for (stripe = 0; stripe < s->stripes; stripe++) { - for (layer = 0; layer < s->d + 1; layer++) { - for (plane = 0; plane < s->planes; plane++) - if (s->sde[stripe][layer][plane] != SDE_DONE && - s->sde[stripe][layer][plane] != SDE_TODO) - jbg_buf_free(&s->sde[stripe][layer][plane]); - checked_free(s->sde[stripe][layer]); - } - checked_free(s->sde[stripe]); - } - checked_free(s->sde); - } - - /* clear free_list */ - jbg_buf_free(&s->free_list); - - /* clear memory for arithmetic encoder states */ - checked_free(s->s); - - /* clear memory for differential-layer typical prediction buffer */ - checked_free(s->tp); - - /* clear memory for adaptive template pixel offsets */ - checked_free(s->tx); - - /* clear lowres image buffers */ - if (s->lhp[1]) { - for (plane = 0; plane < s->planes; plane++) - checked_free(s->lhp[1][plane]); - checked_free(s->lhp[1]); - } - - /* clear buffer for index of highres image in lhp */ - checked_free(s->highres); - - return; -} - - -/* - * Convert the error codes used by jbg_dec_in() into an English ASCII string - */ -const char *jbg_strerror(int errnum) -{ - errnum >>= 4; - if (errnum < 0 || (unsigned) errnum >= sizeof(errmsg)/sizeof(errmsg[0])) - return "Unknown error code passed to jbg_strerror()"; - - return errmsg[errnum]; -} - - -/* - * The constructor for a decoder - */ -void jbg_dec_init(struct jbg_dec_state *s) -{ - s->order = 0; - s->d = -1; - s->bie_len = 0; - s->buf_len = 0; - s->dppriv = NULL; - s->xmax = 4294967295UL; - s->ymax = 4294967295UL; - s->dmax = 256; - s->s = NULL; - - return; -} - - -/* - * Specify a maximum image size for the decoder. If the JBIG file has - * the order bit ILEAVE, but not the bit SEQ set, then the decoder - * will abort to decode after the image has reached the maximal - * resolution layer which is still not wider than xmax or higher than - * ymax. - */ -void jbg_dec_maxsize(struct jbg_dec_state *s, unsigned long xmax, - unsigned long ymax) -{ - if (xmax > 0) s->xmax = xmax; - if (ymax > 0) s->ymax = ymax; - - return; -} - - -/* - * Decode the new len PSDC bytes to which data points and add them to - * the current stripe. Return the number of bytes which have actually - * been read (this will be less than len if a marker segment was - * part of the data or if the final byte was 0xff, in which case - * this code cannot determine whether we have a marker segment). - */ -static size_t decode_pscd(struct jbg_dec_state *s, unsigned char *data, - size_t len) -{ - unsigned long stripe; - unsigned int layer, plane; - unsigned long hl, ll, y, hx, hy, lx, ly, hbpl, lbpl; - unsigned char *hp, *lp1, *lp2, *p1, *q1; - register unsigned long line_h1, line_h2, line_h3; - register unsigned long line_l1, line_l2, line_l3; - struct jbg_ardec_state *se; - unsigned long x; - long o; - unsigned a; - int n; - int pix, cx = 0, slntp, tx; - - /* SDE loop variables */ - stripe = s->ii[iindex[s->order & 7][STRIPE]]; - layer = s->ii[iindex[s->order & 7][LAYER]]; - plane = s->ii[iindex[s->order & 7][PLANE]]; - - /* forward data to arithmetic decoder */ - se = s->s[plane] + layer - s->dl; - se->pscd_ptr = data; - se->pscd_end = data + len; - - /* number of lines per stripe in highres image */ - hl = s->l0 << layer; - /* number of lines per stripe in lowres image */ - ll = hl >> 1; - /* current line number in highres image */ - y = stripe * hl + s->i; - /* number of pixels in highres image */ - hx = jbg_ceil_half(s->xd, s->d - layer); - hy = jbg_ceil_half(s->yd, s->d - layer); - /* number of pixels in lowres image */ - lx = jbg_ceil_half(hx, 1); - ly = jbg_ceil_half(hy, 1); - /* bytes per line in highres and lowres image */ - hbpl = jbg_ceil_half(hx, 3); - lbpl = jbg_ceil_half(lx, 3); - /* pointer to highres and lowres image bytes */ - hp = s->lhp[ layer & 1][plane] + (stripe * hl + s->i) * hbpl + - (s->x >> 3); - lp2 = s->lhp[(layer-1) & 1][plane] + (stripe * ll + (s->i >> 1)) * lbpl + - (s->x >> 4); - lp1 = lp2 + lbpl; - - /* restore a few local variables */ - line_h1 = s->line_h1; - line_h2 = s->line_h2; - line_h3 = s->line_h3; - line_l1 = s->line_l1; - line_l2 = s->line_l2; - line_l3 = s->line_l3; - x = s->x; - -#ifdef DEBUG - if (s->x == 0 && s->i == 0 && s->pseudo) - fprintf(stderr, "decode_pscd(%p, %p, %ld): s/d/p = %2lu/%2u/%2u\n", - (void *) s, (void *) data, (long) len, stripe, layer, plane); -#endif - - if (s->x == 0 && s->i == 0 && - (stripe == 0 || s->reset[plane][layer - s->dl]) && s->pseudo) { - s->tx[plane][layer - s->dl] = s->ty[plane][layer - s->dl] = 0; - s->lntp[plane][layer - s->dl] = 1; - } - - if (layer == 0) { - - /* - * Decode lowest resolution layer - */ - - for (; s->i < hl && y < hy; s->i++, y++) { - - /* adaptive template changes */ - if (x == 0 && s->pseudo) - for (n = 0; n < s->at_moves; n++) - if (s->at_line[n] == s->i) { - s->tx[plane][layer - s->dl] = s->at_tx[n]; - s->ty[plane][layer - s->dl] = s->at_ty[n]; -#ifdef DEBUG - fprintf(stderr, "ATMOVE: line=%lu, tx=%d, ty=%d.\n", s->i, - s->tx[plane][layer - s->dl], s->ty[plane][layer - s->dl]); -#endif - } - tx = s->tx[plane][layer - s->dl]; - assert(tx >= 0); /* i.e., tx can safely be cast to unsigned */ - - /* typical prediction */ - if (s->options & JBG_TPBON && s->pseudo) { - slntp = arith_decode(se, (s->options & JBG_LRLTWO) ? TPB2CX : TPB3CX); - if (slntp < 0) - goto leave; - s->lntp[plane][layer - s->dl] = - !(slntp ^ s->lntp[plane][layer - s->dl]); - if (!s->lntp[plane][layer - s->dl]) { - /* this line is 'typical' (i.e. identical to the previous one) */ - p1 = hp; - if (s->i == 0 && (stripe == 0 || s->reset[plane][layer - s->dl])) - while (p1 < hp + hbpl) *p1++ = 0; - else { - q1 = hp - hbpl; - while (q1 < hp) *p1++ = *q1++; - } - hp += hbpl; - continue; - } - /* this line is 'not typical' and has to be coded completely */ - } - s->pseudo = 0; - - /* - * Layout of the variables line_h1, line_h2, line_h3, which contain - * as bits the neighbour pixels of the currently decoded pixel X: - * - * 76543210 76543210 76543210 76543210 line_h3 - * 76543210 76543210 76543210 76543210 line_h2 - * 76543210 76543210 76543210 76543210 X line_h1 - */ - - if (x == 0) { - line_h1 = line_h2 = line_h3 = 0; - if (s->i > 0 || (y > 0 && !s->reset[plane][layer - s->dl])) - line_h2 = (long)*(hp - hbpl) << 8; - if (s->i > 1 || (y > 1 && !s->reset[plane][layer - s->dl])) - line_h3 = (long)*(hp - hbpl - hbpl) << 8; - } - - /* - * Another tiny JBIG standard bug: - * - * While implementing the line_h3 handling here, I discovered - * another problem with the ITU-T T.82(1993 E) specification. - * This might be a somewhat pathological case, however. The - * standard is unclear about how a decoder should behave in the - * following situation: - * - * Assume we are in layer 0 and all stripes are single lines - * (L0=1 allowed by table 9). We are now decoding the first (and - * only) line of the third stripe. Assume, the first stripe was - * terminated by SDRST and the second stripe was terminated by - * SDNORM. While decoding the only line of the third stripe with - * the three-line template, we need access to pixels from the - * previous two stripes. We know that the previous stripe - * terminated with SDNROM, so we access the pixel from the - * second stripe. But do we have to replace the pixels from the - * first stripe by background pixels, because this stripe ended - * with SDRST? The standard, especially clause 6.2.5 does never - * mention this case, so the behaviour is undefined here. My - * current implementation remembers only the marker used to - * terminate the previous stripe. In the above example, the - * pixels of the first stripe are accessed despite the fact that - * this stripe ended with SDRST. An alternative (only slightly - * more complicated) implementation would be to remember the end - * marker (SDNORM or SDRST) of the previous two stripes in a - * plane/layer and to act accordingly when accessing the two - * previous lines. What am I supposed to do here? - * - * As the standard is unclear about the correct behaviour in the - * situation of the above example, I strongly suggest to avoid - * the following situation while encoding data with JBIG: - * - * LRLTWO = 0, L0=1 and both SDNORM and SDRST appear in layer 0. - * - * I guess that only a very few if any encoders will switch - * between SDNORM and SDRST, so let us hope that this ambiguity - * in the standard will never cause any interoperability - * problems. - * - * Markus Kuhn -- 1995-04-30 - */ - - /* decode line */ - while (x < hx) { - if ((x & 7) == 0) { - if (x < hbpl * 8 - 8 && - (s->i > 0 || (y > 0 && !s->reset[plane][layer - s->dl]))) { - line_h2 |= *(hp - hbpl + 1); - if (s->i > 1 || (y > 1 && !s->reset[plane][layer - s->dl])) - line_h3 |= *(hp - hbpl - hbpl + 1); - } - } - if (s->options & JBG_LRLTWO) { - /* two line template */ - do { - if (tx) { - if ((unsigned) tx > x) - a = 0; - else if (tx < 8) - a = ((line_h1 >> (tx - 5)) & 0x010); - else { - o = (x - tx) - (x & ~7L); - a = (hp[o >> 3] >> (7 - (o & 7))) & 1; - a <<= 4; - } - assert(tx > 31 || - a == ((line_h1 >> (tx - 5)) & 0x010)); - pix = arith_decode(se, (((line_h2 >> 9) & 0x3e0) | a | - (line_h1 & 0x00f))); - } else - pix = arith_decode(se, (((line_h2 >> 9) & 0x3f0) | - (line_h1 & 0x00f))); - if (pix < 0) - goto leave; - line_h1 = (line_h1 << 1) | pix; - line_h2 <<= 1; - } while ((++x & 7) && x < hx); - } else { - /* three line template */ - do { - if (tx) { - if ((unsigned) tx > x) - a = 0; - else if (tx < 8) - a = ((line_h1 >> (tx - 3)) & 0x004); - else { - o = (x - tx) - (x & ~7L); - a = (hp[o >> 3] >> (7 - (o & 7))) & 1; - a <<= 2; - } - assert(tx > 31 || - a == ((line_h1 >> (tx - 3)) & 0x004)); - pix = arith_decode(se, (((line_h3 >> 7) & 0x380) | - ((line_h2 >> 11) & 0x078) | a | - (line_h1 & 0x003))); - } else - pix = arith_decode(se, (((line_h3 >> 7) & 0x380) | - ((line_h2 >> 11) & 0x07c) | - (line_h1 & 0x003))); - if (pix < 0) - goto leave; - - line_h1 = (line_h1 << 1) | pix; - line_h2 <<= 1; - line_h3 <<= 1; - } while ((++x & 7) && x < hx); - } /* if (s->options & JBG_LRLTWO) */ - *hp++ = line_h1; - } /* while */ - *(hp - 1) <<= hbpl * 8 - hx; - x = 0; - s->pseudo = 1; - } /* for (i = ...) */ - - } else { - - /* - * Decode differential layer - */ - - for (; s->i < hl && y < hy; s->i++, y++) { - - /* adaptive template changes */ - if (x == 0) - for (n = 0; n < s->at_moves; n++) - if (s->at_line[n] == s->i) { - s->tx[plane][layer - s->dl] = s->at_tx[n]; - s->ty[plane][layer - s->dl] = s->at_ty[n]; -#ifdef DEBUG - fprintf(stderr, "ATMOVE: line=%lu, tx=%d, ty=%d.\n", s->i, - s->tx[plane][layer - s->dl], s->ty[plane][layer - s->dl]); -#endif - } - tx = s->tx[plane][layer - s->dl]; - - /* handle lower border of low-resolution image */ - if ((s->i >> 1) >= ll - 1 || (y >> 1) >= ly - 1) - lp1 = lp2; - - /* typical prediction */ - if ((s->options & JBG_TPDON) && s->pseudo) { - if ((s->lntp[plane][layer - s->dl] = arith_decode(se, TPDCX)) < 0) - goto leave; - } - s->pseudo = 0; - - /* - * Layout of the variables line_h1, line_h2, line_h3, which contain - * as bits the high resolution neighbour pixels of the currently - * decoded highres pixel X: - * - * 76543210 76543210 76543210 76543210 line_h3 - * 76543210 76543210 76543210 76543210 line_h2 - * 76543210 76543210 76543210 76543210 X line_h1 - * - * Layout of the variables line_l1, line_l2, line_l3, which contain - * the low resolution pixels near the currently decoded pixel as bits. - * The lowres pixel in which the currently coded highres pixel is - * located is marked as Y: - * - * 76543210 76543210 76543210 76543210 line_l3 - * 76543210 76543210 Y6543210 76543210 line_l2 - * 76543210 76543210 76543210 76543210 line_l1 - */ - - - if (x == 0) { - line_h1 = line_h2 = line_h3 = line_l1 = line_l2 = line_l3 = 0; - if (s->i > 0 || (y > 0 && !s->reset[plane][layer - s->dl])) { - line_h2 = (long)*(hp - hbpl) << 8; - if (s->i > 1 || (y > 1 && !s->reset[plane][layer - s->dl])) - line_h3 = (long)*(hp - hbpl - hbpl) << 8; - } - if (s->i > 1 || (y > 1 && !s->reset[plane][layer-s->dl])) - line_l3 = (long)*(lp2 - lbpl) << 8; - line_l2 = (long)*lp2 << 8; - line_l1 = (long)*lp1 << 8; - } - - /* decode line */ - while (x < hx) { - if ((x & 15) == 0) - if ((x >> 1) < lbpl * 8 - 8) { - line_l1 |= *(lp1 + 1); - line_l2 |= *(lp2 + 1); - if (s->i > 1 || - (y > 1 && !s->reset[plane][layer - s->dl])) - line_l3 |= *(lp2 - lbpl + 1); - } - do { - - assert(hp - (s->lhp[ layer &1][plane] + (stripe * hl + s->i) - * hbpl) == (ptrdiff_t) x >> 3); - assert(lp2 - (s->lhp[(layer-1) &1][plane] + (stripe * ll + (s->i>>1)) - * lbpl) == (ptrdiff_t) x >> 4); - - if ((x & 7) == 0) - if (x < hbpl * 8 - 8) { - if (s->i > 0 || (y > 0 && !s->reset[plane][layer - s->dl])) { - line_h2 |= *(hp + 1 - hbpl); - if (s->i > 1 || (y > 1 && !s->reset[plane][layer - s->dl])) - line_h3 |= *(hp + 1 - hbpl - hbpl); - } - } - do { - if (!s->lntp[plane][layer - s->dl]) - cx = (((line_l3 >> 14) & 0x007) | - ((line_l2 >> 11) & 0x038) | - ((line_l1 >> 8) & 0x1c0)); - if (!s->lntp[plane][layer - s->dl] && - (cx == 0x000 || cx == 0x1ff)) { - /* pixels are typical and have not to be decoded */ - do { - line_h1 = (line_h1 << 1) | (cx & 1); - } while ((++x & 1) && x < hx); - line_h2 <<= 2; line_h3 <<= 2; - } else - do { - - /* deterministic prediction */ - if (s->options & JBG_DPON) - if ((y & 1) == 0) - if ((x & 1) == 0) - /* phase 0 */ - pix = s->dppriv[((line_l3 >> 15) & 0x003) | - ((line_l2 >> 13) & 0x00c) | - ((line_h1 << 4) & 0x010) | - ((line_h2 >> 9) & 0x0e0)]; - else - /* phase 1 */ - pix = s->dppriv[(((line_l3 >> 15) & 0x003) | - ((line_l2 >> 13) & 0x00c) | - ((line_h1 << 4) & 0x030) | - ((line_h2 >> 9) & 0x1c0)) + 256]; - else - if ((x & 1) == 0) - /* phase 2 */ - pix = s->dppriv[(((line_l3 >> 15) & 0x003) | - ((line_l2 >> 13) & 0x00c) | - ((line_h1 << 4) & 0x010) | - ((line_h2 >> 9) & 0x0e0) | - ((line_h3 >> 6) & 0x700)) + 768]; - else - /* phase 3 */ - pix = s->dppriv[(((line_l3 >> 15) & 0x003) | - ((line_l2 >> 13) & 0x00c) | - ((line_h1 << 4) & 0x030) | - ((line_h2 >> 9) & 0x1c0) | - ((line_h3 >> 6) & 0xe00)) + 2816]; - else - pix = 2; - - if (pix & 2) { - if (tx) - cx = ((line_h1 & 0x003) | - (((line_h1 << 2) >> (tx - 3)) & 0x010) | - ((line_h2 >> 12) & 0x00c) | - ((line_h3 >> 10) & 0x020)); - else - cx = ((line_h1 & 0x003) | - ((line_h2 >> 12) & 0x01c) | - ((line_h3 >> 10) & 0x020)); - if (x & 1) - cx |= (((line_l2 >> 8) & 0x0c0) | - ((line_l1 >> 6) & 0x300)) | (1UL << 10); - else - cx |= (((line_l2 >> 9) & 0x0c0) | - ((line_l1 >> 7) & 0x300)); - cx |= (y & 1) << 11; - - pix = arith_decode(se, cx); - if (pix < 0) - goto leave; - } - - line_h1 = (line_h1 << 1) | pix; - line_h2 <<= 1; - line_h3 <<= 1; - - } while ((++x & 1) && x < hx); - line_l1 <<= 1; line_l2 <<= 1; line_l3 <<= 1; - } while ((x & 7) && x < hx); - *hp++ = line_h1; - } while ((x & 15) && x < hx); - ++lp1; - ++lp2; - } /* while */ - x = 0; - - *(hp - 1) <<= hbpl * 8 - hx; - if ((s->i & 1) == 0) { - /* low resolution pixels are used twice */ - lp1 -= lbpl; - lp2 -= lbpl; - } else - s->pseudo = 1; - - } /* for (i = ...) */ - - } - - leave: - - /* save a few local variables */ - s->line_h1 = line_h1; - s->line_h2 = line_h2; - s->line_h3 = line_h3; - s->line_l1 = line_l1; - s->line_l2 = line_l2; - s->line_l3 = line_l3; - s->x = x; - - return se->pscd_ptr - data; -} - - -/* - * Provide to the decoder a new BIE fragment of len bytes starting at data. - * - * Unless cnt is NULL, *cnt will contain the number of actually read bytes - * on return. - * - * Normal return values: - * - * JBG_EAGAIN All data bytes provided so far have been processed - * (*cnt == len) but the end of the data stream has - * not yet been recognized. Call the function again - * with additional BIE bytes. - * JBG_EOK The function has reached the end of a and - * a full image has been decoded. The function can - * be called again with data from the next BIE, if - * there exists one, in order to get to a higher - * resolution layer. The remaining len - *cnt bytes - * of the previous data block will then have to passed - * to this function again if len > *cnt. - * JBG_EOK_INTR Parsing the BIE has been interrupted as had been - * requested by a jbg_dec_maxsize() specification. - * This function can be called again with the - * rest of the BIE to continue the decoding process. - * The remaining len - *cnt bytes of the previous - * data block will then have to be passed to this - * function again if len > *cnt. - * - * Any other return value indicates that the decoding process was - * aborted by a serious problem and the only function you can then - * still call is jbg_dec_free() in order to remove the mess, and - * jbg85_strerror() to find out what to tell the user. (Looking at the - * least significant bits of the return value will provide additional - * information by identifying which test exactly has failed.) - */ -int jbg_dec_in(struct jbg_dec_state *s, unsigned char *data, size_t len, - size_t *cnt) -{ - int i, j, required_length; - unsigned long x, y; - unsigned long is[3], ie[3]; - size_t dummy_cnt; - unsigned char *dppriv; - - if (!cnt) cnt = &dummy_cnt; - *cnt = 0; - if (len < 1) return JBG_EAGAIN; - - /* read in 20-byte BIH */ - if (s->bie_len < 20) { - while (s->bie_len < 20 && *cnt < len) - s->buffer[s->bie_len++] = data[(*cnt)++]; - if (s->bie_len < 20) - return JBG_EAGAIN; - /* test whether this looks like a valid JBIG header at all */ - if (s->buffer[1] < s->buffer[0]) - return JBG_EINVAL | 1; - if (s->buffer[3] != 0) return JBG_EINVAL | 2; /* padding != 0 */ - if ((s->buffer[18] & 0xf0) != 0) return JBG_EINVAL | 3; /* padding != 0 */ - if ((s->buffer[19] & 0x80) != 0) return JBG_EINVAL | 4; /* padding != 0 */ - if (s->buffer[0] != s->d + 1) - return JBG_ENOCONT | 1; - s->dl = s->buffer[0]; - s->d = s->buffer[1]; - if (s->dl == 0) - s->planes = s->buffer[2]; - else - if (s->planes != s->buffer[2]) - return JBG_ENOCONT | 2; - x = (((long) s->buffer[ 4] << 24) | ((long) s->buffer[ 5] << 16) | - ((long) s->buffer[ 6] << 8) | (long) s->buffer[ 7]); - y = (((long) s->buffer[ 8] << 24) | ((long) s->buffer[ 9] << 16) | - ((long) s->buffer[10] << 8) | (long) s->buffer[11]); - if (s->dl != 0 && ((s->xd << (s->d - s->dl + 1)) != x && - (s->yd << (s->d - s->dl + 1)) != y)) - return JBG_ENOCONT | 3; - s->xd = x; - s->yd = y; - s->l0 = (((long) s->buffer[12] << 24) | ((long) s->buffer[13] << 16) | - ((long) s->buffer[14] << 8) | (long) s->buffer[15]); - /* ITU-T T.85 trick not directly implemented by decoder; for full - * T.85 compatibility with respect to all NEWLEN marker scenarios, - * preprocess BIE with jbg_newlen() before passing it to the decoder, - * or consider using the decoder found in jbig85.c instead. */ - if (s->yd == 0xffffffff) - return JBG_EIMPL | 1; - if (!s->planes) return JBG_EINVAL | 5; - if (!s->xd) return JBG_EINVAL | 6; - if (!s->yd) return JBG_EINVAL | 7; - if (!s->l0) return JBG_EINVAL | 8; - /* prevent uint32 overflow: s->l0 * 2 ^ s->d < 2 ^ 32 */ - if (s->d > 31) - return JBG_EIMPL | 2; - if ((s->d != 0 && s->l0 >= (1UL << (32 - s->d)))) - return JBG_EIMPL | 3; - s->mx = s->buffer[16]; - if (s->mx > 127) - return JBG_EINVAL | 9; - s->my = s->buffer[17]; -#if 0 - if (s->my > 0) - return JBG_EIMPL | 4; -#endif - s->order = s->buffer[18]; - if (iindex[s->order & 7][0] < 0) - return JBG_EINVAL | 10; - /* HITOLO and SEQ currently not yet implemented */ - if (s->dl != s->d && (s->order & JBG_HITOLO || s->order & JBG_SEQ)) - return JBG_EIMPL | 5; - s->options = s->buffer[19]; - - /* calculate number of stripes that will be required */ - s->stripes = jbg_stripes(s->l0, s->yd, s->d); - - /* some initialization */ - s->ii[iindex[s->order & 7][STRIPE]] = 0; - s->ii[iindex[s->order & 7][LAYER]] = s->dl; - s->ii[iindex[s->order & 7][PLANE]] = 0; - if (s->dl == 0) { - s->s = (struct jbg_ardec_state **) - checked_malloc(s->planes, sizeof(struct jbg_ardec_state *)); - s->tx = (int **) checked_malloc(s->planes, sizeof(int *)); - s->ty = (int **) checked_malloc(s->planes, sizeof(int *)); - s->reset = (int **) checked_malloc(s->planes, sizeof(int *)); - s->lntp = (int **) checked_malloc(s->planes, sizeof(int *)); - s->lhp[0] = (unsigned char **) - checked_malloc(s->planes, sizeof(unsigned char *)); - s->lhp[1] = (unsigned char **) - checked_malloc(s->planes, sizeof(unsigned char *)); - for (i = 0; i < s->planes; i++) { - s->s[i] = (struct jbg_ardec_state *) - checked_malloc(s->d - s->dl + 1, sizeof(struct jbg_ardec_state)); - s->tx[i] = (int *) checked_malloc(s->d - s->dl + 1, sizeof(int)); - s->ty[i] = (int *) checked_malloc(s->d - s->dl + 1, sizeof(int)); - s->reset[i] = (int *) checked_malloc(s->d - s->dl + 1, sizeof(int)); - s->lntp[i] = (int *) checked_malloc(s->d - s->dl + 1, sizeof(int)); - s->lhp[ s->d & 1][i] = (unsigned char *) - checked_malloc(s->yd, jbg_ceil_half(s->xd, 3)); - s->lhp[(s->d-1) & 1][i] = (unsigned char *) - checked_malloc(jbg_ceil_half(s->yd, 1), jbg_ceil_half(s->xd, 1+3)); - } - } else { - for (i = 0; i < s->planes; i++) { - s->s[i] = (struct jbg_ardec_state *) - checked_realloc(s->s[i], s->d - s->dl + 1, - sizeof(struct jbg_ardec_state)); - s->tx[i] = (int *) checked_realloc(s->tx[i], - s->d - s->dl + 1, sizeof(int)); - s->ty[i] = (int *) checked_realloc(s->ty[i], - s->d - s->dl + 1, sizeof(int)); - s->reset[i] = (int *) checked_realloc(s->reset[i], - s->d - s->dl + 1, sizeof(int)); - s->lntp[i] = (int *) checked_realloc(s->lntp[i], - s->d - s->dl + 1, sizeof(int)); - s->lhp[ s->d & 1][i] = (unsigned char *) - checked_realloc(s->lhp[ s->d & 1][i], - s->yd, jbg_ceil_half(s->xd, 3)); - s->lhp[(s->d-1) & 1][i] = (unsigned char *) - checked_realloc(s->lhp[(s->d-1) & 1][i], - jbg_ceil_half(s->yd, 1), jbg_ceil_half(s->xd, 1+3)); - } - } - for (i = 0; i < s->planes; i++) - for (j = 0; j <= s->d - s->dl; j++) - arith_decode_init(s->s[i] + j, 0); - if (s->dl == 0 || (s->options & JBG_DPON && !(s->options & JBG_DPPRIV))) - s->dppriv = jbg_dptable; - s->comment_skip = 0; - s->buf_len = 0; - s->x = 0; - s->i = 0; - s->pseudo = 1; - s->at_moves = 0; - } - - /* read in DPTABLE */ - if (s->bie_len < 20 + 1728 && - (s->options & (JBG_DPON | JBG_DPPRIV | JBG_DPLAST)) == - (JBG_DPON | JBG_DPPRIV)) { - assert(s->bie_len >= 20); - if (!s->dppriv || s->dppriv == jbg_dptable) - s->dppriv = (char *) checked_malloc(1728, sizeof(char)); - while (s->bie_len < 20 + 1728 && *cnt < len) - s->dppriv[s->bie_len++ - 20] = data[(*cnt)++]; - if (s->bie_len < 20 + 1728) - return JBG_EAGAIN; - dppriv = (unsigned char *) s->dppriv; - s->dppriv = (char *) checked_malloc(6912, sizeof(char)); - jbg_dppriv2int(s->dppriv, dppriv); - checked_free(dppriv); - } - - /* - * BID processing loop - */ - - while (*cnt < len) { - - /* process floating marker segments */ - - /* skip COMMENT contents */ - if (s->comment_skip) { - if (s->comment_skip <= len - *cnt) { - *cnt += s->comment_skip; - s->comment_skip = 0; - } else { - s->comment_skip -= len - *cnt; - *cnt = len; - } - continue; - } - - /* load complete marker segments into s->buffer for processing */ - if (s->buf_len > 0) { - assert(s->buffer[0] == MARKER_ESC); - while (s->buf_len < 2 && *cnt < len) - s->buffer[s->buf_len++] = data[(*cnt)++]; - if (s->buf_len < 2) continue; - switch (s->buffer[1]) { - case MARKER_COMMENT: required_length = 6; break; - case MARKER_ATMOVE: required_length = 8; break; - case MARKER_NEWLEN: required_length = 6; break; - case MARKER_ABORT: - case MARKER_SDNORM: - case MARKER_SDRST: required_length = 2; break; - case MARKER_STUFF: - /* forward stuffed 0xff to arithmetic decoder */ - s->buf_len = 0; - decode_pscd(s, s->buffer, 2); - continue; - default: - return JBG_EMARKER; - } - while (s->buf_len < required_length && *cnt < len) - s->buffer[s->buf_len++] = data[(*cnt)++]; - if (s->buf_len < required_length) continue; - /* now the buffer is filled with exactly one marker segment */ - switch (s->buffer[1]) { - case MARKER_COMMENT: - s->comment_skip = - (((long) s->buffer[2] << 24) | ((long) s->buffer[3] << 16) | - ((long) s->buffer[4] << 8) | (long) s->buffer[5]); - break; - case MARKER_ATMOVE: - if (s->at_moves < JBG_ATMOVES_MAX) { - s->at_line[s->at_moves] = - (((long) s->buffer[2] << 24) | ((long) s->buffer[3] << 16) | - ((long) s->buffer[4] << 8) | (long) s->buffer[5]); - s->at_tx[s->at_moves] = (signed char) s->buffer[6]; - s->at_ty[s->at_moves] = s->buffer[7]; - if (s->at_tx[s->at_moves] < - (int) s->mx || - s->at_tx[s->at_moves] > (int) s->mx || - s->at_ty[s->at_moves] > (int) s->my || - (s->at_ty[s->at_moves] == 0 && s->at_tx[s->at_moves] < 0)) - return JBG_EINVAL | 11; - if (s->at_ty[s->at_moves] != 0) - return JBG_EIMPL | 6; - s->at_moves++; - } else - return JBG_EIMPL | 7; /* more than JBG_ATMOVES_MAX ATMOVES */ - break; - case MARKER_NEWLEN: - y = (((long) s->buffer[2] << 24) | ((long) s->buffer[3] << 16) | - ((long) s->buffer[4] << 8) | (long) s->buffer[5]); - if (y > s->yd) return JBG_EINVAL | 12; - if (!(s->options & JBG_VLENGTH)) return JBG_EINVAL | 13; - s->yd = y; - /* calculate again number of stripes that will be required */ - s->stripes = jbg_stripes(s->l0, s->yd, s->d); - break; - case MARKER_ABORT: - return JBG_EABORT; - - case MARKER_SDNORM: - case MARKER_SDRST: - /* decode final pixels based on trailing zero bytes */ - decode_pscd(s, s->buffer, 2); - - arith_decode_init(s->s[s->ii[iindex[s->order & 7][PLANE]]] + - s->ii[iindex[s->order & 7][LAYER]] - s->dl, - s->ii[iindex[s->order & 7][STRIPE]] != s->stripes - 1 - && s->buffer[1] != MARKER_SDRST); - - s->reset[s->ii[iindex[s->order & 7][PLANE]]] - [s->ii[iindex[s->order & 7][LAYER]] - s->dl] = - (s->buffer[1] == MARKER_SDRST); - - /* prepare for next SDE */ - s->x = 0; - s->i = 0; - s->pseudo = 1; - s->at_moves = 0; - - /* increment layer/stripe/plane loop variables */ - /* start and end value for each loop: */ - is[iindex[s->order & 7][STRIPE]] = 0; - ie[iindex[s->order & 7][STRIPE]] = s->stripes - 1; - is[iindex[s->order & 7][LAYER]] = s->dl; - ie[iindex[s->order & 7][LAYER]] = s->d; - is[iindex[s->order & 7][PLANE]] = 0; - ie[iindex[s->order & 7][PLANE]] = s->planes - 1; - i = 2; /* index to innermost loop */ - do { - j = 0; /* carry flag */ - if (++s->ii[i] > ie[i]) { - /* handling overflow of loop variable */ - j = 1; - if (i > 0) - s->ii[i] = is[i]; - } - } while (--i >= 0 && j); - - s->buf_len = 0; - - /* check whether this have been all SDEs */ - if (j) { -#ifdef DEBUG - fprintf(stderr, "This was the final SDE in this BIE, " - "%ld bytes left.\n", (long) (len - *cnt)); -#endif - s->bie_len = 0; - return JBG_EOK; - } - - /* check whether we have to abort because of xmax/ymax */ - if (iindex[s->order & 7][LAYER] == 0 && i < 0) { - /* LAYER is the outermost loop and we have just gone to next layer */ - if (jbg_ceil_half(s->xd, s->d - s->ii[0]) > s->xmax || - jbg_ceil_half(s->yd, s->d - s->ii[0]) > s->ymax) { - s->xmax = 4294967295UL; - s->ymax = 4294967295UL; - return JBG_EOK_INTR; - } - if (s->ii[0] > (unsigned long) s->dmax) { - s->dmax = 256; - return JBG_EOK_INTR; - } - } - - break; - } - s->buf_len = 0; - - } else if (data[*cnt] == MARKER_ESC) - s->buffer[s->buf_len++] = data[(*cnt)++]; - - else { - - /* we have found PSCD bytes */ - *cnt += decode_pscd(s, data + *cnt, len - *cnt); - if (*cnt < len && data[*cnt] != 0xff) { -#ifdef DEBUG - fprintf(stderr, "PSCD was longer than expected, unread bytes " - "%02x %02x %02x %02x ...\n", data[*cnt], data[*cnt+1], - data[*cnt+2], data[*cnt+3]); -#endif - return JBG_EINVAL | 14; - } - - } - } /* of BID processing loop 'while (*cnt < len) ...' */ - - return JBG_EAGAIN; -} - - -/* - * After jbg_dec_in() returned JBG_EOK or JBG_EOK_INTR, you can call this - * function in order to find out the width of the image. Returns 0 if - * there is no image available yet. - */ -unsigned long jbg_dec_getwidth(const struct jbg_dec_state *s) -{ - if (s->d < 0) - return 0; - if (iindex[s->order & 7][LAYER] == 0) { - if (s->ii[0] < 1) - return 0; - else - return jbg_ceil_half(s->xd, s->d - (s->ii[0] - 1)); - } - - return s->xd; -} - - -/* - * After jbg_dec_in() returned JBG_EOK or JBG_EOK_INTR, you can call this - * function in order to find out the height of the image. Returns 0 if - * there is no image available yet. - */ -unsigned long jbg_dec_getheight(const struct jbg_dec_state *s) -{ - if (s->d < 0) - return 0; - if (iindex[s->order & 7][LAYER] == 0) { - if (s->ii[0] < 1) - return 0; - else - return jbg_ceil_half(s->yd, s->d - (s->ii[0] - 1)); - } - - return s->yd; -} - - -/* - * After jbg_dec_in() returned JBG_EOK or JBG_EOK_INTR, you can call this - * function in order to get a pointer to the image. Returns NULL if - * there is no image available yet. - */ -unsigned char *jbg_dec_getimage(const struct jbg_dec_state *s, int plane) -{ - if (s->d < 0) - return NULL; - if (iindex[s->order & 7][LAYER] == 0) { - if (s->ii[0] < 1) - return NULL; - else - return s->lhp[(s->ii[0] - 1) & 1][plane]; - } - - return s->lhp[s->d & 1][plane]; -} - - -/* - * After jbg_dec_in() returned JBG_EOK or JBG_EOK_INTR, you can call - * this function in order to find out the size in bytes of one - * bitplane of the image. - */ -unsigned long jbg_dec_getsize(const struct jbg_dec_state *s) -{ - if (s->d < 0) - return 0; - if (iindex[s->order & 7][LAYER] == 0) { - if (s->ii[0] < 1) - return 0; - else - return - jbg_ceil_half(s->xd, s->d - (s->ii[0] - 1) + 3) * /* overflow risk? */ - jbg_ceil_half(s->yd, s->d - (s->ii[0] - 1)); - } - - return jbg_ceil_half(s->xd, 3) * s->yd; -} - - -/* - * After jbg_dec_in() returned JBG_EOK or JBG_EOK_INTR, you can call - * this function in order to find out the size of the image that you - * can retrieve with jbg_merge_planes(). - */ -unsigned long jbg_dec_getsize_merged(const struct jbg_dec_state *s) -{ - if (s->d < 0) - return 0; - if (iindex[s->order & 7][LAYER] == 0) { - if (s->ii[0] < 1) - return 0; - else - return - jbg_ceil_half(s->xd, s->d - (s->ii[0] - 1)) * /* overflow risk? */ - jbg_ceil_half(s->yd, s->d - (s->ii[0] - 1)) * - ((s->planes + 7) / 8); - } - - return s->xd * s->yd * ((s->planes + 7) / 8); -} - - -/* - * The destructor function which releases any resources obtained by the - * other decoder functions. - */ -void jbg_dec_free(struct jbg_dec_state *s) -{ - int i; - - if (s->d < 0 || s->s == NULL) - return; - s->d = -2; - - for (i = 0; i < s->planes; i++) { - checked_free(s->s[i]); - checked_free(s->tx[i]); - checked_free(s->ty[i]); - checked_free(s->reset[i]); - checked_free(s->lntp[i]); - checked_free(s->lhp[0][i]); - checked_free(s->lhp[1][i]); - } - - checked_free(s->s); - checked_free(s->tx); - checked_free(s->ty); - checked_free(s->reset); - checked_free(s->lntp); - checked_free(s->lhp[0]); - checked_free(s->lhp[1]); - if (s->dppriv && s->dppriv != jbg_dptable) - checked_free(s->dppriv); - - s->s = NULL; - - return; -} - - -/* - * Split bigendian integer pixel field into separate bit planes. In the - * src array, every pixel is represented by a ((has_planes + 7) / 8) byte - * long word, most significant byte first. While has_planes describes - * the number of used bits per pixel in the source image, encode_plane - * is the number of most significant bits among those that we - * actually transfer to dest. - */ -void jbg_split_planes(unsigned long x, unsigned long y, int has_planes, - int encode_planes, - const unsigned char *src, unsigned char **dest, - int use_graycode) -{ - unsigned long bpl = jbg_ceil_half(x, 3); /* bytes per line in dest plane */ - unsigned long line, i; - unsigned k = 8; - int p; - unsigned prev; /* previous *src byte shifted by 8 bit to the left */ - register int bits, msb = has_planes - 1; - int bitno; - - /* sanity checks */ - if (encode_planes > has_planes) - encode_planes = has_planes; - use_graycode = use_graycode != 0 && encode_planes > 1; - - for (p = 0; p < encode_planes; p++) - memset(dest[p], 0, bpl * y); - - for (line = 0; line < y; line++) { /* lines loop */ - for (i = 0; i * 8 < x; i++) { /* dest bytes loop */ - for (k = 0; k < 8 && i * 8 + k < x; k++) { /* pixel loop */ - prev = 0; - for (p = 0; p < encode_planes; p++) { /* bit planes loop */ - /* calculate which bit in *src do we want */ - bitno = (msb - p) & 7; - /* put this bit with its left neighbor right adjusted into bits */ - bits = (prev | *src) >> bitno; - /* go to next *src byte, but keep old */ - if (bitno == 0) - prev = *src++ << 8; - /* make space for inserting new bit */ - dest[p][bpl * line + i] <<= 1; - /* insert bit, if requested apply Gray encoding */ - dest[p][bpl * line + i] |= (bits ^ (use_graycode & (bits>>1))) & 1; - /* - * Theorem: Let b(n),...,b(1),b(0) be the digits of a - * binary word and let g(n),...,g(1),g(0) be the digits of the - * corresponding Gray code word, then g(i) = b(i) xor b(i+1). - */ - } - /* skip unused *src bytes */ - for (;p < has_planes; p++) - if (((msb - p) & 7) == 0) - src++; - } - } - for (p = 0; p < encode_planes; p++) /* right padding loop */ - dest[p][bpl * (line + 1) - 1] <<= 8 - k; - } - - return; -} - -/* - * Merge the separate bit planes decoded by the JBIG decoder into an - * integer pixel field. This is essentially the counterpart to - * jbg_split_planes(). - */ -void jbg_dec_merge_planes(const struct jbg_dec_state *s, int use_graycode, - void (*data_out)(unsigned char *start, size_t len, - void *file), void *file) -{ -#define BUFLEN 4096 - unsigned long bpl, line, i; - unsigned k = 8; - int p; - unsigned char buf[BUFLEN]; - unsigned char *bp = buf; - unsigned char **src; - unsigned long x, y; - unsigned v; - - /* sanity check */ - use_graycode = use_graycode != 0; - - x = jbg_dec_getwidth(s); - y = jbg_dec_getheight(s); - if (x == 0 || y == 0) - return; - bpl = jbg_ceil_half(x, 3); /* bytes per line in src plane */ - - if (iindex[s->order & 7][LAYER] == 0) - if (s->ii[0] < 1) - return; - else - src = s->lhp[(s->ii[0] - 1) & 1]; - else - src = s->lhp[s->d & 1]; - - for (line = 0; line < y; line++) { /* lines loop */ - for (i = 0; i * 8 < x; i++) { /* src bytes loop */ - for (k = 0; k < 8 && i * 8 + k < x; k++) { /* pixel loop */ - v = 0; - for (p = 0; p < s->planes;) { /* dest bytes loop */ - do { - v = (v << 1) | - (((src[p][bpl * line + i] >> (7 - k)) & 1) ^ - (use_graycode & v)); - } while ((s->planes - ++p) & 7); - *bp++ = v; - if (bp - buf == BUFLEN) { - data_out(buf, BUFLEN, file); - bp = buf; - } - } - } - } - } - - if (bp - buf > 0) - data_out(buf, bp - buf, file); - - return; -} - - -/* - * Given a pointer p to the first byte of either a marker segment or a - * PSCD, as well as the length len of the remaining data, return - * either the pointer to the first byte of the next marker segment or - * PSCD, or p+len if this was the last one, or NULL if some error was - * encountered. Possible errors are: - * - * - not enough bytes left for complete marker segment - * - no marker segment terminates the PSCD - * - unknown marker code encountered - * - */ -static unsigned char *jbg_next_pscdms(unsigned char *p, size_t len) -{ - unsigned char *pp; - unsigned long l; - - if (len < 2) - return NULL; /* not enough bytes left for complete marker segment */ - - if (p[0] != MARKER_ESC || p[1] == MARKER_STUFF) { - do { - while (p[0] == MARKER_ESC && p[1] == MARKER_STUFF) { - p += 2; - len -= 2; - if (len < 2) - return NULL; /* not enough bytes left for complete marker segment */ - } - assert(len >= 2); - pp = (unsigned char *) memchr(p, MARKER_ESC, len - 1); - if (!pp) - return NULL; /* no marker segment terminates the PSCD */ - l = pp - p; - assert(l < len); - p += l; - len -= l; - } while (p[1] == MARKER_STUFF); - } else { - switch (p[1]) { - case MARKER_SDNORM: - case MARKER_SDRST: - case MARKER_ABORT: - return p + 2; - case MARKER_NEWLEN: - if (len < 6) - return NULL; /* not enough bytes left for complete marker segment */ - return p + 6; - case MARKER_ATMOVE: - if (len < 8) - return NULL; /* not enough bytes left for complete marker segment */ - return p + 8; - case MARKER_COMMENT: - if (len < 6) - return NULL; /* not enough bytes left for complete marker segment */ - l = (((long) p[2] << 24) | ((long) p[3] << 16) | - ((long) p[4] << 8) | (long) p[5]); - if (len - 6 < l) - return NULL; /* not enough bytes left for complete marker segment */ - return p + 6 + l; - default: - /* unknown marker sequence encountered */ - return NULL; - } - } - - return p; -} - - -/* - * Scan a complete BIE for a NEWLEN marker segment, then read the new - * YD value found in it and use it to overwrite the one in the BIE - * header. Use this procedure if a BIE initially declares an - * unreasonably high provisional YD value (e.g., 0xffffffff) or - * depends on the fact that section 6.2.6.2 of ITU-T T.82 says that a - * NEWLEN marker segment "could refer to a line in the immediately - * preceding stripe due to an unexpected termination of the image or - * the use of only such stripe". ITU-T.85 explicitely suggests the - * use of this for fax machines that start transmission before having - * encountered the end of the page. None of this is necessary for - * BIEs produced by JBIG-KIT, which normally does not use NEWLEN. - */ -int jbg_newlen(unsigned char *bie, size_t len) -{ - unsigned char *p = bie + 20; - int i; - unsigned long y, yn; - - if (len < 20) - return JBG_EAGAIN; - if ((bie[19] & (JBG_DPON | JBG_DPPRIV | JBG_DPLAST)) - == (JBG_DPON | JBG_DPPRIV)) - p += 1728; /* skip DPTABLE */ - if (p >= bie + len) - return JBG_EAGAIN; - - while ((p = jbg_next_pscdms(p, len - (p - bie)))) { - if (p == bie + len) - return JBG_EOK; - else if (p[0] == MARKER_ESC) - switch (p[1]) { - case MARKER_NEWLEN: - y = (((long) bie[ 8] << 24) | ((long) bie[ 9] << 16) | - ((long) bie[10] << 8) | (long) bie[11]); - yn = (((long) p[2] << 24) | ((long) p[3] << 16) | - ((long) p[4] << 8) | (long) p[5]); - if (yn > y) return JBG_EINVAL | 12; - /* overwrite YD in BIH with YD from NEWLEN */ - for (i = 0; i < 4; i++) { - bie[8+i] = p[2+i]; - } - return JBG_EOK; - case MARKER_ABORT: - return JBG_EABORT; - } - } - return JBG_EINVAL | 0; -} diff --git a/converter/other/jbig/libjbig/jbig.txt b/converter/other/jbig/libjbig/jbig.txt deleted file mode 100644 index bdc14b1..0000000 --- a/converter/other/jbig/libjbig/jbig.txt +++ /dev/null @@ -1,810 +0,0 @@ - -Using the JBIG-KIT library --------------------------- - -Markus Kuhn -- 2013-09-10 - - -This text explains how to use the functions provided by the JBIG-KIT -portable image compression library jbig.c in your application -software. The jbig.c library is a full-featured implementation of the -JBIG1 standard aimed at applications that can hold the entire -uncompressed and compressed image in RAM. - -[For applications that require only the single-bit-per-pixel "fax -subset" of the JBIG1 standard defined in ITU-T Recommendation T.85 -, the alternative implementation -found in jbig85.c may be preferable. It keeps not more than three -lines of the uncompressed image in RAM, which makes it particularly -suitable for embedded applications. For information on how to use -jbig85.c, please refer to the separate documentation file jbig85.txt.] - - -1 Introduction to JBIG - -We start with a short introduction to JBIG1. More detailed information -is provided in the "Introduction and overview" section of the JBIG1 -standard. Information on how to obtain a copy of the standard is -available from or -. - -Image data encoded with the JBIG algorithm is separated into planes, -layers, and stripes. Each plane contains one bit per pixel. The number -of planes stored in a JBIG data stream is the number of bits per -pixel. Resolution layers are numbered from 0 to D with 0 being the -layer with the lowest resolution and D the one with the highest. Each -next higher resolution layer has twice the number of rows and columns. -Layer 0 is encoded independently of any other data, all other -resolution layers are encoded as only the difference between the next -lower and the current layer. For applications that require very quick -access to parts of an image, it is possible to divide an image into -several horizontal stripes. All stripes of one resolution layer have -equal size, except perhaps the final one. The number of stripes of an -image is equal in all resolution layers and in all bit planes. - -The compressed data stream specified by the JBIG standard is called a -bi-level image entity (BIE). A BIE consists of a 20-byte header, -followed by an optional 1728-byte table (usually not present, except -in special applications) followed by a sequence of stripe data -entities (SDE). Each SDE encodes the content of one single stripe in -one plane of one resolution layer. Between the SDEs, other information -blocks (called floating marker segments) can also be present. They are -used to change certain parameters of the algorithm in the middle of an -image or contain additional application specific information. A BIE -looks like this: - - - +------------------------------------------------+ - | | - | 20-byte header (with image size, #planes, | - | #layers, stripe size, first layer, options, | - | SDE ordering, ...) | - | | - +------------------------------------------------+ - | | - | optional 1728-byte table | - | | - +------------------------------------------------+ - | | - | optional floating marker segments | - | | - +------------------------------------------------+ - | | - | stripe data entity | - | | - +------------------------------------------------+ - | | - | optional floating marker segments | - | | - +------------------------------------------------+ - | | - | stripe data entity | - | | - +------------------------------------------------+ - ... - +------------------------------------------------+ - | | - | stripe data entity | - | | - +------------------------------------------------+ - - -One BIE can contain all resolution layers of an image, but it is also -possible to store various resolution layers in several BIEs. The BIE -header contains the number of the first and the last resolution layer -stored in this BIE, as well as the size of the highest resolution -layer stored in this BIE. Progressive coding is deactivated by simply -storing the image in one single resolution layer. - -Different applications might have different requirements for the order -in which the SDEs for stripes of various planes and layers are stored -in the BIE, so all possible sensible orderings are allowed by the -standard and indicated by four bits in the header. - -It is possible to use the raw BIE data stream as specified by the JBIG -standard directly as the format of a file used for storing images. -This is what the pbmtojbg, jbgtopbm, pbmtojbg85, and jbgtopbm85 -conversion tools do that are provided in this package as demonstration -applications. However, as the BIE format has been designed for a large -number of very different applications, and to allow efficient direct -processing by special JBIG hardware chip implementations, the BIE -header contains only the minimum amount of information absolutely -required by the decompression algorithm. Many features expected from a -good file format are missing in the BIE data stream: - - - no "magic code" in the first few bytes to allow identification - of the file format on a typeless file system and to allow - automatic distinction from other compression algorithms - - - no standardized way to encode additional information such as a - textual description, information about the meaning of various bit - planes, the physical size and resolution of the document, etc. - - - a checksum to ensure image integrity - - - encryption and signature mechanisms - - - many things more - -Raw BIE data streams alone may therefore not be a suitable format for -document archiving and exchange. A standard format for this purpose -would typically combine a BIE representing the image data with an -additional header providing auxiliary information into one file. -Existing established multi-purpose file formats with a rich set of -auxiliary information attributes like TIFF could be extended easily to -also hold JBIG compressed data. - -On the other hand, in e.g. database applications, a BIE might be -stored directly in a binary variable-length field. Auxiliary -information would then be stored in other fields of the same record, -to simplify search operations. - - -2 Compressing an image - -2.1 Format of the source image - -To be processed by the jbig.c encoder, the image has to be present in -memory as separate bitmap planes. Each byte of a bitmap contains eight -pixels, where the most significant bit represents the leftmost of -these. Each line of a bitmap has to be stored in an integral number of -bytes. If the image width is not an integral multiple of eight, then -the final byte has to be padded with zero bits. - -For example the 23x5 pixels large single plane image: - - .XXXXX..XXX...X...XXX.. - .....X..X..X..X..X..... - .....X..XXX...X..X.XXX. - .X...X..X..X..X..X...X. - ..XXX...XXX...X...XXX.. - -is represented by the 15 bytes - - 01111100 11100010 00111000 - 00000100 10010010 01000000 - 00000100 11100010 01011100 - 01000100 10010010 01000100 - 00111000 11100010 00111000 - -or in hexadecimal notation - - 7c e2 38 04 92 40 04 e2 5c 44 92 44 38 e2 38 - -This is the format used in binary PBM files and it can also be handled -directly by the Xlib library of the X Window System. - -As JBIG can also handle images with multiple bit planes, the jbig.c -library functions accept and return always arrays of pointers to -bitmaps with one pointer per plane. - -For single-plane images, the standard recommends that a 0 pixel -represents the background and a 1 pixel represents the foreground -colour of an image, in other words, 0 is white and 1 is black for -scanned paper documents. For images with several bits per pixel, the -JBIG standard makes no recommendations about how various colours should -be encoded. - -For grey-scale images, by using a Gray code instead of a simple binary -weighted representation of the pixel intensity, some increase in -coding efficiency can be reached. - -A Gray code is also a binary representation of integer numbers, but it -has the property that the representations of the integer numbers i and -(i+1) always differ in exactly one bit. For example, the numbers 0 to -7 can be represented in normal binary code and Gray code as in the -following table: - - normal - number binary code Gray code - --------------------------------------- - 0 000 000 - 1 001 001 - 2 010 011 - 3 011 010 - 4 100 110 - 5 101 111 - 6 110 101 - 7 111 100 - -The form of Gray code shown above has the property that the second -half of the code (numbers 4 - 7) is simply the mirrored first half -(numbers 3 - 0) with the first bit set to one. This way, arbitrarily -large Gray codes can be generated quickly by mirroring the above -example and prefixing the first half with zeros and the second half -with ones as often as required. In grey-scale images, it is common -practise to use the all-0 code for black and the all-1 code for white. - -No matter whether a Gray code or a binary code is used for encoding a -pixel intensity in several bit planes, it always makes sense to store -the most significant (leftmost) bit in plane 0, which is transmitted -first. This way, a decoder could increase the precision of the -displayed pixel intensities while data is still being received and the -basic structure of the image will become visible as early as possible -during the transmission. - - -2.2 A simple compression application - -In order to use jbig.c in your application, just link libjbig.a to -your executable (on Unix systems just add -ljbig and -L. to the -command line options of your compiler, on other systems you will have -to write a new Makefile anyway), copy the file jbig.h into your source -directory and put the line - - #include "jbig.h" - -into your source code. - -The library interface follows object-oriented programming principles. -You have to declare a variable (object) - - struct jbg_enc_state s; - -which contains the current status of an encoder. Then you initialize -the encoder by calling the constructor function - - void jbg_enc_init(struct jbg_enc_state *s, unsigned long x, unsigned long y, - int pl, unsigned char **p, - void (*data_out)(unsigned char *start, size_t len, - void *file), - void *file); - -The parameters have the following meaning: - - s A pointer to the jbg_enc_state structure that you want - to initialize. - - x The width of your image in pixels. - - y The height of your image in pixels (lines). - - pl the number of bitmap planes you want to encode. - - p A pointer to an array of pl pointers, where each is again - pointing to the first byte of a bitmap as described in - section 2.1. - - data_out This is a call-back function that the encoder will - call during the compression process by in order to - deliver the BIE data to your application. The - parameters of the function data_out are a pointer - start to the new block of data being delivered, as - well as the number len of delivered bytes. The pointer - file is transparently delivered to data_out, as - specified in jbg_enc_init(). Typically, data_out will - write the BIE portion to a file, send it to a network - connection, or append it to some memory buffer. - - file A pointer parameter that is passed on to data_out() - and can be used, for instance, to allow data_out() to - distinguish by which compression task it has been - called in multi-threaded applications. - -In the simplest case, the compression is then started by calling the -function - - void jbg_enc_out(struct jbg_enc_state *s); - -which will deliver the complete BIE to data_out() in several calls. -After jbg_enc_out has returned, a call to the destructor function - - void jbg_enc_free(struct jbg_enc_state *s); - -will release any heap memory allocated by the previous functions. - - -A minimal example application, which sends the BIE of the above bitmap -to stdout, looks like this: - ---------------------------------------------------------------------------- -/* A sample JBIG encoding application */ - -#include -#include "jbig.h" - -void output_bie(unsigned char *start, size_t len, void *file) -{ - fwrite(start, 1, len, (FILE *) file); - - return; -} - -int main() -{ - unsigned char bitmap[15] = { - /* 23 x 5 pixels, "JBIG" */ - 0x7c, 0xe2, 0x38, 0x04, 0x92, 0x40, 0x04, 0xe2, - 0x5c, 0x44, 0x92, 0x44, 0x38, 0xe2, 0x38 - }; - unsigned char *bitmaps[1] = { bitmap }; - struct jbg_enc_state se; - - jbg_enc_init(&se, 23, 5, 1, bitmaps, - output_bie, stdout); /* initialize encoder */ - jbg_enc_out(&se); /* encode image */ - jbg_enc_free(&se); /* release allocated resources */ - - return 0; -} ---------------------------------------------------------------------------- - -This software produces a 42 byte long BIE. (JBIG is not very good at -compressing extremely small images like in this example, because the -arithmetic encoder requires some startup data in order to generate -reasonable statistics which influence the compression process and -because there is some header overhead.) - - -2.3 More about compression - -If jbg_enc_out() is called directly after jbg_enc_init(), the -following default values are used for various compression parameters: - - - Only one single resolution layer is used, i.e. no progressive - mode. - - - The number of lines per stripe is selected so that approximately - 35 stripes per image are used (as recommended in annex C of the - standard together with the suggested adaptive template change - algorithm). However, not less than 2 and not more than 128 lines - are used in order to stay within the suggested minimum parameter - support range specified in annex A of the standard). - - - All optional parts of the JBIG algorithm are activated (TPBON, - TPDON and DPON). - - - The default resolution reduction table and the default deterministic - prediction table are used - - - The maximal vertical offset of the adaptive template pixel is 0 - and the maximal horizontal offset is 8 (mx = 8, my = 0). - -In order to change any of these default parameters, additional -functions have to be called between jbg_enc_init() and jbg_enc_out(). - -In order to activate progressive encoding, it is possible to specify -with - - void jbg_enc_layers(struct jbg_enc_state *s, int d); - -the number d of differential resolution layers which shall be encoded -in addition to the lowest resolution layer 0. For example, if a -document with 60-micrometer pixels has to be stored, and the lowest -resolution layer shall have 240-micrometer pixels, so that a screen -previewer can directly decompress only the required resolution, then a -call - - jbg_enc_layers(&se, 2); - -will cause three layers with 240, 120 and 60 micrometers resolution to -be generated. - -If the application does not know what typical resolutions are used and -simply wants to ensure that the lowest resolution layer will fit into -a given maximal window size, then as an alternative, a call to - - int jbg_enc_lrlmax(struct jbg_enc_state *s, unsigned long mwidth, - unsigned long mheight); - -will cause the library to automatically determine the suitable number -of resolutions so that the lowest resolution layer 0 will not be -larger than mwidth x mheight pixels. E.g. if one wants to ensure that -systems with a 640 x 480 pixel large screen can decode the required -resolution directly, then call - - jbg_enc_lrlmax(&se, 640, 480); - -The return value is the number of differential layers selected. - -After the number of resolution layers has been specified by calls to -jbg_enc_layers() or jbg_enc_lrlmax(), by default, all these layers -will be written into the BIE. This can be changed with a call to - - int jbg_enc_lrange(struct jbg_enc_state *s, int dl, int dh); - -Parameter dl specifies the lowest resolution layer and dh the highest -resolution layer that will appear in the BIE. For instance, if layer 0 -shall be written to the first BIE and layer 1 and 2 shall be written -to a second one, then before writing the first BIE, call - - jbg_enc_lrange(&se, 0, 0); - -and before writing the second BIE with jbg_enc_out(), call - - jbg_enc_lrange(&se, 1, 2); - -If any of the parameters is negative, it will be ignored. The return -value is the total number of differential layers that will represent -the input image. This way, jbg_enc_lrange(&se, -1, -1) can be used to -query the layer of the full image resolution. - -A number of other more exotic options of the JBIG algorithm can be -modified by calling - - void jbg_enc_options(struct jbg_enc_state *s, int order, int options, - long l0, int mx, int my); - -before calling jbg_enc_out(). - -The order parameter can be a combination of the bits JBG_HITOLO, -JBG_SEQ, JBG_ILEAVE and JBG_SMID and it determines in which order -the SDEs are stored in the BIE. The bits have the following meaning: - - JBG_HITOLO Usually, the lower resolution layers are stored before - the higher resolution layers, so that a decoder can - already start to display a low resolution version of - the full image once a prefix of the BIE has been - received. When this bit is set, however, the BIE will - contain the higher layers before the lower layers. This - avoids additional buffer memory in the encoder and is - intended for applications where the encoder is connected - to a database which can easily reorder the SDEs before - sending them to a decoder. Warning: JBIG decoders are - not expected to support the HITOLO option (e.g. the - jbig.c decoder currently does not) so you should - normally not use it. - - JBG_SEQ Usually, at first all stripes of one resolution layer - are written to the BIE and then all stripes of the next - layer, and so on. When the SEQ bit is set however, then - all layers of the first stripe will be written, - followed by all layers of the second stripe, etc. This - option also should normally never be required and is - not supported by the current jbig.c decoder. - - JBG_SMID In case there exist several bit planes, then the order of - the stripes is determined by three loops over all stripes, - all planes and all layers. When SMID is set, the loop - over all stripes is the middle loop. - - JBG_ILEAVE If this bit is set, then at first all layers of one - plane are written before the encoder starts with the next - plane. - -The above description may be somewhat confusing, but the following -table (see also Table 11 in ITU-T T.82) clarifies how the three bits -JBG_SEQ, JBIG_ILEAVE and JBG_SMID influence the ordering of the loops -over all stripes, planes and layers: - - - Loops: - JBG_SEQ JBG_ILEAVE JBG_SMID | Outer Middle Inner - ------------------------------------+--------------------------- - 0 0 0 | p d s - 0 1 0 | d p s - 0 1 1 | d s p - 1 0 0 | s p d - 1 0 1 | p s d - 1 1 0 | s d p - - p: plane, s: stripe, d: layer - - -By default, the order combination JBG_ILEAVE | JBG_SMID is used. - -The options value can contain the following bits, which activate -some of the optional algorithms defined by JBIG: - - JBG_LRLTWO Normally, in the lowest resolution layer, pixels - from three lines around the next pixel are used - in order to determine the context in which the next - pixel is encoded. Some people in the JBIG committee - seem to have argued that using only 2 lines will - make software implementations a little bit faster, - however others have argued that using only two lines - will decrease compression efficiency by around 5%. - As you might expect from a committee, now both - alternatives are allowed and if JBG_LRLTWO is set, - the slightly faster but 5% less well compressing two - line alternative is selected. God bless the committees. - Although probably nobody will ever need this option, - it has been implemented in jbig.c and is off by - default. - - JBG_TPDON This activates the "typical prediction" algorithm - for differential layers which avoids that large - areas of equal colour have to be encoded at all. - This is on by default and there is no good reason to - switch it off except for debugging or preparing data - for cheap JBIG hardware that might not support this - option. - - JBG_TPBON Like JBG_TPDON this activates the "typical prediction" - algorithm in the lowest resolution layer. Also activated - by default. - - JBG_DPON This bit activates for the differential resolution - layers the "deterministic prediction" algorithm, - which avoids that higher resolution layer pixels are - encoded when their value can already be determined - with the knowledge of the neighbour pixels, the - corresponding lower resolution pixels and the - resolution reduction algorithm. This is also - activated by default and one reason for deactivating - it would be if the default resolution reduction - algorithm were replaced by another one. - - JBG_DELAY_AT Use a slightly less efficient algorithm to determine - when an adaptive template change is necessary. With - this bit set, the encoder output is compatible to the - conformance test examples in cause 7.2 of ITU-T T.82. - Then all adaptive template changes are delayed until - the first line of the next stripe. This option is by - default deactivated and is only required for passing a - special compatibility test suite. - -In addition, parameter l0 in jbg_enc_options() allows you to specify -the number of lines per stripe in resolution layer 0. The parameters -mx and my change the maximal offset allowed for the adaptive template -pixel. JBIG-KIT now supports the full range of possible mx values up -to 127 in the encoder and decoder, but my is at the moment ignored and -always set to 0. As the standard requires of all decoder -implementations only to support maximum values mx = 16 and my = 0, -higher values should normally be avoided in order to guarantee -interoperability. The ITU-T T.85 profile for JBIG in fax machines -requires support for mx = 127 and my = 0. Default is mx = 8 and my = -0. If any of the parameters order, options, mx or my is negative, or -l0 is zero, then the corresponding current value remains unmodified. - -The resolution reduction and deterministic prediction tables can also -be replaced. However as these options are anyway only for experts, -please have a look at the source code of jbg_enc_out() and the struct -members dppriv and res_tab of struct jbg_enc_state for the details of -how to do this, in case you really need it. The functions -jbg_int2dppriv and jbg_dppriv2int are provided in order to convert the -DPTABLE data from the format used in the standard into the more -efficient format used internally by JBIG-KIT. - -If you want to encode a grey-scale image, you can use the library -function - - void jbg_split_planes(unsigned long x, unsigned long y, int has_planes, - int encode_planes, - const unsigned char *src, unsigned char **dest, - int use_graycode); - -It separates an image in which each pixel is represented by one or -more bytes into separate bit planes. The dest array of pointers to -these bit planes can then be handed over to jbg_enc_init(). The -variables x and y specify the width and height of the image in pixels, -and has_planes specifies how many bits per pixel are used. As each -pixel is represented by an integral number of consecutive bytes, of -which each contains up to eight bits, the total length of the input -image array src[] will therefore be x * y * ((has_planes + 7) / 8) -bytes. The pixels are stored as usually in English reading order, and -for each pixel the integer value is stored with the most significant -byte coming first (Bigendian). This is exactly the format used in raw -PGM files. In encode_planes, the number of bit planes that shall be -extracted can be specified. This allows for instance to extract only -the most significant 8 bits of a 12-bit image, where each pixel is -represented by two bytes, by specifying has_planes = 12 and -encode_planes = 8. If use_graycode is zero, then the binary code of -the pixel integer values will be used instead of the Gray code. Plane -0 contains always the most significant bit. - - -3 Decompressing an image - -Like with the compression functions, if you want to use the jbig.c -library, you have to put the line - - #include "jbig.h" - -into your source code and link your executable with libjbig.a. - -The state of a JBIG decoder is stored completely in a struct and you -will have to define a variable like - - struct jbg_dec_state sd; - -which is initialized by a call to - - void jbg_dec_init(struct jbg_dec_state *s); - -After this, you can directly start to pass data from the BIE to the decoder -by calling the function - - int jbg_dec_in(struct jbg_dec_state *s, unsigned char *data, size_t len, - size_t *cnt); - -The pointer data points to the first byte of a data block with length -len, which contains bytes from a BIE. It is not necessary to pass a -whole BIE at once to jbg_dec_in(), it can arrive fragmented in any way -by calling jbg_dec_in() several times. It is also possible to send -several BIEs concatenated to jbg_dec_in(), however these then have to -fit together. If you send several BIEs to the decoder, the lowest -resolution layer in each following BIE has to be the highest -resolution layer in the previous BIE plus one and the image sizes and -number of planes also have to fit together, otherwise jbg_dec_in() -will return the error JBG_ENOCONT after the header of the new BIE has -been received completely. - -If pointer cnt is not NULL, then the number of bytes actually read -from the data block will be stored there. In case the data block did -not contain the end of the BIE, then the value JBG_EAGAIN will be -returned and *cnt equals len. - -Once the end of a BIE has been reached, the return value of -jbg_dec_in() will be JBG_EOK. After this has happened, the functions -and macros - - unsigned long jbg_dec_getwidth(struct jbg_dec_state *s); - unsigned long jbg_dec_getheight(struct jbg_dec_state *s); - int jbg_dec_getplanes(struct jbg_dec_state *s); - unsigned char *jbg_dec_getimage(struct jbg_dec_state *s, int plane); - unsigned long jbg_dec_getsize(struct jbg_dec_state *s); - -can be used to query the dimensions of the now completely decoded -image and to get a pointer to all bitmap planes. The bitmaps are -stored as described in section 2.1. The function jbg_dec_getsize() -calculates the number of bytes which one bitmap requires. - -The function - - void jbg_dec_merge_planes(const struct jbg_dec_state *s, int use_graycode, - void (*data_out)(unsigned char *start, size_t len, - void *file), void *file); - -allows you to merge the bit planes that can be accessed individually -with jbg_dec_getimage() into an array with one or more bytes per pixel -(i.e., the format provided to jbg_split_planes()). If use_graycode is -zero, then a binary encoding will be used. The output array will be -delivered via the callback function data_out, exactly in the same way -in which the encoder provides the BIE. The function - - unsigned long jbg_dec_getsize_merged(const struct jbg_dec_state *s); - -determines how long the data array delivered by jbg_dec_merge_planes() -is going to be. - -Before calling jbg_dec_in() the first time, it is possible to specify with -a call to - - void jbg_dec_maxsize(struct jbg_dec_state *s, unsigned long xmax, - unsigned long ymax); - -an abort criterion for progressively encoded images. For instance if an -application will display a whole document on a screen which is 1024 x -768 pixels large, then this application should call - - jbg_dec_maxsize(&sd, 1024, 768); - -before the decoding process starts. If the image has been encoded in -progressive mode (i.e. with several resolution layers), then the -decoder will stop with a return value JBG_EOK_INTR after the largest -resolution layer that is still smaller than 1024 x 768. However this -is no guarantee that the image which can then be read out using -jbg_dec_getimage(), etc. is really not larger than the specified -maximal size. The application will have to check the size of the -image, because the decoder does not automatically apply a resolution -reduction if no suitable resolution layer is available in the BIE. - -If jbg_dec_in() returned JBG_EOK_INTR or JBG_EOK, then it is possible -to continue calling jbg_dec_in() with the remaining data in order to -either decode the remaining resolution layers of the current BIE or in -order to add another BIE with additional resolution layers. In both -cases, after jbg_dec_in() returned JBG_EOK_INTR or JBG_EOK, *cnt is -probably not equal to len and the remainder of the data block which -has not yet been processed by the decoder has to be delivered to -jbg_dec_in() again. - -If any other return value than JBG_EOK, JBG_EOK_INTR or JBG_EAGAIN -has been returned by jbg_dec_in(), then an error has occurred and - - void jbg_dec_free(struct jbg_dec_state *s); - -should be called in order to release any allocated memory. The -destructor jbg_dec_free() should of course also be called, once the -decoded bitmap returned by jbg_dec_getimage() is no longer required -and the memory can be released. - -The function - - const char *jbg_strerror(int errnum); - -returns a pointer to a short single line test message that explains -the return value of jbg_dec_in(). This message can be used in order to -provide the user a brief informative message about what when wrong -while decompressing a JBIG image. The po/ subdirectory contains *.po -files that translate the English ASCII strings returned by -jbg_strerror() into other languages (e.g., for use with GNU gettext). -The four least-significant bits of the return value of jbg_dec_in() -may contain additional detailed technical information about the exact -test that spotted the error condition (see source code for details), -i.e. more than the text message returned by jbg_strerror() reveals. -Therefore it may be useful to display the return value itself as a -hexadecimal number, in addition to the string returned by -jbg_strerror(). - -The current implementation of the jbig.c decoder has the following -limitations: - - - The maximal vertical offset MY of the adaptive template pixel - must be zero. - - - HITOLO and SEQ bits must not be set in the order value. - - - Not more than JBG_ATMOVES_MAX (currently set to 64) ATMOVE - marker segments can be handled per stripe. - - - the number D of differential layers must be less than 32 - -None of the above limitations can be exceeded by a JBIG data stream -that conforms to the ITU-T T.85 application profile for the use of -JBIG1 in fax machines. - -The current implementation of the jbig.c decoder does not impose any -limits on the image size that it will process, as long as malloc() is -able to allocate enough heap space for the resulting bitmaps. The only -exception is that jbg_dec_in() will return "Input data stream uses -unimplemented JBIG features" (JBG_EIMPL | 1) if Y_D equals 0xffffffff, -which is an extreme value commonly used to encode images according to -ITU-T T.85 where the height was unknown when the BIH was emitted. -After jbg_dec_in() received the 20-byte long BIH at the start of the -BIE, it will malloc() to allocate enough memory to hold the requested -image planes and layers. If you want to defend your application -against excessive image-size parameters in a received BIH, then do -make sure that you check X_D, Y_D, and P against appropriate safety -limits before handing over the BIH to jbg_dec_in(). - -There are two more limitations of the current implementation of the -jbig.c decoder that might cause problems with processing JBIG data -stream that conform to ITU-T T.85: - - - The jbig.c decoder was designed to operate incrementally. - Each received byte is processed immediately as soon as it arrives. - As a result, it does not look beyond the SDRST/SDNORM at the end - of all stripes for any immediately following NEWLEN marker that - might reduce the number of lines encoded by the current stripe. - However section 6.2.6.2 of ITU-T T.82 says that a NEWLEN marker - segment "could refer to a line in the immediately preceding stripe - due to an unexpected termination of the image or the use of only - such stripe", and ITU-T.85 explicitly suggests the use of this - for fax machines that start transmission before having encountered - the end of the page. - - - The image size initially indicated in the BIE header is used to - allocate memory for a bitmap of this size. This means that BIEs - that set initially Y_D = 0xffffffff (as suggested in ITU-T T.85 - for fax machines that do not know the height of the page at the - start of the transmission) cannot be decoded directly by this - version. - -For both issues, there is a workaround available: - -If you encounter a BIE that has in the header the VLENGTH=1 option bit -set, then first wait until you have received the entire BIE and stored -it in memory. Then call the function - - int jbg_newlen(unsigned char *bie, size_t len); - -where bie is a pointer to the first byte of the BIE and len its length -in bytes. This function will scan the entire BIE for the first NEWLEN -marker segment. It will then take the updated image-height value YD -from it and use it to overwrite the YD value in the BIE header. The -jbg_newlen() can return some of the same error codes as jbg_dec_in(), -namely JBG_EOK if everything went fine, JBG_EAGAIN is the data -provided is too short to be a valid BIE, JBG_EINVAL if a format error -was encountered, and JBG_EABORT if an ABORT marker segment was found. -After having patched the image-height value in the BIE using -jbg_newlen(), simply hand over the BIE as usual to jbg_dec_in(). - -In general, for applications where NEWLEN markers can appear, in -particular fax reception, you should consider using the jbig85.c -decoder instead, as it can process BIEs with NEWLEN markers in a -single pass. - -A more detailed description of the JBIG-KIT implementation is - - Markus Kuhn: Effiziente Kompression von bi-level Bilddaten durch - kontextsensitive arithmetische Codierung. Studienarbeit, Lehrstuhl - für Betriebssysteme, IMMD IV, Universität Erlangen-Nürnberg, - Erlangen, July 1995. (German, 62 pages) - - -Please quote the above if you use JBIG-KIT in your research project. - -*** Happy compressing *** - -[end] diff --git a/converter/other/jbig/libjbig/jbig_ar.c b/converter/other/jbig/libjbig/jbig_ar.c deleted file mode 100644 index d23a317..0000000 --- a/converter/other/jbig/libjbig/jbig_ar.c +++ /dev/null @@ -1,417 +0,0 @@ -/* - * Arithmetic encoder and decoder of the portable JBIG - * compression library - * - * Markus Kuhn -- http://www.cl.cam.ac.uk/~mgk25/jbigkit/ - * - * This module implements a portable standard C arithmetic encoder - * and decoder used by the JBIG lossless bi-level image compression - * algorithm as specified in International Standard ISO 11544:1993 - * and ITU-T Recommendation T.82. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 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., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * If you want to use this program under different license conditions, - * then contact the author for an arrangement. - */ - -#include -#include "jbig_ar.h" - -/* - * Probability estimation tables for the arithmetic encoder/decoder - * given by ITU T.82 Table 24. - */ - -static short lsztab[113] = { - 0x5a1d, 0x2586, 0x1114, 0x080b, 0x03d8, 0x01da, 0x00e5, 0x006f, - 0x0036, 0x001a, 0x000d, 0x0006, 0x0003, 0x0001, 0x5a7f, 0x3f25, - 0x2cf2, 0x207c, 0x17b9, 0x1182, 0x0cef, 0x09a1, 0x072f, 0x055c, - 0x0406, 0x0303, 0x0240, 0x01b1, 0x0144, 0x00f5, 0x00b7, 0x008a, - 0x0068, 0x004e, 0x003b, 0x002c, 0x5ae1, 0x484c, 0x3a0d, 0x2ef1, - 0x261f, 0x1f33, 0x19a8, 0x1518, 0x1177, 0x0e74, 0x0bfb, 0x09f8, - 0x0861, 0x0706, 0x05cd, 0x04de, 0x040f, 0x0363, 0x02d4, 0x025c, - 0x01f8, 0x01a4, 0x0160, 0x0125, 0x00f6, 0x00cb, 0x00ab, 0x008f, - 0x5b12, 0x4d04, 0x412c, 0x37d8, 0x2fe8, 0x293c, 0x2379, 0x1edf, - 0x1aa9, 0x174e, 0x1424, 0x119c, 0x0f6b, 0x0d51, 0x0bb6, 0x0a40, - 0x5832, 0x4d1c, 0x438e, 0x3bdd, 0x34ee, 0x2eae, 0x299a, 0x2516, - 0x5570, 0x4ca9, 0x44d9, 0x3e22, 0x3824, 0x32b4, 0x2e17, 0x56a8, - 0x4f46, 0x47e5, 0x41cf, 0x3c3d, 0x375e, 0x5231, 0x4c0f, 0x4639, - 0x415e, 0x5627, 0x50e7, 0x4b85, 0x5597, 0x504f, 0x5a10, 0x5522, - 0x59eb -}; - -static unsigned char nmpstab[113] = { - 1, 2, 3, 4, 5, 6, 7, 8, - 9, 10, 11, 12, 13, 13, 15, 16, - 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32, - 33, 34, 35, 9, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, - 49, 50, 51, 52, 53, 54, 55, 56, - 57, 58, 59, 60, 61, 62, 63, 32, - 65, 66, 67, 68, 69, 70, 71, 72, - 73, 74, 75, 76, 77, 78, 79, 48, - 81, 82, 83, 84, 85, 86, 87, 71, - 89, 90, 91, 92, 93, 94, 86, 96, - 97, 98, 99, 100, 93, 102, 103, 104, - 99, 106, 107, 103, 109, 107, 111, 109, - 111 -}; - -/* - * least significant 7 bits (mask 0x7f) of nlpstab[] contain NLPS value, - * most significant bit (mask 0x80) contains SWTCH bit - */ -static unsigned char nlpstab[113] = { - 129, 14, 16, 18, 20, 23, 25, 28, - 30, 33, 35, 9, 10, 12, 143, 36, - 38, 39, 40, 42, 43, 45, 46, 48, - 49, 51, 52, 54, 56, 57, 59, 60, - 62, 63, 32, 33, 165, 64, 65, 67, - 68, 69, 70, 72, 73, 74, 75, 77, - 78, 79, 48, 50, 50, 51, 52, 53, - 54, 55, 56, 57, 58, 59, 61, 61, - 193, 80, 81, 82, 83, 84, 86, 87, - 87, 72, 72, 74, 74, 75, 77, 77, - 208, 88, 89, 90, 91, 92, 93, 86, - 216, 95, 96, 97, 99, 99, 93, 223, - 101, 102, 103, 104, 99, 105, 106, 107, - 103, 233, 108, 109, 110, 111, 238, 112, - 240 -}; - -/* - * The next functions implement the arithmedic encoder and decoder - * required for JBIG. The same algorithm is also used in the arithmetic - * variant of JPEG. - */ - -/* marker codes */ -#define MARKER_STUFF 0x00 -#define MARKER_ESC 0xff - -void arith_encode_init(struct jbg_arenc_state *s, int reuse_st) -{ - int i; - - if (!reuse_st) - for (i = 0; i < 4096; s->st[i++] = 0) ; - s->c = 0; - s->a = 0x10000L; - s->sc = 0; - s->ct = 11; - s->buffer = -1; /* empty */ - - return; -} - - -void arith_encode_flush(struct jbg_arenc_state *s) -{ - unsigned long temp; - - /* find the s->c in the coding interval with the largest - * number of trailing zero bits */ - if ((temp = (s->a - 1 + s->c) & 0xffff0000L) < s->c) - s->c = temp + 0x8000; - else - s->c = temp; - /* send remaining bytes to output */ - s->c <<= s->ct; - if (s->c & 0xf8000000L) { - /* one final overflow has to be handled */ - if (s->buffer >= 0) { - s->byte_out(s->buffer + 1, s->file); - if (s->buffer + 1 == MARKER_ESC) - s->byte_out(MARKER_STUFF, s->file); - } - /* output 0x00 bytes only when more non-0x00 will follow */ - if (s->c & 0x7fff800L) - for (; s->sc; --s->sc) - s->byte_out(0x00, s->file); - } else { - if (s->buffer >= 0) - s->byte_out(s->buffer, s->file); - /* T.82 figure 30 says buffer+1 for the above line! Typo? */ - for (; s->sc; --s->sc) { - s->byte_out(0xff, s->file); - s->byte_out(MARKER_STUFF, s->file); - } - } - /* output final bytes only if they are not 0x00 */ - if (s->c & 0x7fff800L) { - s->byte_out((s->c >> 19) & 0xff, s->file); - if (((s->c >> 19) & 0xff) == MARKER_ESC) - s->byte_out(MARKER_STUFF, s->file); - if (s->c & 0x7f800L) { - s->byte_out((s->c >> 11) & 0xff, s->file); - if (((s->c >> 11) & 0xff) == MARKER_ESC) - s->byte_out(MARKER_STUFF, s->file); - } - } - - return; -} - - -void arith_encode(struct jbg_arenc_state *s, int cx, int pix) -{ - register unsigned lsz, ss; - register unsigned char *st; - long temp; - - assert(cx >= 0 && cx < 4096); - st = s->st + cx; - ss = *st & 0x7f; - assert(ss < 113); - lsz = lsztab[ss]; - -#if 0 - fprintf(stderr, "pix = %d, cx = %d, mps = %d, st = %3d, lsz = 0x%04x, " - "a = 0x%05lx, c = 0x%08lx, ct = %2d, buf = 0x%02x\n", - pix, cx, !!(s->st[cx] & 0x80), ss, lsz, s->a, s->c, s->ct, - s->buffer); -#endif - - if (((pix << 7) ^ s->st[cx]) & 0x80) { - /* encode the less probable symbol */ - if ((s->a -= lsz) >= lsz) { - /* If the interval size (lsz) for the less probable symbol (LPS) - * is larger than the interval size for the MPS, then exchange - * the two symbols for coding efficiency, otherwise code the LPS - * as usual: */ - s->c += s->a; - s->a = lsz; - } - /* Check whether MPS/LPS exchange is necessary - * and chose next probability estimator status */ - *st &= 0x80; - *st ^= nlpstab[ss]; - } else { - /* encode the more probable symbol */ - if ((s->a -= lsz) & 0xffff8000L) - return; /* A >= 0x8000 -> ready, no renormalization required */ - if (s->a < lsz) { - /* If the interval size (lsz) for the less probable symbol (LPS) - * is larger than the interval size for the MPS, then exchange - * the two symbols for coding efficiency: */ - s->c += s->a; - s->a = lsz; - } - /* chose next probability estimator status */ - *st &= 0x80; - *st |= nmpstab[ss]; - } - - /* renormalization of coding interval */ - do { - s->a <<= 1; - s->c <<= 1; - --s->ct; - if (s->ct == 0) { - /* another byte is ready for output */ - temp = s->c >> 19; - if (temp & 0xffffff00L) { - /* handle overflow over all buffered 0xff bytes */ - if (s->buffer >= 0) { - ++s->buffer; - s->byte_out(s->buffer, s->file); - if (s->buffer == MARKER_ESC) - s->byte_out(MARKER_STUFF, s->file); - } - for (; s->sc; --s->sc) - s->byte_out(0x00, s->file); - s->buffer = temp & 0xff; /* new output byte, might overflow later */ - assert(s->buffer != 0xff); - /* can s->buffer really never become 0xff here? */ - } else if (temp == 0xff) { - /* buffer 0xff byte (which might overflow later) */ - ++s->sc; - } else { - /* output all buffered 0xff bytes, they will not overflow any more */ - if (s->buffer >= 0) - s->byte_out(s->buffer, s->file); - for (; s->sc; --s->sc) { - s->byte_out(0xff, s->file); - s->byte_out(MARKER_STUFF, s->file); - } - s->buffer = temp; /* buffer new output byte (can still overflow) */ - } - s->c &= 0x7ffffL; - s->ct = 8; - } - } while (s->a < 0x8000); - - return; -} - - -void arith_decode_init(struct jbg_ardec_state *s, int reuse_st) -{ - int i; - - if (!reuse_st) - for (i = 0; i < 4096; s->st[i++] = 0) ; - s->c = 0; - s->a = 1; - s->ct = 0; - s->startup = 1; - s->nopadding = 0; - return; -} - -/* - * Decode and return one symbol from the provided PSCD byte stream - * that starts in s->pscd_ptr and ends in the byte before s->pscd_end. - * The context cx is a 12-bit integer in the range 0..4095. This - * function will advance s->pscd_ptr each time it has consumed all - * information from that PSCD byte. - * - * If a symbol has been decoded successfully, the return value will be - * 0 or 1 (depending on the symbol). - * - * If the decoder was not able to decode a symbol from the provided - * PSCD, then the return value will be -1, and two cases can be - * distinguished: - * - * s->pscd_ptr == s->pscd_end: - * - * The decoder has used up all information in the provided PSCD - * bytes. Further PSCD bytes have to be provided (via new values of - * s->pscd_ptr and/or s->pscd_end) before another symbol can be - * decoded. - * - * s->pscd_ptr == s->pscd_end - 1: - * - * The decoder has used up all provided PSCD bytes except for the - * very last byte, because that has the value 0xff. The decoder can - * at this point not yet tell whether this 0xff belongs to a - * MARKER_STUFF sequence or marks the end of the PSCD. Further PSCD - * bytes have to be provided (via new values of s->pscd_ptr and/or - * s->pscd_end), including the not yet processed 0xff byte, before - * another symbol can be decoded successfully. - * - * If s->nopadding != 0, the decoder will return -2 when it reaches - * the first two bytes of the marker segment that follows (and - * terminates) the PSCD, but before decoding the first symbol that - * depends on a bit in the input data that could have been the result - * of zero padding, and might, therefore, never have been encoded. - * This gives the caller the opportunity to lookahead early enough - * beyond a terminating SDNORM/SDRST for a trailing NEWLEN (as - * required by T.85) before decoding remaining symbols. Call the - * decoder again afterwards as often as necessary (leaving s->pscd_ptr - * pointing to the start of the marker segment) to retrieve any - * required remaining symbols that might depend on padding. - * - * [Note that each PSCD can be decoded into an infinitely long - * sequence of symbols, because the encoder might have truncated away - * an arbitrarily long sequence of trailing 0x00 bytes, which the - * decoder will append automatically as needed when it reaches the end - * of the PSCD. Therefore, the decoder cannot report any end of the - * symbol sequence and other means (external to the PSCD and - * arithmetic decoding process) are needed to determine that.] - */ - -int arith_decode(struct jbg_ardec_state *s, int cx) -{ - register unsigned lsz, ss; - register unsigned char *st; - int pix; - - /* renormalization */ - while (s->a < 0x8000 || s->startup) { - while (s->ct <= 8 && s->ct >= 0) { - /* first we can move a new byte into s->c */ - if (s->pscd_ptr >= s->pscd_end) { - return -1; /* more bytes needed */ - } - if (*s->pscd_ptr == 0xff) - if (s->pscd_ptr + 1 >= s->pscd_end) { - return -1; /* final 0xff byte not processed */ - } else { - if (*(s->pscd_ptr + 1) == MARKER_STUFF) { - s->c |= 0xffL << (8 - s->ct); - s->ct += 8; - s->pscd_ptr += 2; - } else { - s->ct = -1; /* start padding with zero bytes */ - if (s->nopadding) { - s->nopadding = 0; - return -2; /* subsequent symbols might depend on zero padding */ - } - } - } - else { - s->c |= (long)*(s->pscd_ptr++) << (8 - s->ct); - s->ct += 8; - } - } - s->c <<= 1; - s->a <<= 1; - if (s->ct >= 0) s->ct--; - if (s->a == 0x10000L) - s->startup = 0; - } - - st = s->st + cx; - ss = *st & 0x7f; - assert(ss < 113); - lsz = lsztab[ss]; - -#if 0 - fprintf(stderr, "cx = %d, mps = %d, st = %3d, lsz = 0x%04x, a = 0x%05lx, " - "c = 0x%08lx, ct = %2d\n", - cx, !!(s->st[cx] & 0x80), ss, lsz, s->a, s->c, s->ct); -#endif - - if ((s->c >> 16) < (s->a -= lsz)) - if (s->a & 0xffff8000L) - return *st >> 7; - else { - /* MPS_EXCHANGE */ - if (s->a < lsz) { - pix = 1 - (*st >> 7); - /* Check whether MPS/LPS exchange is necessary - * and chose next probability estimator status */ - *st &= 0x80; - *st ^= nlpstab[ss]; - } else { - pix = *st >> 7; - *st &= 0x80; - *st |= nmpstab[ss]; - } - } - else { - /* LPS_EXCHANGE */ - if (s->a < lsz) { - s->c -= s->a << 16; - s->a = lsz; - pix = *st >> 7; - *st &= 0x80; - *st |= nmpstab[ss]; - } else { - s->c -= s->a << 16; - s->a = lsz; - pix = 1 - (*st >> 7); - /* Check whether MPS/LPS exchange is necessary - * and chose next probability estimator status */ - *st &= 0x80; - *st ^= nlpstab[ss]; - } - } - - return pix; -} diff --git a/converter/other/jpeg2000/libjasper/Makefile b/converter/other/jpeg2000/libjasper/Makefile deleted file mode 100644 index ddbd148..0000000 --- a/converter/other/jpeg2000/libjasper/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -ifeq ($(SRCDIR)x,x) - SRCDIR = $(CURDIR)/../../../.. - BUILDDIR = $(SRCDIR) -endif -SUBDIR = converter/other/jpeg2000/libjasper -VPATH=.:$(SRCDIR)/$(SUBDIR) - -include $(BUILDDIR)/config.mk - -SUBDIRS = base jp2 jpc -LIB_OBJECTS = -JASPERSRCDIR = $(SRCDIR)/$(SUBDIR) - -# NOTE: The library source code uses 64 bit types, so you cannot -# build it (compile will fail) if you don't have 64 bit types defined -# by pm_config.h (normally by including ) - -all: libjasper.a - -include $(SRCDIR)/$(SUBDIR)/common.mk - -# We cheat a bit here -- the real dependencies are all the .o files listed -# in the part list, but since we don't know what those are, we just do a -# 'make all' in each subdirectory to get them built. That means it always -# looks like dependencies were rebuilt and libjasper.a gets rebuilt every -# time. -libjasper.a: $(SUBDIRS:%=%/all) partlist - $(AR) rc $@ $(shell cat partlist) - $(RANLIB) $@ - diff --git a/converter/other/jpeg2000/libjasper/README b/converter/other/jpeg2000/libjasper/README deleted file mode 100644 index b0512fe..0000000 --- a/converter/other/jpeg2000/libjasper/README +++ /dev/null @@ -1,19 +0,0 @@ -The code in the directory 'libjasper' is taken from the Jasper package. -In particular, from the 'src/libjasper' directory of Jasper Version -1.600.0. - -The adaptation was done by Bryan Henderson on 2002.10.26. - -The adaptation involved: - - - Remove stuff for formats other than JPEG-2000. - - - Replace build stuff (Jasper uses GNU Autoconf/Automake/Libtool). - - - Make JP2 decoder not dump the box to stderr unless debug is turned on. - -See . - - -You cannot build this library without a 64 bit compiler (and 64 bit -types such as int64_t defined). It does a lot of 64 bit arithmetic. diff --git a/converter/other/jpeg2000/libjasper/base/Makefile b/converter/other/jpeg2000/libjasper/base/Makefile deleted file mode 100644 index ad84f04..0000000 --- a/converter/other/jpeg2000/libjasper/base/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -ifeq ($(SRCDIR)x,x) - SRCDIR = $(CURDIR)/../../../../.. - BUILDDIR = $(SRCDIR) -endif -SUBDIR = converter/other/jpeg2000/libjasper/base -VPATH=.:$(SRCDIR)/$(SUBDIR) - -JASPERSRCDIR=$(SRCDIR)/$(SUBDIR)/.. - -include $(BUILDDIR)/config.mk - -LIB_OBJECTS = jas_debug.o jas_getopt.o jas_image.o jas_init.o \ - jas_malloc.o jas_seq.o jas_stream.o jas_string.o \ - jas_tvp.o jas_version.o - -MERGE_OBJECTS = - -all: partlist $(LIB_OBJECTS) - -include $(JASPERSRCDIR)/common.mk - diff --git a/converter/other/jpeg2000/libjasper/base/jas_debug.c b/converter/other/jpeg2000/libjasper/base/jas_debug.c deleted file mode 100644 index 4248178..0000000 --- a/converter/other/jpeg2000/libjasper/base/jas_debug.c +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include - -#include "jasper/jas_types.h" -#include "jasper/jas_debug.h" - -/******************************************************************************\ -* Local data. -\******************************************************************************/ - -static int jas_dbglevel = 0; -/* The debug level. */ - -/******************************************************************************\ -* Code for getting/setting the debug level. -\******************************************************************************/ - -/* Set the library debug level. */ -int jas_setdbglevel(int dbglevel) -{ - int olddbglevel; - - /* Save the old debug level. */ - olddbglevel = jas_dbglevel; - - /* Change the debug level. */ - jas_dbglevel = dbglevel; - - /* Return the old debug level. */ - return olddbglevel; -} - -/* Get the library debug level. */ -int jas_getdbglevel() -{ - return jas_dbglevel; -} - -/******************************************************************************\ -* Code. -\******************************************************************************/ - -/* Perform formatted output to standard error. */ -int jas_eprintf(const char *fmt, ...) -{ - int ret; - va_list ap; - - va_start(ap, fmt); - ret = vfprintf(stderr, fmt, ap); - va_end(ap); - return ret; -} - -/* Dump memory to a stream. */ -int jas_memdump(FILE *out, void *data, size_t len) -{ - int i; - int j; - unsigned char *dp; - dp = data; - for (i = 0; i < len; i += 16) { - fprintf(out, "%04x:", i); - for (j = 0; j < 16; ++j) { - if (i + j < len) { - fprintf(out, " %02x", dp[i + j]); - } - } - fprintf(out, "\n"); - } - return 0; -} diff --git a/converter/other/jpeg2000/libjasper/base/jas_getopt.c b/converter/other/jpeg2000/libjasper/base/jas_getopt.c deleted file mode 100644 index 7f579b3..0000000 --- a/converter/other/jpeg2000/libjasper/base/jas_getopt.c +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright (c) 1999-2000, Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Command Line Option Parsing Library - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include - -#include "jasper/jas_getopt.h" -#include "jasper/jas_math.h" - -/******************************************************************************\ -* Global data. -\******************************************************************************/ - -int jas_optind = 0; -int jas_opterr = 1; -char *jas_optarg = 0; - -/******************************************************************************\ -* Code. -\******************************************************************************/ - -static jas_opt_t *jas_optlookup(jas_opt_t *opts, char *name) -{ - jas_opt_t *opt; - - for (opt = opts; opt->id >= 0 && opt->name; ++opt) { - if (!strcmp(opt->name, name)) { - return opt; - } - } - return 0; -} - -int jas_getopt(int argc, char **argv, jas_opt_t *opts) -{ - char *cp; - int id; - int hasarg; - jas_opt_t *opt; - char *s; - - if (!jas_optind) { - jas_optind = JAS_MIN(1, argc); - } - while (jas_optind < argc) { - s = cp = argv[jas_optind]; - if (*cp == '-') { - /* We are processing an option. */ - ++jas_optind; - if (*++cp == '-') { - /* We are processing a long option. */ - ++cp; - if (*cp == '\0') { - /* This is the end of the options. */ - return JAS_GETOPT_EOF; - } - if (!(opt = jas_optlookup(opts, cp))) { - if (jas_opterr) { - fprintf(stderr, "unknown long option %s\n", s); - } - return JAS_GETOPT_ERR; - } - hasarg = (opt->flags & JAS_OPT_HASARG) != 0; - id = opt->id; - } else { - /* We are processing a short option. */ - if (strlen(cp) != 1 || - !(opt = jas_optlookup(opts, cp))) { - if (jas_opterr) { - fprintf(stderr, "unknown short option %s\n", s); - } - return JAS_GETOPT_ERR; - } - hasarg = (opt->flags & JAS_OPT_HASARG) != 0; - id = opt->id; - } - if (hasarg) { - /* The option has an argument. */ - if (jas_optind >= argc) { - if (jas_opterr) { - fprintf(stderr, "missing argument for option %s\n", s); - } - return JAS_GETOPT_ERR; - } - jas_optarg = argv[jas_optind]; - ++jas_optind; - } else { - /* The option does not have an argument. */ - jas_optarg = 0; - } - return id; - } else { - /* We are not processing an option. */ - return JAS_GETOPT_EOF; - } - } - return JAS_GETOPT_EOF; -} diff --git a/converter/other/jpeg2000/libjasper/base/jas_image.c b/converter/other/jpeg2000/libjasper/base/jas_image.c deleted file mode 100644 index 903b45c..0000000 --- a/converter/other/jpeg2000/libjasper/base/jas_image.c +++ /dev/null @@ -1,968 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Image Library - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include -#include -#include -#include - -#include "jasper/jas_math.h" -#include "jasper/jas_image.h" -#include "jasper/jas_malloc.h" -#include "jasper/jas_string.h" - -/******************************************************************************\ -* Types. -\******************************************************************************/ - -/******************************************************************************\ -* Local prototypes. -\******************************************************************************/ - -static void jas_image_cmpt_destroy(jas_image_cmpt_t *cmpt); -static jas_image_cmpt_t *jas_image_cmpt_create(uint_fast32_t tlx, uint_fast32_t tly, - uint_fast32_t hstep, uint_fast32_t vstep, uint_fast32_t width, uint_fast32_t - height, uint_fast16_t depth, bool sgnd, uint_fast32_t inmem); -static void jas_image_setbbox(jas_image_t *image); -static jas_image_cmpt_t *jas_image_cmpt_copy(jas_image_cmpt_t *cmpt); -static jas_image_cmpt_t *jas_image_cmpt_create0(); -static int jas_image_growcmpts(jas_image_t *image, int maxcmpts); -static uint_fast32_t inttobits(jas_seqent_t v, int prec, bool sgnd); -static jas_seqent_t bitstoint(uint_fast32_t v, int prec, bool sgnd); - -/******************************************************************************\ -* Global data. -\******************************************************************************/ - -static int jas_image_numfmts = 0; -static jas_image_fmtinfo_t jas_image_fmtinfos[JAS_IMAGE_MAXFMTS]; - -/******************************************************************************\ -* Create and destroy operations. -\******************************************************************************/ - -jas_image_t *jas_image_create(uint_fast16_t numcmpts, jas_image_cmptparm_t *cmptparms, - int colorspace) -{ - jas_image_t *image; - uint_fast32_t rawsize; - uint_fast32_t inmem; - uint_fast16_t cmptno; - jas_image_cmptparm_t *cmptparm; - - if (!(image = jas_image_create0())) { - return 0; - } - - image->colorspace_ = colorspace; - image->maxcmpts_ = numcmpts; - image->inmem_ = true; - - /* Allocate memory for the per-component information. */ - if (!(image->cmpts_ = jas_malloc(image->maxcmpts_ * - sizeof(jas_image_cmpt_t *)))) { - jas_image_destroy(image); - return 0; - } - /* Initialize in case of failure. */ - for (cmptno = 0; cmptno < image->maxcmpts_; ++cmptno) { - image->cmpts_[cmptno] = 0; - } - - /* Compute the approximate raw size of the image. */ - rawsize = 0; - for (cmptno = 0, cmptparm = cmptparms; cmptno < numcmpts; ++cmptno, - ++cmptparm) { - rawsize += cmptparm->width * cmptparm->height * - (cmptparm->prec + 7) / 8; - } - /* Decide whether to buffer the image data in memory, based on the - raw size of the image. */ - inmem = (rawsize < JAS_IMAGE_INMEMTHRESH); - - /* Create the individual image components. */ - for (cmptno = 0, cmptparm = cmptparms; cmptno < numcmpts; ++cmptno, - ++cmptparm) { - if (!(image->cmpts_[cmptno] = jas_image_cmpt_create(cmptparm->tlx, - cmptparm->tly, cmptparm->hstep, cmptparm->vstep, - cmptparm->width, cmptparm->height, cmptparm->prec, - cmptparm->sgnd, inmem))) { - jas_image_destroy(image); - return 0; - } - ++image->numcmpts_; - } - - /* Determine the bounding box for all of the components on the - reference grid (i.e., the image area) */ - jas_image_setbbox(image); - - return image; -} - -jas_image_t *jas_image_create0() -{ - jas_image_t *image; - - if (!(image = jas_malloc(sizeof(jas_image_t)))) { - return 0; - } - - image->tlx_ = 0; - image->tly_ = 0; - image->brx_ = 0; - image->bry_ = 0; - image->colorspace_ = JAS_IMAGE_CS_UNKNOWN; - image->numcmpts_ = 0; - image->maxcmpts_ = 0; - image->cmpts_ = 0; - image->inmem_ = true; - image->iccp_ = 0; - image->iccplen_ = 0; - - return image; -} - -jas_image_t *jas_image_copy(jas_image_t *image) -{ - jas_image_t *newimage; - int cmptno; - - newimage = jas_image_create0(); - if (jas_image_growcmpts(newimage, image->numcmpts_)) { - goto error; - } - for (cmptno = 0; cmptno < image->numcmpts_; ++cmptno) { - if (!(newimage->cmpts_[cmptno] = jas_image_cmpt_copy(image->cmpts_[cmptno]))) { - goto error; - } - ++newimage->numcmpts_; - } - - jas_image_setbbox(newimage); - - return newimage; -error: - if (newimage) { - jas_image_destroy(newimage); - } - return 0; -} - -static jas_image_cmpt_t *jas_image_cmpt_create0() -{ - jas_image_cmpt_t *cmpt; - if (!(cmpt = jas_malloc(sizeof(jas_image_cmpt_t)))) { - return 0; - } - memset(cmpt, 0, sizeof(jas_image_cmpt_t)); - cmpt->type_ = JAS_IMAGE_CT_UNKNOWN; - return cmpt; -} - -static jas_image_cmpt_t *jas_image_cmpt_copy(jas_image_cmpt_t *cmpt) -{ - jas_image_cmpt_t *newcmpt; - - if (!(newcmpt = jas_image_cmpt_create0())) { - return 0; - } - newcmpt->tlx_ = cmpt->tlx_; - newcmpt->tly_ = cmpt->tly_; - newcmpt->hstep_ = cmpt->hstep_; - newcmpt->vstep_ = cmpt->vstep_; - newcmpt->width_ = cmpt->width_; - newcmpt->height_ = cmpt->height_; - newcmpt->prec_ = cmpt->prec_; - newcmpt->sgnd_ = cmpt->sgnd_; - newcmpt->cps_ = cmpt->cps_; - newcmpt->type_ = cmpt->type_; - if (!(newcmpt->stream_ = jas_stream_memopen(0, 0))) { - return 0; - } - if (jas_stream_seek(cmpt->stream_, 0, SEEK_SET)) { - return 0; - } - if (jas_stream_copy(newcmpt->stream_, cmpt->stream_, -1)) { - return 0; - } - if (jas_stream_seek(newcmpt->stream_, 0, SEEK_SET)) { - return 0; - } - return newcmpt; -} - -void jas_image_destroy(jas_image_t *image) -{ - int i; - - if (image->cmpts_) { - for (i = 0; i < image->numcmpts_; ++i) { - jas_image_cmpt_destroy(image->cmpts_[i]); - image->cmpts_[i] = 0; - } - jas_free(image->cmpts_); - } - jas_free(image); -} - -static jas_image_cmpt_t *jas_image_cmpt_create(uint_fast32_t tlx, uint_fast32_t tly, - uint_fast32_t hstep, uint_fast32_t vstep, uint_fast32_t width, uint_fast32_t - height, uint_fast16_t depth, bool sgnd, uint_fast32_t inmem) -{ - jas_image_cmpt_t *cmpt; - long size; - - if (!(cmpt = jas_malloc(sizeof(jas_image_cmpt_t)))) { - return 0; - } - - cmpt->tlx_ = tlx; - cmpt->tly_ = tly; - cmpt->hstep_ = hstep; - cmpt->vstep_ = vstep; - cmpt->width_ = width; - cmpt->height_ = height; - cmpt->prec_ = depth; - cmpt->sgnd_ = sgnd; - cmpt->stream_ = 0; - cmpt->cps_ = (depth + 7) / 8; - - size = cmpt->width_ * cmpt->height_ * cmpt->cps_; - cmpt->stream_ = (inmem) ? jas_stream_memopen(0, size) : jas_stream_tmpfile(); - if (!cmpt->stream_) { - jas_image_cmpt_destroy(cmpt); - return 0; - } - - /* Zero the component data. This isn't necessary, but it is - convenient for debugging purposes. */ - if (jas_stream_seek(cmpt->stream_, size - 1, SEEK_SET) < 0 || - jas_stream_putc(cmpt->stream_, 0) == EOF || - jas_stream_seek(cmpt->stream_, 0, SEEK_SET) < 0) { - jas_image_cmpt_destroy(cmpt); - return 0; - } - - return cmpt; -} - -static void jas_image_cmpt_destroy(jas_image_cmpt_t *cmpt) -{ - if (cmpt->stream_) { - jas_stream_close(cmpt->stream_); - } - jas_free(cmpt); -} - -/*****************************************************************************\ -* Load and save operations. -\*****************************************************************************/ - -jas_image_t *jas_image_decode(jas_stream_t *in, int fmt, char *optstr) -{ - jas_image_fmtinfo_t *fmtinfo; - - /* If possible, try to determine the format of the input data. */ - if (fmt < 0) { - if ((fmt = jas_image_getfmt(in)) < 0) { - return 0; - } - } - if (!(fmtinfo = jas_image_lookupfmtbyid(fmt))) { - return 0; - } - return (fmtinfo->ops.decode) ? (*fmtinfo->ops.decode)(in, optstr) : 0; -} - -int jas_image_encode(jas_image_t *image, jas_stream_t *out, int fmt, char *optstr) -{ - jas_image_fmtinfo_t *fmtinfo; - if (!(fmtinfo = jas_image_lookupfmtbyid(fmt))) { - return -1; - } - return (fmtinfo->ops.encode) ? (*fmtinfo->ops.encode)(image, out, - optstr) : (-1); -} - -/******************************************************************************\ -* Component read and write operations. -\******************************************************************************/ - -int jas_image_readcmpt(jas_image_t *image, uint_fast16_t cmptno, uint_fast32_t x, uint_fast32_t y, uint_fast32_t width, - uint_fast32_t height, jas_matrix_t *data) -{ - jas_image_cmpt_t *cmpt; - uint_fast32_t i; - uint_fast32_t j; - int k; - jas_seqent_t v; - int c; - jas_seqent_t *dr; - jas_seqent_t *d; - int drs; - - if (cmptno >= image->numcmpts_) { - return -1; - } - - cmpt = image->cmpts_[cmptno]; - if (x >= cmpt->width_ || y >= cmpt->height_ || - x + width > cmpt->width_ || - y + height > cmpt->height_) { - return -1; - } - - if (jas_matrix_numrows(data) != height || jas_matrix_numcols(data) != width) { - if (jas_matrix_resize(data, height, width)) { - return -1; - } - } - - dr = jas_matrix_getref(data, 0, 0); - drs = jas_matrix_rowstep(data); - for (i = 0; i < height; ++i, dr += drs) { - d = dr; - if (jas_stream_seek(cmpt->stream_, (cmpt->width_ * (y + i) + x) - * cmpt->cps_, SEEK_SET) < 0) { - return -1; - } - for (j = width; j > 0; --j, ++d) { - v = 0; - for (k = cmpt->cps_; k > 0; --k) { - if ((c = jas_stream_getc(cmpt->stream_)) == EOF) { - return -1; - } - v = (v << 8) | (c & 0xff); - } - *d = bitstoint(v, cmpt->prec_, cmpt->sgnd_); - } - } - - return 0; -} - -#if 0 -int_fast64_t jas_image_readcmpt1(jas_image_t *image, uint_fast16_t cmptno, - uint_fast32_t x, uint_fast32_t y) -{ - jas_image_cmpt_t *cmpt; - int k; - int c; - int_fast64_t v; - cmpt = image->cmpts_[cmptno]; - if (jas_stream_seek(cmpt->stream_, (cmpt->width_ * y + x) * cmpt->cps_, - SEEK_SET) < 0) { - goto error; - } - v = 0; - for (k = cmpt->cps_; k > 0; --k) { - if ((c = jas_stream_getc(cmpt->stream_)) == EOF) { - goto error; - } - v = (v << 8) | (c & 0xff); - } -if (cmpt->sgnd_) { - abort(); -} - - return v; - -error: - return 0; -} -#endif - -int jas_image_writecmpt(jas_image_t *image, uint_fast16_t cmptno, uint_fast32_t x, uint_fast32_t y, uint_fast32_t width, - uint_fast32_t height, jas_matrix_t *data) -{ - jas_image_cmpt_t *cmpt; - uint_fast32_t i; - uint_fast32_t j; - jas_seqent_t *d; - jas_seqent_t *dr; - int drs; - jas_seqent_t v; - int k; - int c; - - if (cmptno >= image->numcmpts_) { - return -1; - } - - cmpt = image->cmpts_[cmptno]; - if (x >= cmpt->width_ || y >= cmpt->height_ || - x + width > cmpt->width_ || - y + height > cmpt->height_) { - return -1; - } - - if (jas_matrix_numrows(data) != height || jas_matrix_numcols(data) != width) { - return -1; - } - - dr = jas_matrix_getref(data, 0, 0); - drs = jas_matrix_rowstep(data); - for (i = 0; i < height; ++i, dr += drs) { - d = dr; - if (jas_stream_seek(cmpt->stream_, (cmpt->width_ * (y + i) + x) - * cmpt->cps_, SEEK_SET) < 0) { - return -1; - } - for (j = width; j > 0; --j, ++d) { - v = inttobits(*d, cmpt->prec_, cmpt->sgnd_); - for (k = cmpt->cps_; k > 0; --k) { - c = (v >> (8 * (cmpt->cps_ - 1))) & 0xff; - if (jas_stream_putc(cmpt->stream_, - (unsigned char) c) == EOF) { - return -1; - } - v <<= 8; - } - } - } - - return 0; -} - -/******************************************************************************\ -* File format operations. -\******************************************************************************/ - -void jas_image_clearfmts() -{ - int i; - jas_image_fmtinfo_t *fmtinfo; - for (i = 0; i < jas_image_numfmts; ++i) { - fmtinfo = &jas_image_fmtinfos[i]; - if (fmtinfo->name) { - jas_free(fmtinfo->name); - fmtinfo->name = 0; - } - if (fmtinfo->ext) { - jas_free(fmtinfo->ext); - fmtinfo->ext = 0; - } - if (fmtinfo->desc) { - jas_free(fmtinfo->desc); - fmtinfo->desc = 0; - } - } - jas_image_numfmts = 0; -} - -int jas_image_addfmt(int id, const char *name, const char *ext, - const char *desc, - jas_image_fmtops_t *ops) -{ - jas_image_fmtinfo_t *fmtinfo; - assert(id >= 0 && name && ext && ops); - if (jas_image_numfmts >= JAS_IMAGE_MAXFMTS) { - return -1; - } - fmtinfo = &jas_image_fmtinfos[jas_image_numfmts]; - fmtinfo->id = id; - if (!(fmtinfo->name = jas_strdup(name))) { - return -1; - } - if (!(fmtinfo->ext = jas_strdup(ext))) { - jas_free(fmtinfo->name); - return -1; - } - if (!(fmtinfo->desc = jas_strdup(desc))) { - jas_free(fmtinfo->name); - jas_free(fmtinfo->ext); - return -1; - } - fmtinfo->ops = *ops; - ++jas_image_numfmts; - return 0; -} - -int jas_image_strtofmt(char *name) -{ - jas_image_fmtinfo_t *fmtinfo; - if (!(fmtinfo = jas_image_lookupfmtbyname(name))) { - return -1; - } - return fmtinfo->id; -} - -char *jas_image_fmttostr(int fmt) -{ - jas_image_fmtinfo_t *fmtinfo; - if (!(fmtinfo = jas_image_lookupfmtbyid(fmt))) { - return 0; - } - return fmtinfo->name; -} - -int jas_image_getfmt(jas_stream_t *in) -{ - jas_image_fmtinfo_t *fmtinfo; - int found; - int i; - - /* Check for data in each of the formats we know. */ - found = 0; - for (i = 0, fmtinfo = jas_image_fmtinfos; i < jas_image_numfmts; ++i, - ++fmtinfo) { - if (fmtinfo->ops.validate) { - /* Is the input data valid for this format? */ - if (!(*fmtinfo->ops.validate)(in)) { - found = 1; - break; - } - } - } - return found ? fmtinfo->id : (-1); -} - -int jas_image_fmtfromname(char *name) -{ - int i; - char *ext; - jas_image_fmtinfo_t *fmtinfo; - /* Get the file name extension. */ - if (!(ext = strrchr(name, '.'))) { - return -1; - } - ++ext; - /* Try to find a format that uses this extension. */ - for (i = 0, fmtinfo = jas_image_fmtinfos; i < jas_image_numfmts; ++i, - ++fmtinfo) { - /* Do we have a match? */ - if (!strcmp(ext, fmtinfo->ext)) { - return fmtinfo->id; - } - } - return -1; -} - -/******************************************************************************\ -* Miscellaneous operations. -\******************************************************************************/ - -uint_fast32_t jas_image_rawsize(jas_image_t *image) -{ - uint_fast32_t rawsize; - uint_fast32_t cmptno; - jas_image_cmpt_t *cmpt; - - rawsize = 0; - for (cmptno = 0; cmptno < image->numcmpts_; ++cmptno) { - cmpt = image->cmpts_[cmptno]; - rawsize += (cmpt->width_ * cmpt->height_ * cmpt->prec_ + - 7) / 8; - } - return rawsize; -} - -void jas_image_delcmpt(jas_image_t *image, uint_fast16_t cmptno) -{ - if (cmptno >= image->numcmpts_) { - return; - } - jas_image_cmpt_destroy(image->cmpts_[cmptno]); - if (cmptno < image->numcmpts_) { - memmove(&image->cmpts_[cmptno], &image->cmpts_[cmptno + 1], - (image->numcmpts_ - 1 - cmptno) * sizeof(jas_image_cmpt_t *)); - } - --image->numcmpts_; - - jas_image_setbbox(image); -} - -int jas_image_addcmpt(jas_image_t *image, uint_fast16_t cmptno, - jas_image_cmptparm_t *cmptparm) -{ - jas_image_cmpt_t *newcmpt; - assert(cmptno <= image->numcmpts_); - if (image->numcmpts_ >= image->maxcmpts_) { - if (jas_image_growcmpts(image, image->maxcmpts_ + 128)) { - return -1; - } - } - if (!(newcmpt = jas_image_cmpt_create(cmptparm->tlx, - cmptparm->tly, cmptparm->hstep, cmptparm->vstep, - cmptparm->width, cmptparm->height, cmptparm->prec, - cmptparm->sgnd, 1))) { - return -1; - } - if (cmptno < image->numcmpts_) { - memmove(&image->cmpts_[cmptno + 1], &image->cmpts_[cmptno], - (image->numcmpts_ - cmptno) * sizeof(jas_image_cmpt_t *)); - } - image->cmpts_[cmptno] = newcmpt; - ++image->numcmpts_; - - jas_image_setbbox(image); - - return 0; -} - -jas_image_fmtinfo_t *jas_image_lookupfmtbyid(int id) -{ - int i; - jas_image_fmtinfo_t *fmtinfo; - - for (i = 0, fmtinfo = jas_image_fmtinfos; i < jas_image_numfmts; ++i, ++fmtinfo) { - if (fmtinfo->id == id) { - return fmtinfo; - } - } - return 0; -} - -jas_image_fmtinfo_t *jas_image_lookupfmtbyname(const char *name) -{ - int i; - jas_image_fmtinfo_t *fmtinfo; - - for (i = 0, fmtinfo = jas_image_fmtinfos; i < jas_image_numfmts; ++i, ++fmtinfo) { - if (!strcmp(fmtinfo->name, name)) { - return fmtinfo; - } - } - return 0; -} - - - - - -static uint_fast32_t inttobits(jas_seqent_t v, int prec, bool sgnd) -{ - uint_fast32_t ret; - ret = ((sgnd && v < 0) ? ((1 << prec) + v) : v) & JAS_ONES(prec); - return ret; -} - -static jas_seqent_t bitstoint(uint_fast32_t v, int prec, bool sgnd) -{ - jas_seqent_t ret; - v &= JAS_ONES(prec); - ret = (sgnd && (v & (1 << (prec - 1)))) ? (v - (1 << prec)) : v; - return ret; -} - -static void jas_image_setbbox(jas_image_t *image) -{ - jas_image_cmpt_t *cmpt; - int cmptno; - int_fast32_t x; - int_fast32_t y; - - if (image->numcmpts_ > 0) { - /* Determine the bounding box for all of the components on the - reference grid (i.e., the image area) */ - cmpt = image->cmpts_[0]; - image->tlx_ = cmpt->tlx_; - image->tly_ = cmpt->tly_; - image->brx_ = cmpt->tlx_ + cmpt->hstep_ * (cmpt->width_ - 1) + 1; - image->bry_ = cmpt->tly_ + cmpt->vstep_ * (cmpt->height_ - 1) + 1; - for (cmptno = 1; cmptno < image->numcmpts_; ++cmptno) { - cmpt = image->cmpts_[cmptno]; - if (image->tlx_ > cmpt->tlx_) { - image->tlx_ = cmpt->tlx_; - } - if (image->tly_ > cmpt->tly_) { - image->tly_ = cmpt->tly_; - } - x = cmpt->tlx_ + cmpt->hstep_ * (cmpt->width_ - 1) + 1; - if (image->brx_ < x) { - image->brx_ = x; - } - y = cmpt->tly_ + cmpt->vstep_ * (cmpt->height_ - 1) + 1; - if (image->bry_ < y) { - image->bry_ = y; - } - } - } else { - image->tlx_ = 0; - image->tly_ = 0; - image->brx_ = 0; - image->bry_ = 0; - } -} - -static int jas_image_growcmpts(jas_image_t *image, int maxcmpts) -{ - jas_image_cmpt_t **newcmpts; - int cmptno; - - newcmpts = (!image->cmpts_) ? jas_malloc(maxcmpts * sizeof(jas_image_cmpt_t *)) : - jas_realloc(image->cmpts_, maxcmpts * sizeof(jas_image_cmpt_t *)); - if (!newcmpts) { - return -1; - } - image->cmpts_ = newcmpts; - image->maxcmpts_ = maxcmpts; - for (cmptno = image->numcmpts_; cmptno < image->maxcmpts_; ++cmptno) { - image->cmpts_[cmptno] = 0; - } - return 0; -} - -int jas_image_copycmpt(jas_image_t *dstimage, int dstcmptno, jas_image_t *srcimage, - int srccmptno) -{ - jas_image_cmpt_t *newcmpt; - if (dstimage->numcmpts_ >= dstimage->maxcmpts_) { - if (jas_image_growcmpts(dstimage, dstimage->maxcmpts_ + 128)) { - return -1; - } - } - if (!(newcmpt = jas_image_cmpt_copy(srcimage->cmpts_[srccmptno]))) { - return -1; - } - if (dstcmptno < dstimage->numcmpts_) { - memmove(&dstimage->cmpts_[dstcmptno + 1], &dstimage->cmpts_[dstcmptno], - (dstimage->numcmpts_ - dstcmptno) * sizeof(jas_image_cmpt_t *)); - } - dstimage->cmpts_[dstcmptno] = newcmpt; - ++dstimage->numcmpts_; - - jas_image_setbbox(dstimage); - return 0; -} - -void jas_image_dump(jas_image_t *image, FILE *out) -{ - int cmptno; - jas_seq2d_t *data; - jas_image_cmpt_t *cmpt; - if (!(data = jas_seq2d_create(0, 0, 1, 1))) { - abort(); - } - for (cmptno = 0; cmptno < image->numcmpts_; ++cmptno) { - cmpt = image->cmpts_[cmptno]; - fprintf(out, "prec=%d sgnd=%d\n", (int)cmpt->prec_, cmpt->sgnd_); - if (jas_image_readcmpt(image, cmptno, 0, 0, 1, 1, data)) { - abort(); - } - fprintf(out, "tlsample %ld\n", (long) jas_seq2d_get(data, 0, 0)); - } - jas_seq2d_destroy(data); -} - -int jas_image_depalettize(jas_image_t *image, int cmptno, int numlutents, - int_fast32_t *lutents, int dtype, int newcmptno) -{ - jas_image_cmptparm_t cmptparms; - int_fast32_t v; - int i; - int j; - jas_image_cmpt_t *cmpt; - - cmpt = image->cmpts_[cmptno]; - cmptparms.tlx = cmpt->tlx_; - cmptparms.tly = cmpt->tly_; - cmptparms.hstep = cmpt->hstep_; - cmptparms.vstep = cmpt->vstep_; - cmptparms.width = cmpt->width_; - cmptparms.height = cmpt->height_; - cmptparms.prec = JAS_IMAGE_CDT_GETPREC(dtype); - cmptparms.sgnd = JAS_IMAGE_CDT_GETSGND(dtype); - - if (jas_image_addcmpt(image, newcmptno, &cmptparms)) { - return -1; - } - if (newcmptno <= cmptno) { - ++cmptno; - cmpt = image->cmpts_[cmptno]; - } - - for (j = 0; j < cmpt->height_; ++j) { - for (i = 0; i < cmpt->width_; ++i) { - v = jas_image_readcmptsample(image, cmptno, i, j); - if (v < 0) { - v = 0; - } else if (v >= numlutents) { - v = numlutents - 1; - } - jas_image_writecmptsample(image, newcmptno, i, j, - lutents[v]); - } - } - return 0; -} - -int jas_image_readcmptsample(jas_image_t *image, int cmptno, int x, int y) -{ - jas_image_cmpt_t *cmpt; - uint_fast32_t v; - int k; - int c; - - cmpt = image->cmpts_[cmptno]; - - if (jas_stream_seek(cmpt->stream_, (cmpt->width_ * y + x) * cmpt->cps_, - SEEK_SET) < 0) { - return -1; - } - v = 0; - for (k = cmpt->cps_; k > 0; --k) { - if ((c = jas_stream_getc(cmpt->stream_)) == EOF) { - return -1; - } - v = (v << 8) | (c & 0xff); - } - return bitstoint(v, cmpt->prec_, cmpt->sgnd_); -} - -void jas_image_writecmptsample(jas_image_t *image, int cmptno, int x, int y, - int_fast32_t v) -{ - jas_image_cmpt_t *cmpt; - uint_fast32_t t; - int k; - int c; - - cmpt = image->cmpts_[cmptno]; - - if (jas_stream_seek(cmpt->stream_, (cmpt->width_ * y + x) * cmpt->cps_, - SEEK_SET) < 0) { - return; - } - t = inttobits(v, cmpt->prec_, cmpt->sgnd_); - for (k = cmpt->cps_; k > 0; --k) { - c = (t >> (8 * (cmpt->cps_ - 1))) & 0xff; - if (jas_stream_putc(cmpt->stream_, (unsigned char) c) == EOF) { - return; - } - t <<= 8; - } -} - -int jas_image_getcmptbytype(jas_image_t *image, int ctype) -{ - int cmptno; - - for (cmptno = 0; cmptno < image->numcmpts_; ++cmptno) { - if (image->cmpts_[cmptno]->type_ == ctype) { - return cmptno; - } - } - return -1; -} diff --git a/converter/other/jpeg2000/libjasper/base/jas_init.c b/converter/other/jpeg2000/libjasper/base/jas_init.c deleted file mode 100644 index c1114bf..0000000 --- a/converter/other/jpeg2000/libjasper/base/jas_init.c +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include "jasper/jas_types.h" -#include "jasper/jas_image.h" -#include "jasper/jas_init.h" - -/******************************************************************************\ -* Code. -\******************************************************************************/ - -/* Initialize the image format table. */ -int jas_init() -{ - jas_image_fmtops_t fmtops; - int fmtid; - - fmtid = 0; - -#if !defined(EXCLUDE_MIF_SUPPORT) - fmtops.decode = mif_decode; - fmtops.encode = mif_encode; - fmtops.validate = mif_validate; - jas_image_addfmt(fmtid, "mif", "mif", "My Image Format (MIF)", &fmtops); - ++fmtid; -#endif - -#if !defined(EXCLUDE_PNM_SUPPORT) - fmtops.decode = pnm_decode; - fmtops.encode = pnm_encode; - fmtops.validate = pnm_validate; - jas_image_addfmt(fmtid, "pnm", "pnm", "Portable Graymap/Pixmap (PNM)", - &fmtops); - jas_image_addfmt(fmtid, "pnm", "pgm", "Portable Graymap/Pixmap (PNM)", - &fmtops); - jas_image_addfmt(fmtid, "pnm", "ppm", "Portable Graymap/Pixmap (PNM)", - &fmtops); - ++fmtid; -#endif - -#if !defined(EXCLUDE_BMP_SUPPORT) - fmtops.decode = bmp_decode; - fmtops.encode = bmp_encode; - fmtops.validate = bmp_validate; - jas_image_addfmt(fmtid, "bmp", "bmp", "Microsoft Bitmap (BMP)", &fmtops); - ++fmtid; -#endif - -#if !defined(EXCLUDE_RAS_SUPPORT) - fmtops.decode = ras_decode; - fmtops.encode = ras_encode; - fmtops.validate = ras_validate; - jas_image_addfmt(fmtid, "ras", "ras", "Sun Rasterfile (RAS)", &fmtops); - ++fmtid; -#endif - -#if !defined(EXCLUDE_JP2_SUPPORT) - fmtops.decode = jp2_decode; - fmtops.encode = jp2_encode; - fmtops.validate = jp2_validate; - jas_image_addfmt(fmtid, "jp2", "jp2", - "JPEG-2000 JP2 File Format Syntax (ISO/IEC 15444-1)", &fmtops); - ++fmtid; - fmtops.decode = jpc_decode; - fmtops.encode = jpc_encode; - fmtops.validate = jpc_validate; - jas_image_addfmt(fmtid, "jpc", "jpc", - "JPEG-2000 Code Stream Syntax (ISO/IEC 15444-1)", &fmtops); - ++fmtid; -#endif - -#if !defined(EXCLUDE_JPG_SUPPORT) - fmtops.decode = jpg_decode; - fmtops.encode = jpg_encode; - fmtops.validate = jpg_validate; - jas_image_addfmt(fmtid, "jpg", "jpg", "JPEG (ISO/IEC 10918-1)", &fmtops); - ++fmtid; -#endif - -#if !defined(EXCLUDE_PGX_SUPPORT) - fmtops.decode = pgx_decode; - fmtops.encode = pgx_encode; - fmtops.validate = pgx_validate; - jas_image_addfmt(fmtid, "pgx", "pgx", "JPEG-2000 VM Format (PGX)", &fmtops); - ++fmtid; -#endif - - return 0; -} diff --git a/converter/other/jpeg2000/libjasper/base/jas_malloc.c b/converter/other/jpeg2000/libjasper/base/jas_malloc.c deleted file mode 100644 index 43c4d3c..0000000 --- a/converter/other/jpeg2000/libjasper/base/jas_malloc.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Memory Allocator - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include - -/* We need the prototype for memset. */ -#include - -#include "jasper/jas_malloc.h" - -/******************************************************************************\ -* Code. -\******************************************************************************/ - -#if defined(DEBUG_MEMALLOC) -#include "../../../local/src/memalloc.c" -#endif - -#if !defined(DEBUG_MEMALLOC) - -void *jas_malloc(size_t size) -{ - return malloc(size); -} - -void jas_free(void *ptr) -{ - free(ptr); -} - -void *jas_realloc(void *ptr, size_t size) -{ - return realloc(ptr, size); -} - -void *jas_calloc(size_t nmemb, size_t size) -{ - void *ptr; - size_t n; - n = nmemb * size; - if (!(ptr = jas_malloc(n * sizeof(char)))) { - return 0; - } - memset(ptr, 0, n); - return ptr; -} - -#endif diff --git a/converter/other/jpeg2000/libjasper/base/jas_seq.c b/converter/other/jpeg2000/libjasper/base/jas_seq.c deleted file mode 100644 index 12dc159..0000000 --- a/converter/other/jpeg2000/libjasper/base/jas_seq.c +++ /dev/null @@ -1,476 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Sequence/Matrix Library - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include -#include - -#include "jasper/jas_seq.h" -#include "jasper/jas_malloc.h" -#include "jasper/jas_math.h" - -/******************************************************************************\ -* Constructors and destructors. -\******************************************************************************/ - -jas_matrix_t *jas_seq2d_create(int xstart, int ystart, int xend, int yend) -{ - jas_matrix_t *matrix; - assert(xstart <= xend && ystart <= yend); - if (!(matrix = jas_matrix_create(yend - ystart, xend - xstart))) { - return 0; - } - matrix->xstart_ = xstart; - matrix->ystart_ = ystart; - matrix->xend_ = xend; - matrix->yend_ = yend; - return matrix; -} - -jas_matrix_t *jas_matrix_create(int numrows, int numcols) -{ - jas_matrix_t *matrix; - int i; - - if (!(matrix = jas_malloc(sizeof(jas_matrix_t)))) { - return 0; - } - matrix->flags_ = 0; - matrix->numrows_ = numrows; - matrix->numcols_ = numcols; - matrix->rows_ = 0; - matrix->maxrows_ = numrows; - matrix->data_ = 0; - matrix->datasize_ = numrows * numcols; - - if (matrix->maxrows_ > 0) { - if (!(matrix->rows_ = jas_malloc(matrix->maxrows_ * - sizeof(jas_seqent_t *)))) { - jas_matrix_destroy(matrix); - return 0; - } - } - - if (matrix->datasize_ > 0) { - if (!(matrix->data_ = jas_malloc(matrix->datasize_ * - sizeof(jas_seqent_t)))) { - jas_matrix_destroy(matrix); - return 0; - } - } - - for (i = 0; i < numrows; ++i) { - matrix->rows_[i] = &matrix->data_[i * matrix->numcols_]; - } - - for (i = 0; i < matrix->datasize_; ++i) { - matrix->data_[i] = 0; - } - - matrix->xstart_ = 0; - matrix->ystart_ = 0; - matrix->xend_ = matrix->numcols_; - matrix->yend_ = matrix->numrows_; - - return matrix; -} - -void jas_matrix_destroy(jas_matrix_t *matrix) -{ - if (matrix->data_) { - assert(!(matrix->flags_ & JAS_MATRIX_REF)); - jas_free(matrix->data_); - matrix->data_ = 0; - } - if (matrix->rows_) { - jas_free(matrix->rows_); - matrix->rows_ = 0; - } - jas_free(matrix); -} - -jas_seq2d_t *jas_seq2d_copy(jas_seq2d_t *x) -{ - jas_matrix_t *y; - int i; - int j; - y = jas_seq2d_create(jas_seq2d_xstart(x), jas_seq2d_ystart(x), jas_seq2d_xend(x), - jas_seq2d_yend(x)); - assert(y); - for (i = 0; i < x->numrows_; ++i) { - for (j = 0; j < x->numcols_; ++j) { - *jas_matrix_getref(y, i, j) = jas_matrix_get(x, i, j); - } - } - return y; -} - -jas_matrix_t *jas_matrix_copy(jas_matrix_t *x) -{ - jas_matrix_t *y; - int i; - int j; - y = jas_matrix_create(x->numrows_, x->numcols_); - for (i = 0; i < x->numrows_; ++i) { - for (j = 0; j < x->numcols_; ++j) { - *jas_matrix_getref(y, i, j) = jas_matrix_get(x, i, j); - } - } - return y; -} - -/******************************************************************************\ -* Bind operations. -\******************************************************************************/ - -void jas_seq2d_bindsub(jas_matrix_t *s, jas_matrix_t *s1, int xstart, int ystart, - int xend, int yend) -{ - jas_matrix_bindsub(s, s1, ystart - s1->ystart_, xstart - s1->xstart_, - yend - s1->ystart_ - 1, xend - s1->xstart_ - 1); -} - -void jas_matrix_bindsub(jas_matrix_t *mat0, jas_matrix_t *mat1, int r0, int c0, - int r1, int c1) -{ - int i; - - if (mat0->data_) { - if (!(mat0->flags_ & JAS_MATRIX_REF)) { - jas_free(mat0->data_); - } - mat0->data_ = 0; - mat0->datasize_ = 0; - } - if (mat0->rows_) { - jas_free(mat0->rows_); - mat0->rows_ = 0; - } - mat0->flags_ |= JAS_MATRIX_REF; - mat0->numrows_ = r1 - r0 + 1; - mat0->numcols_ = c1 - c0 + 1; - mat0->maxrows_ = mat0->numrows_; - mat0->rows_ = jas_malloc(mat0->maxrows_ * sizeof(jas_seqent_t *)); - for (i = 0; i < mat0->numrows_; ++i) { - mat0->rows_[i] = mat1->rows_[r0 + i] + c0; - } - - mat0->xstart_ = mat1->xstart_ + c0; - mat0->ystart_ = mat1->ystart_ + r0; - mat0->xend_ = mat0->xstart_ + mat0->numcols_; - mat0->yend_ = mat0->ystart_ + mat0->numrows_; -} - -/******************************************************************************\ -* Arithmetic operations. -\******************************************************************************/ - -int jas_matrix_cmp(jas_matrix_t *mat0, jas_matrix_t *mat1) -{ - int i; - int j; - - if (mat0->numrows_ != mat1->numrows_ || mat0->numcols_ != - mat1->numcols_) { - return 1; - } - for (i = 0; i < mat0->numrows_; i++) { - for (j = 0; j < mat0->numcols_; j++) { - if (jas_matrix_get(mat0, i, j) != jas_matrix_get(mat1, i, j)) { - return 1; - } - } - } - return 0; -} - -void jas_matrix_divpow2(jas_matrix_t *matrix, int n) -{ - int i; - int j; - jas_seqent_t *rowstart; - int rowstep; - jas_seqent_t *data; - - rowstep = jas_matrix_rowstep(matrix); - for (i = matrix->numrows_, rowstart = matrix->rows_[0]; i > 0; --i, - rowstart += rowstep) { - for (j = matrix->numcols_, data = rowstart; j > 0; --j, - ++data) { - *data = (*data >= 0) ? ((*data) >> n) : - (-((-(*data)) >> n)); - } - } -} - -void jas_matrix_clip(jas_matrix_t *matrix, jas_seqent_t minval, jas_seqent_t maxval) -{ - int i; - int j; - jas_seqent_t v; - jas_seqent_t *rowstart; - jas_seqent_t *data; - int rowstep; - - rowstep = jas_matrix_rowstep(matrix); - for (i = matrix->numrows_, rowstart = matrix->rows_[0]; i > 0; --i, - rowstart += rowstep) { - data = rowstart; - for (j = matrix->numcols_, data = rowstart; j > 0; --j, - ++data) { - v = *data; - if (v < minval) { - *data = minval; - } else if (v > maxval) { - *data = maxval; - } - } - } -} - -void jas_matrix_asr(jas_matrix_t *matrix, int n) -{ - int i; - int j; - jas_seqent_t *rowstart; - int rowstep; - jas_seqent_t *data; - - assert(n >= 0); - rowstep = jas_matrix_rowstep(matrix); - for (i = matrix->numrows_, rowstart = matrix->rows_[0]; i > 0; --i, - rowstart += rowstep) { - for (j = matrix->numcols_, data = rowstart; j > 0; --j, - ++data) { - *data >>= n; - } - } -} - -void jas_matrix_asl(jas_matrix_t *matrix, int n) -{ - int i; - int j; - jas_seqent_t *rowstart; - int rowstep; - jas_seqent_t *data; - - rowstep = jas_matrix_rowstep(matrix); - for (i = matrix->numrows_, rowstart = matrix->rows_[0]; i > 0; --i, - rowstart += rowstep) { - for (j = matrix->numcols_, data = rowstart; j > 0; --j, - ++data) { - *data <<= n; - } - } -} - -/******************************************************************************\ -* Code. -\******************************************************************************/ - -int jas_matrix_resize(jas_matrix_t *matrix, int numrows, int numcols) -{ - int size; - int i; - - size = numrows * numcols; - if (size > matrix->datasize_ || numrows > matrix->maxrows_) { - return -1; - } - - matrix->numrows_ = numrows; - matrix->numcols_ = numcols; - - for (i = 0; i < numrows; ++i) { - matrix->rows_[i] = &matrix->data_[numcols * i]; - } - - return 0; -} - -int jas_matrix_output(jas_matrix_t *matrix, FILE *out) -{ - int i; - int j; - jas_seqent_t x; - - fprintf(out, "%d %d\n", - (int)jas_matrix_numrows(matrix), (int)jas_matrix_numcols(matrix)); - for (i = 0; i < jas_matrix_numrows(matrix); ++i) { - for (j = 0; j < jas_matrix_numcols(matrix); ++j) { - x = jas_matrix_get(matrix, i, j); - fprintf(out, "%ld", JAS_CAST(long, x)); - if (j < jas_matrix_numcols(matrix) - 1) { - fprintf(out, " "); - } - } - fprintf(out, "\n"); - } - return 0; -} - -void jas_matrix_setall(jas_matrix_t *matrix, jas_seqent_t val) -{ - int i; - int j; - jas_seqent_t *rowstart; - int rowstep; - jas_seqent_t *data; - - rowstep = jas_matrix_rowstep(matrix); - for (i = matrix->numrows_, rowstart = matrix->rows_[0]; i > 0; --i, - rowstart += rowstep) { - for (j = matrix->numcols_, data = rowstart; j > 0; --j, - ++data) { - *data = val; - } - } -} - -jas_matrix_t *jas_matrix_input(FILE *in) -{ - jas_matrix_t *matrix; - int i; - int j; - long x; - int numrows; - int numcols; - - if (fscanf(in, "%d %d", &numrows, &numcols) != 2) - return 0; - if (!(matrix = jas_matrix_create(numrows, numcols))) - return 0; - - /* Get matrix data. */ - for (i = 0; i < jas_matrix_numrows(matrix); i++) { - for (j = 0; j < jas_matrix_numcols(matrix); j++) { - if (fscanf(in, "%ld", &x) != 1) { - jas_matrix_destroy(matrix); - return 0; - } - jas_matrix_set(matrix, i, j, JAS_CAST(jas_seqent_t, x)); - } - } - - return matrix; -} diff --git a/converter/other/jpeg2000/libjasper/base/jas_stream.c b/converter/other/jpeg2000/libjasper/base/jas_stream.c deleted file mode 100644 index 16c948e..0000000 --- a/converter/other/jpeg2000/libjasper/base/jas_stream.c +++ /dev/null @@ -1,1172 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -#define _SVID_SOURCE - /* Make sure P_tmpdir is defined in GNU libc 2.0.7 (_XOPEN_SOURCE 500 - does it in other libc's). pm_config.h defines TMPDIR as P_tmpdir - in some environments. - */ -#define _XOPEN_SOURCE 500 /* Make sure P_tmpdir is defined */ - -#include "pm_config.h" -#include -#include -#include -#include -#include -#include -#if defined(HAVE_UNISTD_H) -#include -#endif -#if HAVE_IO_H -#include -#endif - -#include "netpbm/pm.h" - -#include "jasper/jas_types.h" -#include "jasper/jas_stream.h" -#include "jasper/jas_malloc.h" -#include "jasper/jas_math.h" - -/****************************************************************************\ -* Local function prototypes. -\****************************************************************************/ - -static int jas_strtoopenmode(const char *s); -static void jas_stream_destroy(jas_stream_t *stream); -static jas_stream_t *jas_stream_create(void); -static void jas_stream_initbuf(jas_stream_t *stream, int bufmode, char *buf, - int bufsize); - -static int mem_read(jas_stream_obj_t *obj, char *buf, int cnt); -static int mem_write(jas_stream_obj_t *obj, char *buf, int cnt); -static long mem_seek(jas_stream_obj_t *obj, long offset, int origin); -static int mem_close(jas_stream_obj_t *obj); - -static int sfile_read(jas_stream_obj_t *obj, char *buf, int cnt); -static int sfile_write(jas_stream_obj_t *obj, char *buf, int cnt); -static long sfile_seek(jas_stream_obj_t *obj, long offset, int origin); -static int sfile_close(jas_stream_obj_t *obj); - -static int file_read(jas_stream_obj_t *obj, char *buf, int cnt); -static int file_write(jas_stream_obj_t *obj, char *buf, int cnt); -static long file_seek(jas_stream_obj_t *obj, long offset, int origin); -static int file_close(jas_stream_obj_t *obj); - -/******************************************************************************\ -* Local data. -\******************************************************************************/ - -static jas_stream_ops_t jas_stream_fileops = { - file_read, - file_write, - file_seek, - file_close -}; - -static jas_stream_ops_t jas_stream_sfileops = { - sfile_read, - sfile_write, - sfile_seek, - sfile_close -}; - -static jas_stream_ops_t jas_stream_memops = { - mem_read, - mem_write, - mem_seek, - mem_close -}; - -/******************************************************************************\ -* Code for opening and closing streams. -\******************************************************************************/ - -static jas_stream_t *jas_stream_create() -{ - jas_stream_t *stream; - - if (!(stream = jas_malloc(sizeof(jas_stream_t)))) { - return 0; - } - stream->openmode_ = 0; - stream->bufmode_ = 0; - stream->flags_ = 0; - stream->bufbase_ = 0; - stream->bufstart_ = 0; - stream->bufsize_ = 0; - stream->ptr_ = 0; - stream->cnt_ = 0; - stream->ops_ = 0; - stream->obj_ = 0; - stream->rwcnt_ = 0; - stream->rwlimit_ = -1; - - return stream; -} - -jas_stream_t *jas_stream_memopen(char *buf, int bufsize) -{ - jas_stream_t *stream; - jas_stream_memobj_t *obj; - - if (!(stream = jas_stream_create())) { - return 0; - } - - /* A stream associated with a memory buffer is always opened - for both reading and writing in binary mode. */ - stream->openmode_ = JAS_STREAM_READ | JAS_STREAM_WRITE | JAS_STREAM_BINARY; - - /* Since the stream data is already resident in memory, buffering - is not necessary. */ - /* But... It still may be faster to use buffering anyways. */ - jas_stream_initbuf(stream, JAS_STREAM_FULLBUF, 0, 0); - - /* Select the operations for a memory stream. */ - stream->ops_ = &jas_stream_memops; - - /* Allocate memory for the underlying memory stream object. */ - if (!(obj = jas_malloc(sizeof(jas_stream_memobj_t)))) { - jas_stream_destroy(stream); - return 0; - } - stream->obj_ = (void *) obj; - - /* Initialize a few important members of the memory stream object. */ - obj->myalloc_ = 0; - obj->buf_ = 0; - - /* If the buffer size specified is nonpositive, then the buffer - is allocated internally and automatically grown as needed. */ - if (bufsize <= 0) { - obj->bufsize_ = 1024; - obj->growable_ = 1; - } else { - obj->bufsize_ = bufsize; - obj->growable_ = 0; - } - if (buf) { - obj->buf_ = (unsigned char *) buf; - } else { - obj->buf_ = jas_malloc(obj->bufsize_ * sizeof(char)); - obj->myalloc_ = 1; - } - if (!obj->buf_) { - jas_stream_close(stream); - return 0; - } - - if (bufsize > 0 && buf) { - /* If a buffer was supplied by the caller and its length is positive, - make the associated buffer data appear in the stream initially. */ - obj->len_ = bufsize; - } else { - /* The stream is initially empty. */ - obj->len_ = 0; - } - obj->pos_ = 0; - - return stream; -} - -jas_stream_t *jas_stream_fopen(const char *filename, const char *mode) -{ - jas_stream_t *stream; - int *obj; - int openflags; - - /* Allocate a stream object. */ - if (!(stream = jas_stream_create())) { - return 0; - } - - /* Parse the mode string. */ - stream->openmode_ = jas_strtoopenmode(mode); - - /* Determine the correct flags to use for opening the file. */ - if ((stream->openmode_ & JAS_STREAM_READ) && - (stream->openmode_ & JAS_STREAM_WRITE)) { - openflags = O_RDWR; - } else if (stream->openmode_ & JAS_STREAM_READ) { - openflags = O_RDONLY; - } else if (stream->openmode_ & JAS_STREAM_WRITE) { - openflags = O_WRONLY; - } else { - openflags = 0; - } - if (stream->openmode_ & JAS_STREAM_APPEND) { - openflags |= O_APPEND; - } - if (stream->openmode_ & JAS_STREAM_BINARY) { - openflags |= O_BINARY; - } - if (stream->openmode_ & JAS_STREAM_CREATE) { - openflags |= O_CREAT | O_TRUNC; - } - - /* Allocate space for the underlying file stream object. */ - if (!(obj = jas_malloc(sizeof(int)))) { - jas_stream_destroy(stream); - return 0; - } - stream->obj_ = (void *) obj; - - /* Select the operations for a file stream object. */ - stream->ops_ = &jas_stream_fileops; - - /* Open the underlying file. */ - if ((*obj = open(filename, openflags, JAS_STREAM_PERMS)) < 0) { - jas_stream_destroy(stream); - return 0; - } - - /* By default, use full buffering for this type of stream. */ - jas_stream_initbuf(stream, JAS_STREAM_FULLBUF, 0, 0); - - return stream; -} - -jas_stream_t *jas_stream_freopen(const char *path, const char *mode, FILE *fp) -{ - jas_stream_t *stream; - int openflags; - - /* Allocate a stream object. */ - if (!(stream = jas_stream_create())) { - return 0; - } - - /* Parse the mode string. */ - stream->openmode_ = jas_strtoopenmode(mode); - - /* Determine the correct flags to use for opening the file. */ - if ((stream->openmode_ & JAS_STREAM_READ) && - (stream->openmode_ & JAS_STREAM_WRITE)) { - openflags = O_RDWR; - } else if (stream->openmode_ & JAS_STREAM_READ) { - openflags = O_RDONLY; - } else if (stream->openmode_ & JAS_STREAM_WRITE) { - openflags = O_WRONLY; - } else { - openflags = 0; - } - if (stream->openmode_ & JAS_STREAM_APPEND) { - openflags |= O_APPEND; - } - if (stream->openmode_ & JAS_STREAM_BINARY) { - openflags |= O_BINARY; - } - if (stream->openmode_ & JAS_STREAM_CREATE) { - openflags |= O_CREAT | O_TRUNC; - } - - stream->obj_ = JAS_CAST(void *, fp); - - /* Select the operations for a file stream object. */ - stream->ops_ = &jas_stream_sfileops; - - /* By default, use full buffering for this type of stream. */ - jas_stream_initbuf(stream, JAS_STREAM_FULLBUF, 0, 0); - - return stream; -} - - -jas_stream_t *jas_stream_tmpfile() -{ - jas_stream_t *stream; - int *obj; - - if (!(stream = jas_stream_create())) { - return 0; - } - - /* A temporary file stream is always opened for both reading and - writing in binary mode. */ - stream->openmode_ = JAS_STREAM_READ | JAS_STREAM_WRITE | JAS_STREAM_BINARY; - - /* Allocate memory for the underlying temporary file object. */ - if (!(obj = jas_malloc(sizeof(int)))) { - jas_stream_destroy(stream); - return 0; - } - stream->obj_ = obj; - - { - /* This is a Netpbm enhancement. Original Jasper library uses - tmpnam(), which is unsafe. - */ - jmp_buf jmpbuf; - int rc; - - rc = setjmp(jmpbuf); - if (rc == 0) { - pm_setjmpbuf(&jmpbuf); - *obj = pm_tmpfile_fd(); - } else { - /* pm_tmpfile_fd() threw an error */ - jas_stream_destroy(stream); - return 0; - } - } - /* Use full buffering. */ - jas_stream_initbuf(stream, JAS_STREAM_FULLBUF, 0, 0); - - stream->ops_ = &jas_stream_fileops; - - return stream; -} - -jas_stream_t *jas_stream_fdopen(int fd, const char *mode) -{ - jas_stream_t *stream; - int *obj; - - /* Allocate a stream object. */ - if (!(stream = jas_stream_create())) { - return 0; - } - - /* Parse the mode string. */ - stream->openmode_ = jas_strtoopenmode(mode); - -#if defined(HAVE_SETMODE) && defined(O_BINARY) - /* Argh!!! Someone ought to banish text mode (i.e., O_TEXT) to the - greatest depths of purgatory! */ - /* Ensure that the file descriptor is in binary mode, if the caller - has specified the binary mode flag. Arguably, the caller ought to - take care of this, but text mode is a ugly wart anyways, so we save - the caller some grief by handling this within the stream library. */ - /* This ugliness is mainly for the benefit of those who run the - JasPer software under Windows from shells that insist on opening - files in text mode. For example, in the Cygwin environment, - shells often open files in text mode when I/O redirection is - used. Grr... */ - if (stream->openmode_ & JAS_STREAM_BINARY) { - setmode(fd, O_BINARY); - } -#endif - - /* Allocate space for the underlying file stream object. */ - if (!(obj = jas_malloc(sizeof(int)))) { - jas_stream_destroy(stream); - return 0; - } - stream->obj_ = (void *) obj; - *obj = fd; - - /* By default, use full buffering for this type of stream. */ - jas_stream_initbuf(stream, JAS_STREAM_FULLBUF, 0, 0); - - /* Select the operations for a file stream object. */ - stream->ops_ = &jas_stream_fileops; - -/* Do not close the underlying file descriptor when the stream is closed. */ - stream->openmode_ |= JAS_STREAM_NOCLOSE; - - return stream; -} - -static void jas_stream_destroy(jas_stream_t *stream) -{ - /* If the memory for the buffer was allocated with malloc, free - this memory. */ - if ((stream->bufmode_ & JAS_STREAM_FREEBUF) && stream->bufbase_) { - jas_free(stream->bufbase_); - stream->bufbase_ = 0; - } - jas_free(stream); -} - -int jas_stream_close(jas_stream_t *stream) -{ - /* Flush buffer if necessary. */ - jas_stream_flush(stream); - - /* Close the underlying stream object. */ - if (!(stream->openmode_ & JAS_STREAM_NOCLOSE)) { - (*stream->ops_->close_)(stream->obj_); - } - - jas_stream_destroy(stream); - - return 0; -} - -/******************************************************************************\ -* Code for reading and writing streams. -\******************************************************************************/ - -int jas_stream_getc_func(jas_stream_t *stream) -{ - assert(stream->ptr_ - stream->bufbase_ <= stream->bufsize_ + - JAS_STREAM_MAXPUTBACK); - return jas_stream_getc_macro(stream); -} - -int jas_stream_putc_func(jas_stream_t *stream, int c) -{ - assert(stream->ptr_ - stream->bufstart_ <= stream->bufsize_); - return jas_stream_putc_macro(stream, c); -} - -int jas_stream_ungetc(jas_stream_t *stream, int c) -{ - if (!stream->ptr_ || stream->ptr_ == stream->bufbase_) { - return -1; - } - - /* Reset the EOF indicator (since we now have at least one character - to read). */ - stream->flags_ &= ~JAS_STREAM_EOF; - - --stream->rwcnt_; - --stream->ptr_; - ++stream->cnt_; - *stream->ptr_ = c; - return 0; -} - -int jas_stream_read(jas_stream_t *stream, void *buf, int cnt) -{ - int n; - int c; - char *bufptr; - - bufptr = buf; - - n = 0; - while (n < cnt) { - if ((c = jas_stream_getc(stream)) == EOF) { - return n; - } - *bufptr++ = c; - ++n; - } - - return n; -} - -int jas_stream_write(jas_stream_t *stream, const void *buf, int cnt) -{ - int n; - const char *bufptr; - - bufptr = buf; - - n = 0; - while (n < cnt) { - if (jas_stream_putc(stream, *bufptr) == EOF) { - return n; - } - ++bufptr; - ++n; - } - - return n; -} - -/* Note: This function uses a fixed size buffer. Therefore, it cannot - handle invocations that will produce more output than can be held - by the buffer. */ -int jas_stream_printf(jas_stream_t *stream, const char *fmt, ...) -{ - va_list ap; - char buf[4096]; - int ret; - - va_start(ap, fmt); - ret = vsprintf(buf, fmt, ap); - jas_stream_puts(stream, buf); - va_end(ap); - return ret; -} - -int jas_stream_puts(jas_stream_t *stream, const char *s) -{ - while (*s != '\0') { - if (jas_stream_putc_macro(stream, *s) == EOF) { - return -1; - } - ++s; - } - return 0; -} - -char *jas_stream_gets(jas_stream_t *stream, char *buf, int bufsize) -{ - int c; - char *bufptr; - assert(bufsize > 0); - - bufptr = buf; - while (bufsize > 1) { - if ((c = jas_stream_getc(stream)) == EOF) { - break; - } - *bufptr++ = c; - --bufsize; - if (c == '\n') { - break; - } - } - *bufptr = '\0'; - return buf; -} - -int jas_stream_gobble(jas_stream_t *stream, int n) -{ - int m; - m = n; - for (m = n; m > 0; --m) { - if (jas_stream_getc(stream) == EOF) { - return n - m; - } - } - return n; -} - -/******************************************************************************\ -* Code for getting and setting the stream position. -\******************************************************************************/ - -int jas_stream_isseekable(jas_stream_t *stream) -{ - if (stream->ops_ == &jas_stream_memops) { - return 1; - } else if (stream->ops_ == &jas_stream_fileops) { - if ((*stream->ops_->seek_)(stream->obj_, 0, SEEK_CUR) < 0) { - return 0; - } - return 1; - } else { - return 0; - } -} - -int jas_stream_rewind(jas_stream_t *stream) -{ - return jas_stream_seek(stream, 0, SEEK_SET); -} - -long jas_stream_seek(jas_stream_t *stream, long offset, int origin) -{ - long newpos; - - /* The buffer cannot be in use for both reading and writing. */ - assert(!((stream->bufmode_ & JAS_STREAM_RDBUF) && (stream->bufmode_ & - JAS_STREAM_WRBUF))); - - /* Reset the EOF indicator (since we may not be at the EOF anymore). */ - stream->flags_ &= ~JAS_STREAM_EOF; - - if (stream->bufmode_ & JAS_STREAM_RDBUF) { - if (origin == SEEK_CUR) { - offset -= stream->cnt_; - } - } else if (stream->bufmode_ & JAS_STREAM_WRBUF) { - if (jas_stream_flush(stream)) { - return -1; - } - } - stream->cnt_ = 0; - stream->ptr_ = stream->bufstart_; - stream->bufmode_ &= ~(JAS_STREAM_RDBUF | JAS_STREAM_WRBUF); - - if ((newpos = (*stream->ops_->seek_)(stream->obj_, offset, origin)) - < 0) { - return -1; - } - - return newpos; -} - -long jas_stream_tell(jas_stream_t *stream) -{ - int adjust; - int offset; - - if (stream->bufmode_ & JAS_STREAM_RDBUF) { - adjust = -stream->cnt_; - } else if (stream->bufmode_ & JAS_STREAM_WRBUF) { - adjust = stream->ptr_ - stream->bufstart_; - } else { - adjust = 0; - } - - if ((offset = (*stream->ops_->seek_)(stream->obj_, 0, SEEK_CUR)) < 0) { - return -1; - } - - return offset + adjust; -} - -/******************************************************************************\ -* Buffer initialization code. -\******************************************************************************/ - -static void jas_stream_initbuf(jas_stream_t *stream, int bufmode, char *buf, - int bufsize) -{ - /* If this function is being called, the buffer should not have been - initialized yet. */ - assert(!stream->bufbase_); - - if (bufmode != JAS_STREAM_UNBUF) { - /* The full- or line-buffered mode is being employed. */ - if (!buf) { - /* The caller has not specified a buffer to employ, so allocate - one. */ - if ((stream->bufbase_ = jas_malloc(JAS_STREAM_BUFSIZE + - JAS_STREAM_MAXPUTBACK))) { - stream->bufmode_ |= JAS_STREAM_FREEBUF; - stream->bufsize_ = JAS_STREAM_BUFSIZE; - } else { - /* The buffer allocation has failed. Resort to unbuffered - operation. */ - stream->bufbase_ = stream->tinybuf_; - stream->bufsize_ = 1; - } - } else { - /* The caller has specified a buffer to employ. */ - /* The buffer must be large enough to accommodate maximum - putback. */ - assert(bufsize > JAS_STREAM_MAXPUTBACK); - stream->bufbase_ = JAS_CAST(unsigned char *, buf); - stream->bufsize_ = bufsize - JAS_STREAM_MAXPUTBACK; - } - } else { - /* The unbuffered mode is being employed. */ - /* A buffer should not have been supplied by the caller. */ - assert(!buf); - /* Use a trivial one-character buffer. */ - stream->bufbase_ = stream->tinybuf_; - stream->bufsize_ = 1; - } - stream->bufstart_ = &stream->bufbase_[JAS_STREAM_MAXPUTBACK]; - stream->ptr_ = stream->bufstart_; - stream->cnt_ = 0; - stream->bufmode_ |= bufmode & JAS_STREAM_BUFMODEMASK; -} - -/******************************************************************************\ -* Buffer filling and flushing code. -\******************************************************************************/ - -int jas_stream_flush(jas_stream_t *stream) -{ - if (stream->bufmode_ & JAS_STREAM_RDBUF) { - return 0; - } - return jas_stream_flushbuf(stream, EOF); -} - -int jas_stream_fillbuf(jas_stream_t *stream, int getflag) -{ - int c; - - /* The stream must not be in an error or EOF state. */ - if ((stream->flags_ & (JAS_STREAM_ERRMASK)) != 0) { - return EOF; - } - - /* The stream must be open for reading. */ - if ((stream->openmode_ & JAS_STREAM_READ) == 0) { - return EOF; - } - - /* Make a half-hearted attempt to confirm that the buffer is not - currently being used for writing. This check is not intended - to be foolproof! */ - assert((stream->bufmode_ & JAS_STREAM_WRBUF) == 0); - - assert(stream->ptr_ - stream->bufstart_ <= stream->bufsize_); - - /* Mark the buffer as being used for reading. */ - stream->bufmode_ |= JAS_STREAM_RDBUF; - - /* Read new data into the buffer. */ - stream->ptr_ = stream->bufstart_; - if ((stream->cnt_ = (*stream->ops_->read_)(stream->obj_, - (char *) stream->bufstart_, stream->bufsize_)) <= 0) { - if (stream->cnt_ < 0) { - stream->flags_ |= JAS_STREAM_ERR; - } else { - stream->flags_ |= JAS_STREAM_EOF; - } - stream->cnt_ = 0; - return EOF; - } - - assert(stream->cnt_ > 0); - /* Get or peek at the first character in the buffer. */ - c = (getflag) ? jas_stream_getc2(stream) : (*stream->ptr_); - - return c; -} - -int jas_stream_flushbuf(jas_stream_t *stream, int c) -{ - int len; - int n; - - /* The stream should not be in an error or EOF state. */ - if ((stream->flags_ & (JAS_STREAM_ERRMASK)) != 0) { - return EOF; - } - - /* The stream must be open for writing. */ - if ((stream->openmode_ & (JAS_STREAM_WRITE | JAS_STREAM_APPEND)) == 0) { - return EOF; - } - - /* The buffer should not currently be in use for reading. */ - assert(!(stream->bufmode_ & JAS_STREAM_RDBUF)); - - /* Note: Do not use the quantity stream->cnt to determine the number - of characters in the buffer! Depending on how this function was - called, the stream->cnt value may be "off-by-one". */ - len = stream->ptr_ - stream->bufstart_; - if (len > 0) { - n = (*stream->ops_->write_)(stream->obj_, (char *) - stream->bufstart_, len); - if (n != len) { - stream->flags_ |= JAS_STREAM_ERR; - return EOF; - } - } - stream->cnt_ = stream->bufsize_; - stream->ptr_ = stream->bufstart_; - - stream->bufmode_ |= JAS_STREAM_WRBUF; - - if (c != EOF) { - assert(stream->cnt_ > 0); - jas_stream_putc2(stream, c); - } - - return 0; -} - -/******************************************************************************\ -* Miscellaneous code. -\******************************************************************************/ - -static int jas_strtoopenmode(const char *s) -{ - int openmode = 0; - while (*s != '\0') { - switch (*s) { - case 'r': - openmode |= JAS_STREAM_READ; - break; - case 'w': - openmode |= JAS_STREAM_WRITE | JAS_STREAM_CREATE; - break; - case 'b': - openmode |= JAS_STREAM_BINARY; - break; - case 'a': - openmode |= JAS_STREAM_APPEND; - break; - case '+': - openmode |= JAS_STREAM_READ | JAS_STREAM_WRITE; - break; - default: - break; - } - ++s; - } - return openmode; -} - -int jas_stream_copy(jas_stream_t *out, jas_stream_t *in, int n) -{ - int all; - int c; - int m; - - all = (n < 0) ? 1 : 0; - - m = n; - while (all || m > 0) { - if ((c = jas_stream_getc_macro(in)) == EOF) { - /* The next character of input could not be read. */ - /* Return with an error if an I/O error occurred - (not including EOF) or if an explicit copy count - was specified. */ - return (!all || jas_stream_error(in)) ? (-1) : 0; - } - if (jas_stream_putc_macro(out, c) == EOF) { - return -1; - } - --m; - } - return 0; -} - -long jas_stream_setrwcount(jas_stream_t *stream, long rwcnt) -{ - int old; - - old = stream->rwcnt_; - stream->rwcnt_ = rwcnt; - return old; -} - -int jas_stream_display(jas_stream_t *stream, FILE *fp, int n) -{ - unsigned char buf[16]; - int i; - int j; - int m; - int c; - int display; - int cnt; - - cnt = n - (n % 16); - display = 1; - - for (i = 0; i < n; i += 16) { - if (n > 16 && i > 0) { - display = (i >= cnt) ? 1 : 0; - } - if (display) { - fprintf(fp, "%08x:", i); - } - m = JAS_MIN(n - i, 16); - for (j = 0; j < m; ++j) { - if ((c = jas_stream_getc(stream)) == EOF) { - abort(); - return -1; - } - buf[j] = c; - } - if (display) { - for (j = 0; j < m; ++j) { - fprintf(fp, " %02x", buf[j]); - } - fputc(' ', fp); - for (; j < 16; ++j) { - fprintf(fp, " "); - } - for (j = 0; j < m; ++j) { - if (isprint(buf[j])) { - fputc(buf[j], fp); - } else { - fputc(' ', fp); - } - } - fprintf(fp, "\n"); - } - - - } - return 0; -} - -long jas_stream_length(jas_stream_t *stream) -{ - long oldpos; - long pos; - if ((oldpos = jas_stream_tell(stream)) < 0) { - return -1; - } - if (jas_stream_seek(stream, 0, SEEK_END) < 0) { - return -1; - } - if ((pos = jas_stream_tell(stream)) < 0) { - return -1; - } - if (jas_stream_seek(stream, oldpos, SEEK_SET) < 0) { - return -1; - } - return pos; -} - -/******************************************************************************\ -* Memory stream object. -\******************************************************************************/ - -static int mem_read(jas_stream_obj_t *obj, char *buf, int cnt) -{ - int n; - jas_stream_memobj_t *m = (jas_stream_memobj_t *)obj; - n = m->len_ - m->pos_; - cnt = JAS_MIN(n, cnt); - memcpy(buf, &m->buf_[m->pos_], cnt); - m->pos_ += cnt; - return cnt; -} - -static int mem_resize(jas_stream_memobj_t *m, int bufsize) -{ - unsigned char *buf; - - assert(m->buf_); - if (!(buf = jas_realloc(m->buf_, bufsize * sizeof(unsigned char)))) { - return -1; - } - m->buf_ = buf; - m->bufsize_ = bufsize; - return 0; -} - -static int mem_write(jas_stream_obj_t *obj, char *buf, int cnt) -{ - int n; - int ret; - jas_stream_memobj_t *m = (jas_stream_memobj_t *)obj; - long newbufsize; - long newpos; - - newpos = m->pos_ + cnt; - if (newpos > m->bufsize_ && m->growable_) { - newbufsize = m->bufsize_; - while (newbufsize < newpos) { - newbufsize <<= 1; - assert(newbufsize >= 0); - } - if (mem_resize(m, newbufsize)) { - return -1; - } - } - if (m->pos_ > m->len_) { - /* The current position is beyond the end of the file, so - pad the file to the current position with zeros. */ - n = JAS_MIN(m->pos_, m->bufsize_) - m->len_; - if (n > 0) { - memset(&m->buf_[m->len_], 0, n); - m->len_ += n; - } - if (m->pos_ != m->len_) { - /* The buffer is not big enough. */ - return 0; - } - } - n = m->bufsize_ - m->pos_; - ret = JAS_MIN(n, cnt); - if (ret > 0) { - memcpy(&m->buf_[m->pos_], buf, ret); - m->pos_ += ret; - } - if (m->pos_ > m->len_) { - m->len_ = m->pos_; - } -assert(ret == cnt); - return ret; -} - -static long mem_seek(jas_stream_obj_t *obj, long offset, int origin) -{ - jas_stream_memobj_t *m = (jas_stream_memobj_t *)obj; - long newpos; - - switch (origin) { - case SEEK_SET: - newpos = offset; - break; - case SEEK_END: - newpos = m->len_ - offset; - break; - case SEEK_CUR: - newpos = m->pos_ + offset; - break; - default: - abort(); - break; - } - if (newpos < 0) { - return -1; - } - m->pos_ = newpos; - - return m->pos_; -} - -static int mem_close(jas_stream_obj_t *obj) -{ - jas_stream_memobj_t *m = (jas_stream_memobj_t *)obj; - if (m->myalloc_ && m->buf_) { - jas_free(m->buf_); - m->buf_ = 0; - } - jas_free(obj); - return 0; -} - -/******************************************************************************\ -* File stream object. -\******************************************************************************/ - -static int file_read(jas_stream_obj_t *obj, char *buf, int cnt) -{ - int fd; - fd = *((int *)obj); - return read(fd, buf, cnt); -} - -static int file_write(jas_stream_obj_t *obj, char *buf, int cnt) -{ - int fd; - fd = *((int *)obj); - return write(fd, buf, cnt); -} - -static long file_seek(jas_stream_obj_t *obj, long offset, int origin) -{ - int fd; - fd = *((int *)obj); - return lseek(fd, offset, origin); -} - -static int file_close(jas_stream_obj_t *obj) -{ - int fd; - fd = *((int *)obj); - jas_free(obj); - return close(fd); -} - -/******************************************************************************\ -* Stdio file stream object. -\******************************************************************************/ - -static int sfile_read(jas_stream_obj_t *obj, char *buf, int cnt) -{ - FILE *fp; - fp = JAS_CAST(FILE *, obj); - return fread(buf, 1, cnt, fp); -} - -static int sfile_write(jas_stream_obj_t *obj, char *buf, int cnt) -{ - FILE *fp; - fp = JAS_CAST(FILE *, obj); - return fwrite(buf, 1, cnt, fp); -} - -static long sfile_seek(jas_stream_obj_t *obj, long offset, int origin) -{ - FILE *fp; - fp = JAS_CAST(FILE *, obj); - return fseek(fp, offset, origin); -} - -static int sfile_close(jas_stream_obj_t *obj) -{ - FILE *fp; - fp = JAS_CAST(FILE *, obj); - return fclose(fp); -} diff --git a/converter/other/jpeg2000/libjasper/base/jas_string.c b/converter/other/jpeg2000/libjasper/base/jas_string.c deleted file mode 100644 index 945731a..0000000 --- a/converter/other/jpeg2000/libjasper/base/jas_string.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * String Library - * - * $Id$ - */ - -/******************************************************************************\ -* Includes -\******************************************************************************/ - -#include - -#include "jasper/jas_malloc.h" -#include "jasper/jas_string.h" - -/******************************************************************************\ -* Miscellaneous Functions -\******************************************************************************/ - -/* This function is equivalent to the popular but non-standard (and - not-always-available) strdup function. */ - -char *jas_strdup(const char *s) -{ - int n; - char *p; - n = strlen(s) + 1; - if (!(p = jas_malloc(n * sizeof(char)))) { - return 0; - } - strcpy(p, s); - return p; -} diff --git a/converter/other/jpeg2000/libjasper/base/jas_tvp.c b/converter/other/jpeg2000/libjasper/base/jas_tvp.c deleted file mode 100644 index aab1270..0000000 --- a/converter/other/jpeg2000/libjasper/base/jas_tvp.c +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Tag-Value Parser Library - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include -#include -#include - -#include "jasper/jas_malloc.h" -#include "jasper/jas_string.h" -#include "jasper/jas_tvp.h" - -/******************************************************************************\ -* Macros. -\******************************************************************************/ - -/* Is the specified character valid for a tag name? */ -#define JAS_TVP_ISTAG(x) \ - (isalpha(x) || (x) == '_' || isdigit(x)) - -/******************************************************************************\ -* Code for creating and destroying a tag-value parser. -\******************************************************************************/ - -jas_tvparser_t *jas_tvparser_create(const char *s) -{ - jas_tvparser_t *tvp; - if (!(tvp = jas_malloc(sizeof(jas_tvparser_t)))) { - return 0; - } - if (!(tvp->buf = jas_strdup(s))) { - jas_tvparser_destroy(tvp); - return 0; - } - tvp->pos = tvp->buf; - tvp->tag = 0; - tvp->val = 0; - return tvp; -} - -void jas_tvparser_destroy(jas_tvparser_t *tvp) -{ - if (tvp->buf) { - jas_free(tvp->buf); - } - jas_free(tvp); -} - -/******************************************************************************\ -* Main parsing code. -\******************************************************************************/ - -/* Get the next tag-value pair. */ -int jas_tvparser_next(jas_tvparser_t *tvp) -{ - char *p; - char *tag; - const char *val; - - /* Skip any leading whitespace. */ - p = tvp->pos; - while (*p != '\0' && isspace(*p)) { - ++p; - } - - /* Has the end of the input data been reached? */ - if (*p == '\0') { - /* No more tags are present. */ - tvp->pos = p; - return 1; - } - - /* Does the tag name begin with a valid character? */ - if (!JAS_TVP_ISTAG(*p)) { - return -1; - } - - /* Remember where the tag name begins. */ - tag = p; - - /* Find the end of the tag name. */ - while (*p != '\0' && JAS_TVP_ISTAG(*p)) { - ++p; - } - - /* Has the end of the input data been reached? */ - if (*p == '\0') { - /* The value field is empty. */ - tvp->tag = tag; - tvp->val = ""; - tvp->pos = p; - return 0; - } - - /* Is a value field not present? */ - if (*p != '=') { - if (*p != '\0' && !isspace(*p)) { - return -1; - } - *p++ = '\0'; - tvp->tag = tag; - tvp->val = ""; - tvp->pos = p; - return 0; - } - - *p++ = '\0'; - - val = p; - while (*p != '\0' && !isspace(*p)) { - ++p; - } - - if (*p != '\0') { - *p++ = '\0'; - } - - tvp->pos = p; - tvp->tag = tag; - tvp->val = val; - - return 0; -} - -/******************************************************************************\ -* Code for querying the current tag/value. -\******************************************************************************/ - -/* Get the current tag. */ -char *jas_tvparser_gettag(jas_tvparser_t *tvp) -{ - return tvp->tag; -} - -/* Get the current value. */ -const char *jas_tvparser_getval(jas_tvparser_t *tvp) -{ - return tvp->val; -} - -/******************************************************************************\ -* Miscellaneous code. -\******************************************************************************/ - -/* Lookup a tag by name. */ -jas_taginfo_t *jas_taginfos_lookup(jas_taginfo_t *taginfos, const char *name) -{ - jas_taginfo_t *taginfo; - taginfo = taginfos; - while (taginfo->id >= 0) { - if (!strcmp(taginfo->name, name)) { - return taginfo; - } - ++taginfo; - } - return 0; -} - -/* This function is simply for convenience. */ -/* One can avoid testing for the special case of a null pointer, by - using this function. This function never returns a null pointer. */ -jas_taginfo_t *jas_taginfo_nonull(jas_taginfo_t *taginfo) -{ - static jas_taginfo_t invalidtaginfo = { - -1, 0 - }; - - return taginfo ? taginfo : &invalidtaginfo; -} diff --git a/converter/other/jpeg2000/libjasper/base/jas_version.c b/converter/other/jpeg2000/libjasper/base/jas_version.c deleted file mode 100644 index 5608c4d..0000000 --- a/converter/other/jpeg2000/libjasper/base/jas_version.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -#include "jasper/jas_version.h" - -const char *jas_getversion() -{ - return JAS_VERSION; -} diff --git a/converter/other/jpeg2000/libjasper/common.mk b/converter/other/jpeg2000/libjasper/common.mk deleted file mode 100644 index a333f5d..0000000 --- a/converter/other/jpeg2000/libjasper/common.mk +++ /dev/null @@ -1,39 +0,0 @@ -# This is common rules for the libjasper subdirectories. -# -# Set the following variables before including this: -# -# SUBDIRS: Subdirectory names -# LIB_OBJECTS: List of object files from this directory that go into -# libjasper. -# JASPERSRCDIR: libjasper source directory - -all: $(LIB_OBJECTS) partlist - -partlist: $(SUBDIRS:%=%/partlist) - cat /dev/null $(SUBDIRS:%=%/partlist) >$@ - echo $(LIB_OBJECTS:%=$(CURDIR)/%) >>$@ - -$(SUBDIRS:%=%/partlist): - $(MAKE) -C $(dir $@) -f $(SRCDIR)/$(SUBDIR)/$(dir $@)Makefile \ - SRCDIR=$(SRCDIR) BUILDDIR=$(BUILDDIR) $(notdir $@) - -include $(SRCDIR)/common.mk - -INCLUDES := -I$(JASPERSRCDIR)/include $(INCLUDES) - -DEFS = -DHAVE_LIBM=1 -DSTDC_HEADERS=1 -DHAVE_FCNTL_H=1 -DHAVE_LIMITS_H=1 -DHAVE_UNISTD_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STDDEF_H=1 -DEXCLUDE_BMP_SUPPORT -DEXCLUDE_RAS_SUPPORT -DEXCLUDE_MIF_SUPPORT -DEXCLUDE_JPG_SUPPORT -DEXCLUDE_PGX_SUPPORT -DEXCLUDE_PNM_SUPPORT - -$(LIB_OBJECTS):%.o:%.c - $(CC) -c $(INCLUDES) $(DEFS) $(CPPFLAGS) $(CFLAGS) \ - $(CFLAGS_PERSONAL) $(CADD) $< - -$(LIB_OBJECTS): importinc - -thisdirclean: localclean - -.PHONY: localclean -localclean: - rm -f partlist - -.PHONY: FORCE -FORCE: diff --git a/converter/other/jpeg2000/libjasper/include/jasper/jas_debug.h b/converter/other/jpeg2000/libjasper/include/jasper/jas_debug.h deleted file mode 100644 index 6c597c5..0000000 --- a/converter/other/jpeg2000/libjasper/include/jasper/jas_debug.h +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Debugging-Related Code - * - * $Id$ - */ - -#ifndef JAS_DEBUG_H -#define JAS_DEBUG_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include - -#include "jasper/jas_types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/******************************************************************************\ -* Macros and functions. -\******************************************************************************/ - -/* Output debugging information to standard error provided that the debug - level is set sufficiently high. */ -#if defined(DEBUG) -#define JAS_DBGLOG(n, x) \ - ((jas_getdbglevel() >= (n)) ? (jas_eprintf x) : 0) -#else -#define JAS_DBGLOG(n, x) -#endif - -/* Get the library debug level. */ -int jas_getdbglevel(void); - -/* Set the library debug level. */ -int jas_setdbglevel(int dbglevel); - -/* Perform formatted output to standard error. */ -int jas_eprintf(const char *fmt, ...); - -/* Dump memory to a stream. */ -int jas_memdump(FILE *out, void *data, size_t len); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/converter/other/jpeg2000/libjasper/include/jasper/jas_fix.h b/converter/other/jpeg2000/libjasper/include/jasper/jas_fix.h deleted file mode 100644 index 9599eb1..0000000 --- a/converter/other/jpeg2000/libjasper/include/jasper/jas_fix.h +++ /dev/null @@ -1,406 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Fixed-Point Number Class - * - * $Id$ - */ - -#ifndef JAS_FIX_H -#define JAS_FIX_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include -#include - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/******************************************************************************\ -* Constants. -\******************************************************************************/ - -/* The representation of the value zero. */ -#define JAS_FIX_ZERO(fix_t, fracbits) \ - JAS_CAST(fix_t, 0) - -/* The representation of the value one. */ -#define JAS_FIX_ONE(fix_t, fracbits) \ - (JAS_CAST(fix_t, 1) << (fracbits)) - -/* The representation of the value one half. */ -#define JAS_FIX_HALF(fix_t, fracbits) \ - (JAS_CAST(fix_t, 1) << ((fracbits) - 1)) - -/******************************************************************************\ -* Conversion operations. -\******************************************************************************/ - -/* Convert an int to a fixed-point number. */ -#define JAS_INTTOFIX(fix_t, fracbits, x) \ - JAS_CAST(fix_t, (x) << (fracbits)) - -/* Convert a fixed-point number to an int. */ -#define JAS_FIXTOINT(fix_t, fracbits, x) \ - JAS_CAST(int, (x) >> (fracbits)) - -/* Convert a fixed-point number to a double. */ -#define JAS_FIXTODBL(fix_t, fracbits, x) \ - (JAS_CAST(double, x) / (JAS_CAST(fix_t, 1) << (fracbits))) - -/* Convert a double to a fixed-point number. */ -#define JAS_DBLTOFIX(fix_t, fracbits, x) \ - JAS_CAST(fix_t, ((x) * JAS_CAST(double, JAS_CAST(fix_t, 1) << (fracbits)))) - -/******************************************************************************\ -* Basic arithmetic operations. -* All other arithmetic operations are synthesized from these basic operations. -* There are three macros for each type of arithmetic operation. -* One macro always performs overflow/underflow checking, one never performs -* overflow/underflow checking, and one is generic with its behavior -* depending on compile-time flags. -* Only the generic macros should be invoked directly by application code. -\******************************************************************************/ - -/* Calculate the sum of two fixed-point numbers. */ -#if !defined(DEBUG_OVERFLOW) -#define JAS_FIX_ADD JAS_FIX_ADD_FAST -#else -#define JAS_FIX_ADD JAS_FIX_ADD_OFLOW -#endif - -/* Calculate the sum of two fixed-point numbers without overflow checking. */ -#define JAS_FIX_ADD_FAST(fix_t, fracbits, x, y) ((x) + (y)) - -/* Calculate the sum of two fixed-point numbers with overflow checking. */ -#define JAS_FIX_ADD_OFLOW(fix_t, fracbits, x, y) \ - ((x) >= 0) ? \ - (((y) >= 0) ? ((x) + (y) >= 0 || JAS_FIX_OFLOW(), (x) + (y)) : \ - ((x) + (y))) : \ - (((y) >= 0) ? ((x) + (y)) : ((x) + (y) < 0 || JAS_FIX_OFLOW(), \ - (x) + (y))) - -/* Calculate the product of two fixed-point numbers. */ -#if !defined(DEBUG_OVERFLOW) -#define JAS_FIX_MUL JAS_FIX_MUL_FAST -#else -#define JAS_FIX_MUL JAS_FIX_MUL_OFLOW -#endif - -/* Calculate the product of two fixed-point numbers without overflow - checking. */ -#define JAS_FIX_MUL_FAST(fix_t, fracbits, bigfix_t, x, y) \ - JAS_CAST(fix_t, (JAS_CAST(bigfix_t, x) * JAS_CAST(bigfix_t, y)) >> \ - (fracbits)) - -/* Calculate the product of two fixed-point numbers with overflow - checking. */ -#define JAS_FIX_MUL_OFLOW(fix_t, fracbits, bigfix_t, x, y) \ - ((JAS_CAST(bigfix_t, x) * JAS_CAST(bigfix_t, y) >> (fracbits)) == \ - JAS_CAST(fix_t, (JAS_CAST(bigfix_t, x) * JAS_CAST(bigfix_t, y) >> \ - (fracbits))) ? \ - JAS_CAST(fix_t, (JAS_CAST(bigfix_t, x) * JAS_CAST(bigfix_t, y) >> \ - (fracbits))) : JAS_FIX_OFLOW()) - -/* Calculate the product of a fixed-point number and an int. */ -#if !defined(DEBUG_OVERFLOW) -#define JAS_FIX_MULBYINT JAS_FIX_MULBYINT_FAST -#else -#define JAS_FIX_MULBYINT JAS_FIX_MULBYINT_OFLOW -#endif - -/* Calculate the product of a fixed-point number and an int without overflow - checking. */ -#define JAS_FIX_MULBYINT_FAST(fix_t, fracbits, x, y) \ - JAS_CAST(fix_t, ((x) * (y))) - -/* Calculate the product of a fixed-point number and an int with overflow - checking. */ -#define JAS_FIX_MULBYINT_OFLOW(fix_t, fracbits, x, y) \ - JAS_FIX_MULBYINT_FAST(fix_t, fracbits, x, y) - -/* Calculate the quotient of two fixed-point numbers. */ -#if !defined(DEBUG_OVERFLOW) -#define JAS_FIX_DIV JAS_FIX_DIV_FAST -#else -#define JAS_FIX_DIV JAS_FIX_DIV_UFLOW -#endif - -/* Calculate the quotient of two fixed-point numbers without underflow - checking. */ -#define JAS_FIX_DIV_FAST(fix_t, fracbits, bigfix_t, x, y) \ - JAS_CAST(fix_t, (JAS_CAST(bigfix_t, x) << (fracbits)) / (y)) - -/* Calculate the quotient of two fixed-point numbers with underflow - checking. */ -#define JAS_FIX_DIV_UFLOW(fix_t, fracbits, bigfix_t, x, y) \ - JAS_FIX_DIV_FAST(fix_t, fracbits, bigfix_t, x, y) - -/* Negate a fixed-point number. */ -#if !defined(DEBUG_OVERFLOW) -#define JAS_FIX_NEG JAS_FIX_NEG_FAST -#else -#define JAS_FIX_NEG JAS_FIX_NEG_OFLOW -#endif - -/* Negate a fixed-point number without overflow checking. */ -#define JAS_FIX_NEG_FAST(fix_t, fracbits, x) \ - (-(x)) - -/* Negate a fixed-point number with overflow checking. */ -/* Yes, overflow is actually possible for two's complement representations, - although highly unlikely to occur. */ -#define JAS_FIX_NEG_OFLOW(fix_t, fracbits, x) \ - (((x) < 0) ? (-(x) > 0 || JAS_FIX_OFLOW(), -(x)) : (-(x))) - -/* Perform an arithmetic shift left of a fixed-point number. */ -#if !defined(DEBUG_OVERFLOW) -#define JAS_FIX_ASL JAS_FIX_ASL_FAST -#else -#define JAS_FIX_ASL JAS_FIX_ASL_OFLOW -#endif - -/* Perform an arithmetic shift left of a fixed-point number without overflow - checking. */ -#define JAS_FIX_ASL_FAST(fix_t, fracbits, x, n) \ - ((x) << (n)) - -/* Perform an arithmetic shift left of a fixed-point number with overflow - checking. */ -#define JAS_FIX_ASL_OFLOW(fix_t, fracbits, x, n) \ - ((((x) << (n)) >> (n)) == (x) || JAS_FIX_OFLOW(), (x) << (n)) - -/* Perform an arithmetic shift right of a fixed-point number. */ -#if !defined(DEBUG_OVERFLOW) -#define JAS_FIX_ASR JAS_FIX_ASR_FAST -#else -#define JAS_FIX_ASR JAS_FIX_ASR_UFLOW -#endif - -/* Perform an arithmetic shift right of a fixed-point number without underflow - checking. */ -#define JAS_FIX_ASR_FAST(fix_t, fracbits, x, n) \ - ((x) >> (n)) - -/* Perform an arithmetic shift right of a fixed-point number with underflow - checking. */ -#define JAS_FIX_ASR_UFLOW(fix_t, fracbits, x, n) \ - JAS_FIX_ASR_FAST(fix_t, fracbits, x, n) - -/******************************************************************************\ -* Other basic arithmetic operations. -\******************************************************************************/ - -/* Calculate the difference between two fixed-point numbers. */ -#define JAS_FIX_SUB(fix_t, fracbits, x, y) \ - JAS_FIX_ADD(fix_t, fracbits, x, JAS_FIX_NEG(fix_t, fracbits, y)) - -/* Add one fixed-point number to another. */ -#define JAS_FIX_PLUSEQ(fix_t, fracbits, x, y) \ - ((x) = JAS_FIX_ADD(fix_t, fracbits, x, y)) - -/* Subtract one fixed-point number from another. */ -#define JAS_FIX_MINUSEQ(fix_t, fracbits, x, y) \ - ((x) = JAS_FIX_SUB(fix_t, fracbits, x, y)) - -/* Multiply one fixed-point number by another. */ -#define JAS_FIX_MULEQ(fix_t, fracbits, bigfix_t, x, y) \ - ((x) = JAS_FIX_MUL(fix_t, fracbits, bigfix_t, x, y)) - -/******************************************************************************\ -* Miscellaneous operations. -\******************************************************************************/ - -/* Calculate the absolute value of a fixed-point number. */ -#define JAS_FIX_ABS(fix_t, fracbits, x) \ - (((x) >= 0) ? (x) : (JAS_FIX_NEG(fix_t, fracbits, x))) - -/* Is a fixed-point number an integer? */ -#define JAS_FIX_ISINT(fix_t, fracbits, x) \ - (JAS_FIX_FLOOR(fix_t, fracbits, x) == (x)) - -/* Get the sign of a fixed-point number. */ -#define JAS_FIX_SGN(fix_t, fracbits, x) \ - ((x) >= 0 ? 1 : (-1)) - -/******************************************************************************\ -* Relational operations. -\******************************************************************************/ - -/* Compare two fixed-point numbers. */ -#define JAS_FIX_CMP(fix_t, fracbits, x, y) \ - ((x) > (y) ? 1 : (((x) == (y)) ? 0 : (-1))) - -/* Less than. */ -#define JAS_FIX_LT(fix_t, fracbits, x, y) \ - ((x) < (y)) - -/* Less than or equal. */ -#define JAS_FIX_LTE(fix_t, fracbits, x, y) \ - ((x) <= (y)) - -/* Greater than. */ -#define JAS_FIX_GT(fix_t, fracbits, x, y) \ - ((x) > (y)) - -/* Greater than or equal. */ -#define JAS_FIX_GTE(fix_t, fracbits, x, y) \ - ((x) >= (y)) - -/******************************************************************************\ -* Rounding functions. -\******************************************************************************/ - -/* Round a fixed-point number to the nearest integer. */ -#define JAS_FIX_ROUND(fix_t, fracbits, x) \ - (((x) < 0) ? JAS_FIX_FLOOR(fix_t, fracbits, JAS_FIX_ADD(fix_t, fracbits, \ - (x), JAS_FIX_HALF(fix_t, fracbits))) : \ - JAS_FIX_NEG(fix_t, fracbits, JAS_FIX_FLOOR(fix_t, fracbits, \ - JAS_FIX_ADD(fix_t, fracbits, (-(x)), JAS_FIX_HALF(fix_t, fracbits))))) - -/* Round a fixed-point number to the nearest integer in the direction of - negative infinity (i.e., the floor function). */ -#define JAS_FIX_FLOOR(fix_t, fracbits, x) \ - ((x) & (~((JAS_CAST(fix_t, 1) << (fracbits)) - 1))) - -/* Round a fixed-point number to the nearest integer in the direction - of zero. */ -#define JAS_FIX_TRUNC(fix_t, fracbits, x) \ - (((x) >= 0) ? JAS_FIX_FLOOR(fix_t, fracbits, x) : \ - JAS_FIX_CEIL(fix_t, fracbits, x)) - -/******************************************************************************\ -* The below macros are for internal library use only. Do not invoke them -* directly in application code. -\******************************************************************************/ - -/* Handle overflow. */ -#define JAS_FIX_OFLOW() \ - fprintf(stderr, "overflow error: file %s, line %d\n", __FILE__, __LINE__) - -/* Handle underflow. */ -#define JAS_FIX_UFLOW() \ - fprintf(stderr, "underflow error: file %s, line %d\n", __FILE__, __LINE__) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/converter/other/jpeg2000/libjasper/include/jasper/jas_getopt.h b/converter/other/jpeg2000/libjasper/include/jasper/jas_getopt.h deleted file mode 100644 index 4f272dc..0000000 --- a/converter/other/jpeg2000/libjasper/include/jasper/jas_getopt.h +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Command Line Option Parsing Code - * - * $Id$ - */ - -#ifndef JAS_GETOPT_H -#define JAS_GETOPT_H - -#ifdef __cplusplus -extern "C" { -#endif - -/******************************************************************************\ -* Constants. -\******************************************************************************/ - -#define JAS_GETOPT_EOF (-1) -#define JAS_GETOPT_ERR '?' - -/* option flags. */ -#define JAS_OPT_HASARG 0x01 /* option has argument */ - -/******************************************************************************\ -* Types. -\******************************************************************************/ - -/* Command line option type. */ -typedef struct { - - int id; - /* The unique identifier for this option. */ - - char *name; - /* The name of this option. */ - - int flags; - /* option flags. */ - -} jas_opt_t; - -/******************************************************************************\ -* External data. -\******************************************************************************/ - -/* The current option index. */ -extern int jas_optind; - -/* The current option argument. */ -extern char *jas_optarg; - -/* The debug level. */ -extern int jas_opterr; - -/******************************************************************************\ -* Prototypes. -\******************************************************************************/ - -/* Get the next option. */ -int jas_getopt(int argc, char **argv, jas_opt_t *opts); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/converter/other/jpeg2000/libjasper/include/jasper/jas_image.h b/converter/other/jpeg2000/libjasper/include/jasper/jas_image.h deleted file mode 100644 index 6e914ef..0000000 --- a/converter/other/jpeg2000/libjasper/include/jasper/jas_image.h +++ /dev/null @@ -1,593 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Image Class - * - * $Id$ - */ - -#ifndef JAS_IMAGE_H -#define JAS_IMAGE_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include "netpbm/pm_c_util.h" -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/******************************************************************************\ -* Constants. -\******************************************************************************/ - -/* - * Miscellaneous constants. - */ - -/* The threshold at which image data is no longer stored in memory. */ -#define JAS_IMAGE_INMEMTHRESH (16 * 1024 * 1024) - -/* - * Color models. - */ - -#define JAS_IMAGE_CS_UNKNOWN 0 /* Unknown */ -#define JAS_IMAGE_CS_GRAY 1 /* Standard Gray */ -#define JAS_IMAGE_CS_RGB 2 /* Standard RGB */ -#define JAS_IMAGE_CS_YCBCR 3 /* Standard YCC */ -#if 0 -#define JAS_IMAGE_CM_ICC 4 /* ICC Profile */ -#endif -/* - * Component types - */ - -#define JAS_IMAGE_CT_UNKNOWN 0x10000 -#define JAS_IMAGE_CT_COLOR(n) ((n) & 0x7fff) -#define JAS_IMAGE_CT_OPACITY 0x08000 - -#define JAS_IMAGE_CT_RGB_R 0 -#define JAS_IMAGE_CT_RGB_G 1 -#define JAS_IMAGE_CT_RGB_B 2 - -#define JAS_IMAGE_CT_YCBCR_Y 0 -#define JAS_IMAGE_CT_YCBCR_CB 1 -#define JAS_IMAGE_CT_YCBCR_CR 2 - -#define JAS_IMAGE_CT_GRAY_Y 0 - -/*****************************************************************************\ -* Image class and supporting classes. -\*****************************************************************************/ - -/* Image component class. */ - -typedef struct { - - uint_fast32_t tlx_; - /* The x-coordinate of the top-left corner of the component. */ - - uint_fast32_t tly_; - /* The y-coordinate of the top-left corner of the component. */ - - uint_fast32_t hstep_; - /* The horizontal sampling period in units of the reference grid. */ - - uint_fast32_t vstep_; - /* The vertical sampling period in units of the reference grid. */ - - uint_fast32_t width_; - /* The component width in samples. */ - - uint_fast32_t height_; - /* The component height in samples. */ - - uint_fast16_t prec_; - /* The precision of the sample data (i.e., the number of bits per - sample). If the samples are signed values, this quantity - includes the sign bit. */ - - uint_fast8_t sgnd_; - /* The signedness of the sample data. */ - - jas_stream_t *stream_; - /* The stream containing the component data. */ - - int cps_; - /* The number of characters per sample in the stream. */ - - uint_fast32_t type_; - /* The type of component (e.g., opacity, red, green, blue, luma). */ - -} jas_image_cmpt_t; - -/* Image class. */ - -typedef struct { - - uint_fast32_t tlx_; - /* The x-coordinate of the top-left corner of the image bounding box. */ - - uint_fast32_t tly_; - /* The y-coordinate of the top-left corner of the image bounding box. */ - - uint_fast32_t brx_; - /* The x-coordinate of the bottom-right corner of the image bounding - box (plus one). */ - - uint_fast32_t bry_; - /* The y-coordinate of the bottom-right corner of the image bounding - box (plus one). */ - - uint_fast16_t numcmpts_; - /* The number of components. */ - - uint_fast16_t maxcmpts_; - /* The maximum number of components that this image can have (i.e., the - allocated size of the components array). */ - - jas_image_cmpt_t **cmpts_; - /* Per-component information. */ - - int colorspace_; - /* The color space used (e.g., RGB, YCbCr, gray). This field is only - of particular relevance in the case of a multi-component image. */ - - unsigned char *iccp_; - /* ICC profile information. */ - - int iccplen_; - - bool inmem_; - -} jas_image_t; - -/* Component parameters class. */ -/* This data type exists solely/mainly for the purposes of the - jas_image_create function. */ - -typedef struct { - - uint_fast32_t tlx; - /* The x-coordinate of the top-left corner of the component. */ - - uint_fast32_t tly; - /* The y-coordinate of the top-left corner of the component. */ - - uint_fast32_t hstep; - /* The horizontal sampling period in units of the reference grid. */ - - uint_fast32_t vstep; - /* The vertical sampling period in units of the reference grid. */ - - uint_fast32_t width; - /* The width of the component in samples. */ - - uint_fast32_t height; - /* The height of the component in samples. */ - - uint_fast16_t prec; - /* The precision of the component sample data. */ - - bool sgnd; - /* The signedness of the component sample data. */ - -} jas_image_cmptparm_t; - -/******************************************************************************\ -* File format related classes. -\******************************************************************************/ - -#define JAS_IMAGE_MAXFMTS 32 -/* The maximum number of image data formats we can handle. */ - -/* Image format-dependent operations. */ - -typedef struct { - - jas_image_t *(*decode)(jas_stream_t *in, char *opts); - /* Decode image data from a stream. */ - - int (*encode)(jas_image_t *image, jas_stream_t *out, char *opts); - /* Encode image data to a stream. */ - - int (*validate)(jas_stream_t *in); - /* Determine if stream data is in a particular format. */ - -} jas_image_fmtops_t; - -/* Image format information. */ - -typedef struct { - - int id; - /* The ID for this format. */ - - char *name; - /* The name by which this format is identified. */ - - char *ext; - /* The file name extension associated with this format. */ - - char *desc; - /* A brief description of the format. */ - - jas_image_fmtops_t ops; - /* The operations for this format. */ - -} jas_image_fmtinfo_t; - -/******************************************************************************\ -* Image operations. -\******************************************************************************/ - -/* Create an image. */ -jas_image_t *jas_image_create(uint_fast16_t numcmpts, - jas_image_cmptparm_t *cmptparms, int colorspace); - -/* Create an "empty" image. */ -jas_image_t *jas_image_create0(void); - -/* Clone an image. */ -jas_image_t *jas_image_copy(jas_image_t *image); - -/* Deallocate any resources associated with an image. */ -void jas_image_destroy(jas_image_t *image); - -/* Get the width of the image in units of the image reference grid. */ -#define jas_image_width(image) \ - ((image)->brx_ - (image)->tlx_) - -/* Get the height of the image in units of the image reference grid. */ -#define jas_image_height(image) \ - ((image)->bry_ - (image)->tly_) - -/* Get the x-coordinate of the top-left corner of the image bounding box - on the reference grid. */ -#define jas_image_tlx(image) \ - ((image)->tlx_) - -/* Get the y-coordinate of the top-left corner of the image bounding box - on the reference grid. */ -#define jas_image_tly(image) \ - ((image)->tly_) - -/* Get the x-coordinate of the bottom-right corner of the image bounding box - on the reference grid (plus one). */ -#define jas_image_brx(image) \ - ((image)->brx_) - -/* Get the y-coordinate of the bottom-right corner of the image bounding box - on the reference grid (plus one). */ -#define jas_image_bry(image) \ - ((image)->bry_) - -/* Get the number of image components. */ -#define jas_image_numcmpts(image) \ - ((image)->numcmpts_) - -/* Get the color model used by the image. */ -#define jas_image_colorspace(image) \ - ((image)->colorspace_) - -/* Set the color model for an image. */ -#define jas_image_setcolorspace(image, colorspace) \ - ((image)->colorspace_ = (colorspace)) - -#define jas_image_cmpttype(image, cmptno) \ - ((image)->cmpts_[(cmptno)]->type_) -#define jas_image_setcmpttype(image, cmptno, type) \ - ((image)->cmpts_[(cmptno)]->type_ = (type)) - -/* Get the width of a component. */ -#define jas_image_cmptwidth(image, cmptno) \ - ((image)->cmpts_[cmptno]->width_) - -/* Get the height of a component. */ -#define jas_image_cmptheight(image, cmptno) \ - ((image)->cmpts_[cmptno]->height_) - -/* Get the signedness of the sample data for a component. */ -#define jas_image_cmptsgnd(image, cmptno) \ - ((image)->cmpts_[cmptno]->sgnd_) - -/* Get the precision of the sample data for a component. */ -#define jas_image_cmptprec(image, cmptno) \ - ((image)->cmpts_[cmptno]->prec_) - -/* Get the horizontal subsampling factor for a component. */ -#define jas_image_cmpthstep(image, cmptno) \ - ((image)->cmpts_[cmptno]->hstep_) - -/* Get the vertical subsampling factor for a component. */ -#define jas_image_cmptvstep(image, cmptno) \ - ((image)->cmpts_[cmptno]->vstep_) - -/* Get the x-coordinate of the top-left corner of a component. */ -#define jas_image_cmpttlx(image, cmptno) \ - ((image)->cmpts_[cmptno]->tlx_) - -/* Get the y-coordinate of the top-left corner of a component. */ -#define jas_image_cmpttly(image, cmptno) \ - ((image)->cmpts_[cmptno]->tly_) - -/* Get the x-coordinate of the bottom-right corner of a component - (plus "one"). */ -#define jas_image_cmptbrx(image, cmptno) \ - ((image)->cmpts_[cmptno]->tlx_ + (image)->cmpts_[cmptno]->width_ * \ - (image)->cmpts_[cmptno]->hstep_) - -/* Get the y-coordinate of the bottom-right corner of a component - (plus "one"). */ -#define jas_image_cmptbry(image, cmptno) \ - ((image)->cmpts_[cmptno]->tly_ + (image)->cmpts_[cmptno]->height_ * \ - (image)->cmpts_[cmptno]->vstep_) - -/* Get the raw size of an image (i.e., the nominal size of the image without - any compression. */ -uint_fast32_t jas_image_rawsize(jas_image_t *image); - -/* Create an image from a stream in some specified format. */ -jas_image_t *jas_image_decode(jas_stream_t *in, int fmt, char *optstr); - -/* Write an image to a stream in a specified format. */ -int jas_image_encode(jas_image_t *image, jas_stream_t *out, int fmt, - char *optstr); - -/* Read a rectangular region of an image component. */ -/* The position and size of the rectangular region to be read is specified -relative to the component's coordinate system. */ -int jas_image_readcmpt(jas_image_t *image, uint_fast16_t cmptno, - uint_fast32_t x, uint_fast32_t y, uint_fast32_t width, uint_fast32_t height, - jas_matrix_t *data); - -/* Write a rectangular region of an image component. */ -int jas_image_writecmpt(jas_image_t *image, uint_fast16_t cmptno, - uint_fast32_t x, uint_fast32_t y, uint_fast32_t width, uint_fast32_t height, - jas_matrix_t *data); - -/* Delete a component from an image. */ -void jas_image_delcmpt(jas_image_t *image, uint_fast16_t cmptno); - -/* Add a component to an image. */ -int jas_image_addcmpt(jas_image_t *image, uint_fast16_t cmptno, - jas_image_cmptparm_t *cmptparm); - -/* Copy a component from one image to another. */ -int jas_image_copycmpt(jas_image_t *dstimage, int dstcmptno, - jas_image_t *srcimage, int srccmptno); - -#if 0 -int_fast64_t jas_image_readcmpt1(jas_image_t *image, uint_fast16_t cmptno, - uint_fast32_t x, uint_fast32_t y); -#endif - -#define JAS_IMAGE_CDT_GETSGND(dtype) (((dtype) >> 7) & 1) -#define JAS_IMAGE_CDT_SETSGND(dtype) (((dtype) & 1) << 7) -#define JAS_IMAGE_CDT_GETPREC(dtype) ((dtype) & 0x7f) -#define JAS_IMAGE_CDT_SETPREC(dtype) ((dtype) & 0x7f) - -#define jas_image_cmptdtype(image, cmptno) \ - (JAS_IMAGE_CDT_SETSGND((image)->cmpts_[cmptno]->sgnd_) | JAS_IMAGE_CDT_SETPREC((image)->cmpts_[cmptno]->prec_)) - -void jas_image_dump(jas_image_t *image, FILE *out); - -int jas_image_depalettize(jas_image_t *image, int cmptno, int numlutents, - int_fast32_t *lutents, int dtype, int newcmptno); - -int jas_image_readcmptsample(jas_image_t *image, int cmptno, int x, int y); -void jas_image_writecmptsample(jas_image_t *image, int cmptno, int x, int y, - int_fast32_t v); - -int jas_image_getcmptbytype(jas_image_t *image, int ctype); - -/******************************************************************************\ -* Image format-related operations. -\******************************************************************************/ - -/* Clear the table of image formats. */ -void jas_image_clearfmts(void); - -/* Add entry to table of image formats. */ -int jas_image_addfmt(int id, const char *name, const char *ext, - const char *desc, - jas_image_fmtops_t *ops); - -/* Get the ID for the image format with the specified name. */ -int jas_image_strtofmt(char *s); - -/* Get the name of the image format with the specified ID. */ -char *jas_image_fmttostr(int fmt); - -/* Lookup image format information by the format ID. */ -jas_image_fmtinfo_t *jas_image_lookupfmtbyid(int id); - -/* Lookup image format information by the format name. */ -jas_image_fmtinfo_t *jas_image_lookupfmtbyname(const char *name); - -/* Guess the format of an image file based on its name. */ -int jas_image_fmtfromname(char *filename); - -/* Get the format of image data in a stream. */ -int jas_image_getfmt(jas_stream_t *in); - -/******************************************************************************\ -* Image format-dependent operations. -\******************************************************************************/ - -#if !defined(EXCLUDE_JPG_CAPABILITY) -/* Format-dependent operations for JPG capability. */ -jas_image_t *jpg_decode(jas_stream_t *in, char *optstr); -int jpg_encode(jas_image_t *image, jas_stream_t *out, char *optstr); -int jpg_validate(jas_stream_t *in); -#endif - -#if !defined(EXCLUDE_MIF_CAPABILITY) -/* Format-dependent operations for MIF capability. */ -jas_image_t *mif_decode(jas_stream_t *in, char *optstr); -int mif_encode(jas_image_t *image, jas_stream_t *out, char *optstr); -int mif_validate(jas_stream_t *in); -#endif - -#if !defined(EXCLUDE_PNM_CAPABILITY) -/* Format-dependent operations for PNM capability. */ -jas_image_t *pnm_decode(jas_stream_t *in, char *optstr); -int pnm_encode(jas_image_t *image, jas_stream_t *out, char *optstr); -int pnm_validate(jas_stream_t *in); -#endif - -#if !defined(EXCLUDE_RAS_CAPABILITY) -/* Format-dependent operations for Sun Rasterfile capability. */ -jas_image_t *ras_decode(jas_stream_t *in, char *optstr); -int ras_encode(jas_image_t *image, jas_stream_t *out, char *optstr); -int ras_validate(jas_stream_t *in); -#endif - -#if !defined(EXCLUDE_BMP_CAPABILITY) -/* Format-dependent operations for BMP capability. */ -jas_image_t *bmp_decode(jas_stream_t *in, char *optstr); -int bmp_encode(jas_image_t *image, jas_stream_t *out, char *optstr); -int bmp_validate(jas_stream_t *in); -#endif - -#if !defined(EXCLUDE_JP2_CAPABILITY) -/* Format-dependent operations for JP2 capability. */ -jas_image_t *jp2_decode(jas_stream_t *in, char *optstr); -int jp2_encode(jas_image_t *image, jas_stream_t *out, char *optstr); -int jp2_validate(jas_stream_t *in); -#endif - -#if !defined(EXCLUDE_JPC_CAPABILITY) -/* Format-dependent operations for JPEG-2000 code stream capability. */ -jas_image_t *jpc_decode(jas_stream_t *in, char *optstr); -int jpc_encode(jas_image_t *image, jas_stream_t *out, char *optstr); -int jpc_validate(jas_stream_t *in); -#endif - -#if !defined(EXCLUDE_PGX_CAPABILITY) -/* Format-dependent operations for PGX capability. */ -jas_image_t *pgx_decode(jas_stream_t *in, char *optstr); -int pgx_encode(jas_image_t *image, jas_stream_t *out, char *optstr); -int pgx_validate(jas_stream_t *in); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/converter/other/jpeg2000/libjasper/include/jasper/jas_init.h b/converter/other/jpeg2000/libjasper/include/jasper/jas_init.h deleted file mode 100644 index 4ebeaa8..0000000 --- a/converter/other/jpeg2000/libjasper/include/jasper/jas_init.h +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -#ifndef JAS_INIT_H -#define JAS_INIT_H - -#ifdef __cplusplus -extern "C" { -#endif - -/******************************************************************************\ -* Functions. -\******************************************************************************/ - -int jas_init(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/converter/other/jpeg2000/libjasper/include/jasper/jas_malloc.h b/converter/other/jpeg2000/libjasper/include/jasper/jas_malloc.h deleted file mode 100644 index fe5b617..0000000 --- a/converter/other/jpeg2000/libjasper/include/jasper/jas_malloc.h +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Memory Allocator - * - * $Id$ - */ - -#ifndef JAS_MALLOC_H -#define JAS_MALLOC_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/******************************************************************************\ -* Hack follows... -\******************************************************************************/ - -#if defined(DEBUG_MEMALLOC) -/* This is somewhat of a hack, but it's a useful hack. :-) */ -/* Use my own custom memory allocator for debugging. */ -#include "../../../../local/src/memalloc.h" -#define jas_malloc MEMALLOC -#define jas_free MEMFREE -#define jas_realloc MEMREALLOC -#define jas_calloc MEMCALLOC -#endif - -/******************************************************************************\ -* Functions. -\******************************************************************************/ - -#if !defined(DEBUG_MEMALLOC) - -/* Allocate memory. */ -void *jas_malloc(size_t size); - -/* Free memory. */ -void jas_free(void *ptr); - -/* Resize a block of allocated memory. */ -void *jas_realloc(void *ptr, size_t size); - -/* Allocate a block of memory and initialize the contents to zero. */ -void *jas_calloc(size_t nmemb, size_t size); - -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/converter/other/jpeg2000/libjasper/include/jasper/jas_math.h b/converter/other/jpeg2000/libjasper/include/jasper/jas_math.h deleted file mode 100644 index a43051e..0000000 --- a/converter/other/jpeg2000/libjasper/include/jasper/jas_math.h +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Math-Related Code - * - * $Id$ - */ - -#ifndef JAS_MATH_H -#define JAS_MATH_H - -/******************************************************************************\ -* Includes -\******************************************************************************/ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/******************************************************************************\ -* Macros -\******************************************************************************/ - -/* Compute the absolute value. */ -#define JAS_ABS(x) \ - (((x) >= 0) ? (x) : (-(x))) - -/* Compute the minimum of two values. */ -#define JAS_MIN(x, y) \ - (((x) < (y)) ? (x) : (y)) - -/* Compute the maximum of two values. */ -#define JAS_MAX(x, y) \ - (((x) > (y)) ? (x) : (y)) - -/* Compute the remainder from division (where division is defined such - that the remainder is always nonnegative). */ -#define JAS_MOD(x, y) \ - (((x) < 0) ? (((-x) % (y)) ? ((y) - ((-(x)) % (y))) : (0)) : ((x) % (y))) - -/* Compute the integer with the specified number of least significant bits - set to one. */ -#define JAS_ONES(n) \ - ((1 << (n)) - 1) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/converter/other/jpeg2000/libjasper/include/jasper/jas_seq.h b/converter/other/jpeg2000/libjasper/include/jasper/jas_seq.h deleted file mode 100644 index 4599f50..0000000 --- a/converter/other/jpeg2000/libjasper/include/jasper/jas_seq.h +++ /dev/null @@ -1,348 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Sequence/Matrix Library - * - * $Id$ - */ - -#ifndef JAS_SEQ_H -#define JAS_SEQ_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/******************************************************************************\ -* Constants. -\******************************************************************************/ - -/* This matrix is a reference to another matrix. */ -#define JAS_MATRIX_REF 0x0001 - -/******************************************************************************\ -* Types. -\******************************************************************************/ - -/* An element in a sequence. */ -typedef int_fast32_t jas_seqent_t; - -/* An element in a matrix. */ -typedef int_fast32_t jas_matent_t; - -/* Matrix. */ - -typedef struct { - - /* Additional state information. */ - int flags_; - - /* The starting horizontal index. */ - int_fast32_t xstart_; - - /* The starting vertical index. */ - int_fast32_t ystart_; - - /* The ending horizontal index. */ - int_fast32_t xend_; - - /* The ending vertical index. */ - int_fast32_t yend_; - - /* The number of rows in the matrix. */ - int_fast32_t numrows_; - - /* The number of columns in the matrix. */ - int_fast32_t numcols_; - - /* Pointers to the start of each row. */ - jas_seqent_t **rows_; - - /* The allocated size of the rows array. */ - int_fast32_t maxrows_; - - /* The matrix data buffer. */ - jas_seqent_t *data_; - - /* The allocated size of the data array. */ - int_fast32_t datasize_; - -} jas_matrix_t; - -typedef jas_matrix_t jas_seq2d_t; -typedef jas_matrix_t jas_seq_t; - -/******************************************************************************\ -* Functions/macros for matrix class. -\******************************************************************************/ - -/* Get the number of rows. */ -#define jas_matrix_numrows(matrix) \ - ((matrix)->numrows_) - -/* Get the number of columns. */ -#define jas_matrix_numcols(matrix) \ - ((matrix)->numcols_) - -/* Get a matrix element. */ -#define jas_matrix_get(matrix, i, j) \ - ((matrix)->rows_[i][j]) - -/* Set a matrix element. */ -#define jas_matrix_set(matrix, i, j, v) \ - ((matrix)->rows_[i][j] = (v)) - -/* Get an element from a matrix that is known to be a row or column vector. */ -#define jas_matrix_getv(matrix, i) \ - (((matrix)->numrows_ == 1) ? ((matrix)->rows_[0][i]) : \ - ((matrix)->rows_[i][0])) - -/* Set an element in a matrix that is known to be a row or column vector. */ -#define jas_matrix_setv(matrix, i, v) \ - (((matrix)->numrows_ == 1) ? ((matrix)->rows_[0][i] = (v)) : \ - ((matrix)->rows_[i][0] = (v))) - -/* Get the address of an element in a matrix. */ -#define jas_matrix_getref(matrix, i, j) \ - (&(matrix)->rows_[i][j]) - -#define jas_matrix_getvref(matrix, i) \ - (((matrix)->numrows_ > 1) ? jas_matrix_getref(matrix, i, 0) : jas_matrix_getref(matrix, 0, i)) - -#define jas_matrix_length(matrix) \ - (max((matrix)->numrows_, (matrix)->numcols_)) - -/* Create a matrix with the specified dimensions. */ -jas_matrix_t *jas_matrix_create(int numrows, int numcols); - -/* Destroy a matrix. */ -void jas_matrix_destroy(jas_matrix_t *matrix); - -jas_matrix_t *jas_matrix_copy(jas_matrix_t *x); - -/* Resize a matrix. The previous contents of the matrix are lost. */ -int jas_matrix_resize(jas_matrix_t *matrix, int numrows, int numcols); - -int jas_matrix_output(jas_matrix_t *matrix, FILE *out); - -jas_matrix_t *jas_matrix_input(FILE *in); - -/* Create a matrix that references part of another matrix. */ -void jas_matrix_bindsub(jas_matrix_t *mat0, jas_matrix_t *mat1, int r0, int c0, - int r1, int c1); - -/* Create a matrix that is a reference to a row of another matrix. */ -#define jas_matrix_bindrow(mat0, mat1, r) \ - (jas_matrix_bindsub((mat0), (mat1), (r), 0, (r), (mat1)->numcols_ - 1)) - -/* Create a matrix that is a reference to a column of another matrix. */ -#define jas_matrix_bindcol(mat0, mat1, c) \ - (jas_matrix_bindsub((mat0), (mat1), 0, (c), (mat1)->numrows_ - 1, (c))) - -/* Clip the values of matrix elements to the specified range. */ -void jas_matrix_clip(jas_matrix_t *matrix, jas_seqent_t minval, - jas_seqent_t maxval); - -/* Arithmetic shift left of all elements in a matrix. */ -void jas_matrix_asl(jas_matrix_t *matrix, int n); - -/* Arithmetic shift right of all elements in a matrix. */ -void jas_matrix_asr(jas_matrix_t *matrix, int n); - -/* Almost-but-not-quite arithmetic shift right of all elements in a matrix. */ -void jas_matrix_divpow2(jas_matrix_t *matrix, int n); - -/* Set all elements of a matrix to the specified value. */ -void jas_matrix_setall(jas_matrix_t *matrix, jas_seqent_t val); - -/* The spacing between rows of a matrix. */ -#define jas_matrix_rowstep(matrix) \ - (((matrix)->numrows_ > 1) ? ((matrix)->rows_[1] - (matrix)->rows_[0]) : (0)) - -/* The spacing between columns of a matrix. */ -#define jas_matrix_step(matrix) \ - (((matrix)->numrows_ > 1) ? (jas_matrix_rowstep(matrix)) : (1)) - -/* Compare two matrices for equality. */ -int jas_matrix_cmp(jas_matrix_t *mat0, jas_matrix_t *mat1); - -/******************************************************************************\ -* Functions/macros for 2-D sequence class. -\******************************************************************************/ - -jas_seq2d_t *jas_seq2d_copy(jas_seq2d_t *x); - -jas_matrix_t *jas_seq2d_create(int xstart, int ystart, int xend, int yend); - -#define jas_seq2d_destroy(s) \ - jas_matrix_destroy(s) - -#define jas_seq2d_xstart(s) \ - ((s)->xstart_) -#define jas_seq2d_ystart(s) \ - ((s)->ystart_) -#define jas_seq2d_xend(s) \ - ((s)->xend_) -#define jas_seq2d_yend(s) \ - ((s)->yend_) -#define jas_seq2d_getref(s, x, y) \ - (jas_matrix_getref(s, (y) - (s)->ystart_, (x) - (s)->xstart_)) -#define jas_seq2d_get(s, x, y) \ - (jas_matrix_get(s, (y) - (s)->ystart_, (x) - (s)->xstart_)) -#define jas_seq2d_rowstep(s) \ - jas_matrix_rowstep(s) -#define jas_seq2d_width(s) \ - ((s)->xend_ - (s)->xstart_) -#define jas_seq2d_height(s) \ - ((s)->yend_ - (s)->ystart_) -#define jas_seq2d_setshift(s, x, y) \ - ((s)->xstart_ = (x), (s)->ystart_ = (y), \ - (s)->xend_ = (s)->xstart_ + (s)->numcols_, \ - (s)->yend_ = (s)->ystart_ + (s)->numrows_) - -void jas_seq2d_bindsub(jas_matrix_t *s, jas_matrix_t *s1, int xstart, - int ystart, int xend, int yend); - -/******************************************************************************\ -* Functions/macros for 1-D sequence class. -\******************************************************************************/ - -#define jas_seq_create(start, end) \ - (jas_seq2d_create(start, 0, end, 1)) - -#define jas_seq_destroy(seq) \ - (jas_seq2d_destroy(seq)) - -#define jas_seq_set(seq, i, v) \ - ((seq)->rows_[0][(i) - (seq)->xstart_] = (v)) -#define jas_seq_getref(seq, i) \ - (&(seq)->rows_[0][(i) - (seq)->xstart_]) -#define jas_seq_get(seq, i) \ - ((seq)->rows_[0][(i) - (seq)->xstart_]) -#define jas_seq_start(seq) \ - ((seq)->xstart_) -#define jas_seq_end(seq) \ - ((seq)->xend_) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/converter/other/jpeg2000/libjasper/include/jasper/jas_stream.h b/converter/other/jpeg2000/libjasper/include/jasper/jas_stream.h deleted file mode 100644 index 1062fe1..0000000 --- a/converter/other/jpeg2000/libjasper/include/jasper/jas_stream.h +++ /dev/null @@ -1,498 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * I/O Stream Class - * - * $Id$ - */ - -#ifndef JAS_STREAM_H -#define JAS_STREAM_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include -#include -#if defined(HAVE_UNISTD_H) -#include -#endif -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/******************************************************************************\ -* Constants. -\******************************************************************************/ - -/* On most UNIX systems, we probably need to define O_BINARY ourselves. */ -#ifndef O_BINARY -#define O_BINARY 0 -#endif - -/* - * Stream open flags. - */ - -/* The stream was opened for reading. */ -#define JAS_STREAM_READ 0x0001 -/* The stream was opened for writing. */ -#define JAS_STREAM_WRITE 0x0002 -/* The stream was opened for appending. */ -#define JAS_STREAM_APPEND 0x0004 -/* The stream was opened in binary mode. */ -#define JAS_STREAM_BINARY 0x0008 -/* The stream should be created/truncated. */ -#define JAS_STREAM_CREATE 0x0010 - -#define JAS_STREAM_NOCLOSE 0x0020 - -/* - * Stream buffering flags. - */ - -/* The stream is unbuffered. */ -#define JAS_STREAM_UNBUF 0x0000 -/* The stream is line buffered. */ -#define JAS_STREAM_LINEBUF 0x0001 -/* The stream is fully buffered. */ -#define JAS_STREAM_FULLBUF 0x0002 -/* The buffering mode mask. */ -#define JAS_STREAM_BUFMODEMASK 0x000f - -/* The memory associated with the buffer needs to be deallocated when the - stream is destroyed. */ -#define JAS_STREAM_FREEBUF 0x0008 -/* The buffer is currently being used for reading. */ -#define JAS_STREAM_RDBUF 0x0010 -/* The buffer is currently being used for writing. */ -#define JAS_STREAM_WRBUF 0x0020 - -/* - * Stream error flags. - */ - -/* The end-of-file has been encountered (on reading). */ -#define JAS_STREAM_EOF 0x0001 -/* An I/O error has been encountered on the stream. */ -#define JAS_STREAM_ERR 0x0002 -/* The read/write limit has been exceeded. */ -#define JAS_STREAM_RWLIMIT 0x0004 -/* The error mask. */ -#define JAS_STREAM_ERRMASK \ - (JAS_STREAM_EOF | JAS_STREAM_ERR | JAS_STREAM_RWLIMIT) - -/* - * Other miscellaneous constants. - */ - -/* The default buffer size (for fully-buffered operation). */ -#define JAS_STREAM_BUFSIZE 8192 -/* The default permission mask for file creation. */ -#define JAS_STREAM_PERMS 0666 - -/* The maximum number of characters that can always be put back on a stream. */ -#define JAS_STREAM_MAXPUTBACK 16 - -/******************************************************************************\ -* Types. -\******************************************************************************/ - -/* - * Generic file object. - */ - -typedef void jas_stream_obj_t; - -/* - * Generic file object operations. - */ - -typedef struct { - - /* Read characters from a file object. */ - int (*read_)(jas_stream_obj_t *obj, char *buf, int cnt); - - /* Write characters to a file object. */ - int (*write_)(jas_stream_obj_t *obj, char *buf, int cnt); - - /* Set the position for a file object. */ - long (*seek_)(jas_stream_obj_t *obj, long offset, int origin); - - /* Close a file object. */ - int (*close_)(jas_stream_obj_t *obj); - -} jas_stream_ops_t; - -/* - * Stream object. - */ - -typedef struct { - - /* The mode in which the stream was opened. */ - int openmode_; - - /* The buffering mode. */ - int bufmode_; - - /* The stream status. */ - int flags_; - - /* The start of the buffer area to use for reading/writing. */ - unsigned char *bufbase_; - - /* The start of the buffer area excluding the extra initial space for - character putback. */ - unsigned char *bufstart_; - - /* The buffer size. */ - int bufsize_; - - /* The current position in the buffer. */ - unsigned char *ptr_; - - /* The number of characters that must be read/written before - the buffer needs to be filled/flushed. */ - int cnt_; - - /* A trivial buffer to be used for unbuffered operation. */ - unsigned char tinybuf_[JAS_STREAM_MAXPUTBACK + 1]; - - /* The operations for the underlying stream file object. */ - jas_stream_ops_t *ops_; - - /* The underlying stream file object. */ - jas_stream_obj_t *obj_; - - /* The number of characters read/written. */ - long rwcnt_; - - /* The maximum number of characters that may be read/written. */ - long rwlimit_; - -} jas_stream_t; - -/* - * Regular file object. - */ - -/* Note: This is simply a file descriptor. */ -typedef int jas_stream_fileobj_t; - -/* - * Memory file object. - */ - -typedef struct { - - /* The data associated with this file. */ - unsigned char *buf_; - - /* The allocated size of the buffer for holding file data. */ - int bufsize_; - - /* The length of the file. */ - int_fast32_t len_; - - /* The seek position. */ - int_fast32_t pos_; - - /* Is the buffer growable? */ - int growable_; - - /* Was the buffer allocated internally? */ - int myalloc_; - -} jas_stream_memobj_t; - -/******************************************************************************\ -* Macros/functions for opening and closing streams. -\******************************************************************************/ - -/* Open a file as a stream. */ -jas_stream_t *jas_stream_fopen(const char *filename, const char *mode); - -/* Open a memory buffer as a stream. */ -jas_stream_t *jas_stream_memopen(char *buf, int bufsize); - -/* Open a file descriptor as a stream. */ -jas_stream_t *jas_stream_fdopen(int fd, const char *mode); - -/* Open a stdio stream as a stream. */ -jas_stream_t *jas_stream_freopen(const char *path, const char *mode, FILE *fp); - -/* Open a temporary file as a stream. */ -jas_stream_t *jas_stream_tmpfile(void); - -/* Close a stream. */ -int jas_stream_close(jas_stream_t *stream); - -/******************************************************************************\ -* Macros/functions for getting/setting the stream state. -\******************************************************************************/ - -/* Get the EOF indicator for a stream. */ -#define jas_stream_eof(stream) \ - (((stream)->flags_ & JAS_STREAM_EOF) != 0) - -/* Get the error indicator for a stream. */ -#define jas_stream_error(stream) \ - (((stream)->flags_ & JAS_STREAM_ERR) != 0) - -/* Clear the error indicator for a stream. */ -#define jas_stream_clearerr(stream) \ - ((stream)->flags_ &= ~(JAS_STREAM_ERR | JAS_STREAM_EOF)) - -/* Get the read/write limit for a stream. */ -#define jas_stream_getrwlimit(stream) \ - (((const jas_stream_t *)(stream))->rwlimit_) - -/* Set the read/write limit for a stream. */ -int jas_stream_setrwlimit(jas_stream_t *stream, long rwlimit); - -/* Get the read/write count for a stream. */ -#define jas_stream_getrwcount(stream) \ - (((const jas_stream_t *)(stream))->rwcnt_) - -/* Set the read/write count for a stream. */ -long jas_stream_setrwcount(jas_stream_t *stream, long rwcnt); - -/******************************************************************************\ -* Macros/functions for I/O. -\******************************************************************************/ - -/* Read a character from a stream. */ -#if defined(DEBUG) -#define jas_stream_getc(stream) jas_stream_getc_func(stream) -#else -#define jas_stream_getc(stream) jas_stream_getc_macro(stream) -#endif - -/* Write a character to a stream. */ -#if defined(DEBUG) -#define jas_stream_putc(stream, c) jas_stream_putc_func(stream, c) -#else -#define jas_stream_putc(stream, c) jas_stream_putc_macro(stream, c) -#endif - -/* Read characters from a stream into a buffer. */ -int jas_stream_read(jas_stream_t *stream, void *buf, int cnt); - -/* Write characters from a buffer to a stream. */ -int jas_stream_write(jas_stream_t *stream, const void *buf, int cnt); - -/* Write formatted output to a stream. */ -int jas_stream_printf(jas_stream_t *stream, const char *fmt, ...); - -/* Write a string to a stream. */ -int jas_stream_puts(jas_stream_t *stream, const char *s); - -/* Read a line of input from a stream. */ -char *jas_stream_gets(jas_stream_t *stream, char *buf, int bufsize); - -/* Look at the next character to be read from a stream without actually - removing it from the stream. */ -#define jas_stream_peekc(stream) \ - (((stream)->cnt_ <= 0) ? jas_stream_fillbuf(stream, 0) : \ - ((int)(*(stream)->ptr_))) - -/* Put a character back on a stream. */ -int jas_stream_ungetc(jas_stream_t *stream, int c); - -/******************************************************************************\ -* Macros/functions for getting/setting the stream position. -\******************************************************************************/ - -/* Is it possible to seek on this stream? */ -int jas_stream_isseekable(jas_stream_t *stream); - -/* Set the current position within the stream. */ -long jas_stream_seek(jas_stream_t *stream, long offset, int origin); - -/* Get the current position within the stream. */ -long jas_stream_tell(jas_stream_t *stream); - -/* Seek to the beginning of a stream. */ -int jas_stream_rewind(jas_stream_t *stream); - -/******************************************************************************\ -* Macros/functions for flushing. -\******************************************************************************/ - -/* Flush any pending output to a stream. */ -int jas_stream_flush(jas_stream_t *stream); - -/******************************************************************************\ -* Miscellaneous macros/functions. -\******************************************************************************/ - -/* Copy data from one stream to another. */ -int jas_stream_copy(jas_stream_t *dst, jas_stream_t *src, int n); - -/* Display stream contents (for debugging purposes). */ -int jas_stream_display(jas_stream_t *stream, FILE *fp, int n); - -/* Consume (i.e., discard) characters from stream. */ -int jas_stream_gobble(jas_stream_t *stream, int n); - -/* Get the size of the file associated with the specified stream. - The specified stream must be seekable. */ -long jas_stream_length(jas_stream_t *stream); - -/******************************************************************************\ -* Internal functions. -\******************************************************************************/ - -/* The following functions are for internal use only! If you call them -directly, you will die a horrible, miserable, and painful death! */ - -/* Read a character from a stream. */ -#define jas_stream_getc_macro(stream) \ - ((!((stream)->flags_ & (JAS_STREAM_ERR | JAS_STREAM_EOF | \ - JAS_STREAM_RWLIMIT))) ? \ - (((stream)->rwlimit_ >= 0 && (stream)->rwcnt_ >= (stream)->rwlimit_) ? \ - (stream->flags_ |= JAS_STREAM_RWLIMIT, EOF) : \ - jas_stream_getc2(stream)) : EOF) -#define jas_stream_getc2(stream) \ - ((--(stream)->cnt_ < 0) ? jas_stream_fillbuf(stream, 1) : \ - (++(stream)->rwcnt_, (int)(*(stream)->ptr_++))) - -/* Write a character to a stream. */ -#define jas_stream_putc_macro(stream, c) \ - ((!((stream)->flags_ & (JAS_STREAM_ERR | JAS_STREAM_EOF | \ - JAS_STREAM_RWLIMIT))) ? \ - (((stream)->rwlimit_ >= 0 && (stream)->rwcnt_ >= (stream)->rwlimit_) ? \ - (stream->flags_ |= JAS_STREAM_RWLIMIT, EOF) : \ - jas_stream_putc2(stream, c)) : EOF) -#define jas_stream_putc2(stream, c) \ - (((stream)->bufmode_ |= JAS_STREAM_WRBUF, --(stream)->cnt_ < 0) ? \ - jas_stream_flushbuf((stream), (unsigned char)(c)) : \ - (++(stream)->rwcnt_, (int)(*(stream)->ptr_++ = (c)))) - -/* These prototypes need to be here for the sake of the stream_getc and -stream_putc macros. */ -int jas_stream_fillbuf(jas_stream_t *stream, int getflag); -int jas_stream_flushbuf(jas_stream_t *stream, int c); -int jas_stream_getc_func(jas_stream_t *stream); -int jas_stream_putc_func(jas_stream_t *stream, int c); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/converter/other/jpeg2000/libjasper/include/jasper/jas_string.h b/converter/other/jpeg2000/libjasper/include/jasper/jas_string.h deleted file mode 100644 index 55b611b..0000000 --- a/converter/other/jpeg2000/libjasper/include/jasper/jas_string.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * String Library - * - * $Id$ - */ - -#ifndef JAS_STRING_H -#define JAS_STRING_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/******************************************************************************\ -* Functions. -\******************************************************************************/ - -/* Copy a string (a la strdup). */ -char *jas_strdup(const char *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/converter/other/jpeg2000/libjasper/include/jasper/jas_tvp.h b/converter/other/jpeg2000/libjasper/include/jasper/jas_tvp.h deleted file mode 100644 index 9ac50db..0000000 --- a/converter/other/jpeg2000/libjasper/include/jasper/jas_tvp.h +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Tag/Value Parser - * - * $Id$ - */ - -#ifndef JAS_TVP_H -#define JAS_TVP_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#ifdef __cplusplus -extern "C" { -#endif - -/******************************************************************************\ -* Types. -\******************************************************************************/ - -/* Tag information type. */ - -typedef struct { - - int id; - /* The ID for the tag. */ - - const char *name; - /* The name of the tag. */ - -} jas_taginfo_t; - -/* Tag-value parser type. */ - -typedef struct { - - char *buf; - /* The parsing buffer. */ - - char *tag; - /* The current tag name. */ - - const char *val; - /* The current value. */ - - char *pos; - /* The current position in the parsing buffer. */ - -} jas_tvparser_t; - -/******************************************************************************\ -* Tag information functions. -\******************************************************************************/ - -/* Lookup a tag by name. */ -jas_taginfo_t *jas_taginfos_lookup(jas_taginfo_t *taginfos, const char *name); - -/* This function returns a pointer to the specified taginfo object if it - exists (i.e., the pointer is nonnull); otherwise, a pointer to a dummy - object is returned. This is useful in some situations to avoid checking - for a null pointer. */ -jas_taginfo_t *jas_taginfo_nonull(jas_taginfo_t *taginfo); - -/******************************************************************************\ -* Tag-value parser functions. -\******************************************************************************/ - -/* Create a tag-value parser for the specified string. */ -jas_tvparser_t *jas_tvparser_create(const char *s); - -/* Destroy a tag-value parser. */ -void jas_tvparser_destroy(jas_tvparser_t *tvparser); - -/* Get the next tag-value pair. */ -int jas_tvparser_next(jas_tvparser_t *tvparser); - -/* Get the tag name for the current tag-value pair. */ -char *jas_tvparser_gettag(jas_tvparser_t *tvparser); - -/* Get the value for the current tag-value pair. */ -const char *jas_tvparser_getval(jas_tvparser_t *tvparser); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/converter/other/jpeg2000/libjasper/include/jasper/jas_types.h b/converter/other/jpeg2000/libjasper/include/jasper/jas_types.h deleted file mode 100644 index fbcb2ff..0000000 --- a/converter/other/jpeg2000/libjasper/include/jasper/jas_types.h +++ /dev/null @@ -1,14 +0,0 @@ -/* In the original Jasper library, this contains definitions of the int_fast32, - etc. types and bool. - - In Netpbm, we do that with pm_config.h, and the original Jasper - method doesn't work. -*/ -#include "netpbm/pm_config.h" - - -/* The below macro is intended to be used for type casts. By using this - macro, type casts can be easily located in the source code with - tools like "grep". */ -#define JAS_CAST(t, e) \ - ((t) (e)) diff --git a/converter/other/jpeg2000/libjasper/include/jasper/jas_version.h b/converter/other/jpeg2000/libjasper/include/jasper/jas_version.h deleted file mode 100644 index 2178257..0000000 --- a/converter/other/jpeg2000/libjasper/include/jasper/jas_version.h +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * $Id$ - */ - -#ifndef JAS_VERSION_H -#define JAS_VERSION_H - -#ifdef __cplusplus -extern "C" { -#endif - -/******************************************************************************\ -* Constants and types. -\******************************************************************************/ - -#if !defined(JAS_VERSION) -/* The version information below should match that specified in - the "configure.in" file! */ -#define JAS_VERSION "1.600.0" -#endif - -#define JAS_COPYRIGHT \ - "Copyright (c) 1999-2000 Image Power, Inc. and the University of\n" \ - " British Columbia.\n" \ - "Copyright (c) 2001-2002 Michael David Adams.\n" \ - "All rights reserved.\n" - -#define JAS_NOTES \ - "For more information about this software, please visit the following\n" \ - "web sites/pages:\n" \ - " http://www.ece.ubc.ca/~mdadams/jasper\n" \ - " http://www.jpeg.org/software\n" \ - "To be added to the (moderated) JasPer software announcements\n" \ - "mailing list, send an email to:\n" \ - " jasper-announce-subscribe@yahoogroups.com\n" \ - "To be added to the (unmoderated) JasPer software discussion\n" \ - "mailing list, send an email to:\n" \ - " jasper-discussion-subscribe@yahoogroups.com\n" \ - "Please send any bug reports to:\n" \ - " mdadams@ieee.org\n" - -/******************************************************************************\ -* Functions. -\******************************************************************************/ - -const char *jas_getversion(void); -/* Get the version information for the JasPer library. */ -/* Note: Since libjasper can be built as a shared library, the version - returned by this function may not necessarily correspond to JAS_VERSION. */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/converter/other/jpeg2000/libjasper/include/jasper/jasper.h b/converter/other/jpeg2000/libjasper/include/jasper/jasper.h deleted file mode 100644 index b003acf..0000000 --- a/converter/other/jpeg2000/libjasper/include/jasper/jasper.h +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -#ifndef JAS_JASPER_H -#define JAS_JASPER_H - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/converter/other/jpeg2000/libjasper/jp2/Makefile b/converter/other/jpeg2000/libjasper/jp2/Makefile deleted file mode 100644 index 65838cc..0000000 --- a/converter/other/jpeg2000/libjasper/jp2/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -ifeq ($(SRCDIR)x,x) - SRCDIR = $(CURDIR)/../../../../.. - BUILDDIR = $(SRCDIR) -endif -SUBDIR = converter/other/jpeg2000/libjasper/jp2 -VPATH=.:$(SRCDIR)/$(SUBDIR) - -JASPERSRCDIR=$(SRCDIR)/$(SUBDIR)/.. - -include $(BUILDDIR)/config.mk - -LIB_OBJECTS = jp2_cod.o jp2_dec.o jp2_enc.o - -MERGE_OBJECTS = - -all: partlist $(LIB_OBJECTS) - -include $(JASPERSRCDIR)/common.mk - diff --git a/converter/other/jpeg2000/libjasper/jp2/jp2_cod.c b/converter/other/jpeg2000/libjasper/jp2/jp2_cod.c deleted file mode 100644 index c99c960..0000000 --- a/converter/other/jpeg2000/libjasper/jp2/jp2_cod.c +++ /dev/null @@ -1,931 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * JP2 Library - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include - -#include "netpbm/pm_c_util.h" - -#include "jasper/jas_stream.h" -#include "jasper/jas_malloc.h" -#include "jasper/jas_debug.h" - -#include "jp2_cod.h" - -/******************************************************************************\ -* Function prototypes. -\******************************************************************************/ - -#define ONES(n) ((1 << (n)) - 1) - -jp2_boxinfo_t *jp2_boxinfolookup(int type); - -static int jp2_getuint8(jas_stream_t *in, uint_fast8_t *val); -static int jp2_getuint16(jas_stream_t *in, uint_fast16_t *val); -static int jp2_getuint32(jas_stream_t *in, uint_fast32_t *val); -static int jp2_getuint64(jas_stream_t *in, uint_fast64_t *val); -static int jp2_putuint8(jas_stream_t *out, uint_fast8_t val); -static int jp2_putuint16(jas_stream_t *out, uint_fast16_t val); -static int jp2_putuint32(jas_stream_t *out, uint_fast32_t val); - -static int jp2_getint(jas_stream_t *in, int s, int n, int_fast32_t *val); - -jp2_box_t *jp2_box_get(jas_stream_t *in); -void jp2_box_dump(jp2_box_t *box, FILE *out); - -static int jp2_jp_getdata(jp2_box_t *box, jas_stream_t *in); -static int jp2_jp_putdata(jp2_box_t *box, jas_stream_t *out); -static int jp2_ftyp_getdata(jp2_box_t *box, jas_stream_t *in); -static int jp2_ftyp_putdata(jp2_box_t *box, jas_stream_t *out); -static int jp2_ihdr_getdata(jp2_box_t *box, jas_stream_t *in); -static int jp2_ihdr_putdata(jp2_box_t *box, jas_stream_t *out); -static void jp2_bpcc_destroy(jp2_box_t *box); -static int jp2_bpcc_getdata(jp2_box_t *box, jas_stream_t *in); -static int jp2_bpcc_putdata(jp2_box_t *box, jas_stream_t *out); -static int jp2_colr_getdata(jp2_box_t *box, jas_stream_t *in); -static int jp2_colr_putdata(jp2_box_t *box, jas_stream_t *out); -static void jp2_colr_dumpdata(jp2_box_t *box, FILE *out); -static void jp2_colr_destroy(jp2_box_t *box); -static void jp2_cdef_destroy(jp2_box_t *box); -static int jp2_cdef_getdata(jp2_box_t *box, jas_stream_t *in); -static int jp2_cdef_putdata(jp2_box_t *box, jas_stream_t *out); -static void jp2_cdef_dumpdata(jp2_box_t *box, FILE *out); -static void jp2_cmap_destroy(jp2_box_t *box); -static int jp2_cmap_getdata(jp2_box_t *box, jas_stream_t *in); -static int jp2_cmap_putdata(jp2_box_t *box, jas_stream_t *out); -static void jp2_cmap_dumpdata(jp2_box_t *box, FILE *out); -static void jp2_pclr_destroy(jp2_box_t *box); -static int jp2_pclr_getdata(jp2_box_t *box, jas_stream_t *in); -static int jp2_pclr_putdata(jp2_box_t *box, jas_stream_t *out); -static void jp2_pclr_dumpdata(jp2_box_t *box, FILE *out); - -/******************************************************************************\ -* Local data. -\******************************************************************************/ - -jp2_boxinfo_t jp2_boxinfos[] = { - {JP2_BOX_JP, "JP", 0, - {0, 0, jp2_jp_getdata, jp2_jp_putdata, 0}}, - {JP2_BOX_FTYP, "FTYP", 0, - {0, 0, jp2_ftyp_getdata, jp2_ftyp_putdata, 0}}, - {JP2_BOX_JP2H, "JP2H", JP2_BOX_SUPER, - {0, 0, 0, 0, 0}}, - {JP2_BOX_IHDR, "IHDR", 0, - {0, 0, jp2_ihdr_getdata, jp2_ihdr_putdata, 0}}, - {JP2_BOX_BPCC, "BPCC", 0, - {0, jp2_bpcc_destroy, jp2_bpcc_getdata, jp2_bpcc_putdata, 0}}, - {JP2_BOX_COLR, "COLR", 0, - {0, jp2_colr_destroy, jp2_colr_getdata, jp2_colr_putdata, jp2_colr_dumpdata}}, - {JP2_BOX_PCLR, "PCLR", 0, - {0, jp2_pclr_destroy, jp2_pclr_getdata, jp2_pclr_putdata, jp2_pclr_dumpdata}}, - {JP2_BOX_CMAP, "CMAP", 0, - {0, jp2_cmap_destroy, jp2_cmap_getdata, jp2_cmap_putdata, jp2_cmap_dumpdata}}, - {JP2_BOX_CDEF, "CDEF", 0, - {0, jp2_cdef_destroy, jp2_cdef_getdata, jp2_cdef_putdata, jp2_cdef_dumpdata}}, - {JP2_BOX_RES, "RES", JP2_BOX_SUPER, - {0, 0, 0, 0, 0}}, - {JP2_BOX_RESC, "RESC", 0, - {0, 0, 0, 0, 0}}, - {JP2_BOX_RESD, "RESD", 0, - {0, 0, 0, 0, 0}}, - {JP2_BOX_JP2C, "JP2C", JP2_BOX_NODATA, - {0, 0, 0, 0, 0}}, - {JP2_BOX_JP2I, "JP2I", 0, - {0, 0, 0, 0, 0}}, - {JP2_BOX_XML, "XML", 0, - {0, 0, 0, 0, 0}}, - {JP2_BOX_UUID, "UUID", 0, - {0, 0, 0, 0, 0}}, - {JP2_BOX_UINF, "UINF", JP2_BOX_SUPER, - {0, 0, 0, 0, 0}}, - {JP2_BOX_ULST, "ULST", 0, - {0, 0, 0, 0, 0}}, - {JP2_BOX_URL, "URL", 0, - {0, 0, 0, 0, 0}}, - {0, 0, 0, {0, 0, 0, 0, 0}}, -}; - -jp2_boxinfo_t jp2_boxinfo_unk = { - 0, "Unknown", 0, {0, 0, 0, 0} -}; - -/******************************************************************************\ -* Box constructor. -\******************************************************************************/ - -jp2_box_t *jp2_box_create(int type) -{ - jp2_box_t *box; - jp2_boxinfo_t *boxinfo; - - if (!(box = jas_malloc(sizeof(jp2_box_t)))) { - return 0; - } - memset(box, 0, sizeof(jp2_box_t)); - box->type = type; - box->len = 0; - if (!(boxinfo = jp2_boxinfolookup(type))) { - return 0; - } - box->info = boxinfo; - box->ops = &boxinfo->ops; - return box; -} - -/******************************************************************************\ -* Box destructor. -\******************************************************************************/ - -void jp2_box_destroy(jp2_box_t *box) -{ - if (box->ops->destroy) { - (*box->ops->destroy)(box); - } - jas_free(box); -} - -static void jp2_bpcc_destroy(jp2_box_t *box) -{ - jp2_bpcc_t *bpcc = &box->data.bpcc; - if (bpcc->bpcs) { - jas_free(bpcc->bpcs); - bpcc->bpcs = 0; - } -} - -static void jp2_cdef_destroy(jp2_box_t *box) -{ - jp2_cdef_t *cdef = &box->data.cdef; - if (cdef->ents) { - jas_free(cdef->ents); - cdef->ents = 0; - } -} - -/******************************************************************************\ -* Box input. -\******************************************************************************/ - -jp2_box_t *jp2_box_get(jas_stream_t *in) -{ - jp2_box_t *box; - jp2_boxinfo_t *boxinfo; - jas_stream_t *tmpstream; - uint_fast32_t len; - uint_fast64_t extlen; - bool dataflag; - - box = 0; - tmpstream = 0; - - if (!(box = jas_malloc(sizeof(jp2_box_t)))) { - goto error; - } - box->ops = &jp2_boxinfo_unk.ops; - if (jp2_getuint32(in, &len) || jp2_getuint32(in, &box->type)) { - goto error; - } - boxinfo = jp2_boxinfolookup(box->type); - box->info = boxinfo; - box->ops = &boxinfo->ops; - box->len = len; - if (box->len == 1) { - if (jp2_getuint64(in, &extlen)) { - goto error; - } - box->len = extlen; - } - if (box->len != 0 && box->len < 8) { - goto error; - } - - dataflag = !(box->info->flags & (JP2_BOX_SUPER | JP2_BOX_NODATA)); - - if (dataflag) { - if (!(tmpstream = jas_stream_memopen(0, 0))) { - goto error; - } - if (jas_stream_copy(tmpstream, in, box->len - JP2_BOX_HDRLEN)) { - goto error; - } - jas_stream_rewind(tmpstream); - - if (box->ops->getdata) { - if ((*box->ops->getdata)(box, tmpstream)) { - goto error; - } - } - jas_stream_close(tmpstream); - } - - if (jas_getdbglevel() > 0) { - jp2_box_dump(box, stderr); - } - return box; - abort(); - -error: - if (box) { - jp2_box_destroy(box); - } - if (tmpstream) { - jas_stream_close(tmpstream); - } - return 0; -} - -void jp2_box_dump(jp2_box_t *box, FILE *out) -{ - jp2_boxinfo_t *boxinfo; - boxinfo = jp2_boxinfolookup(box->type); - assert(boxinfo); - - fprintf(out, "JP2 box: "); - fprintf(out, "type=%c%s%c (0x%08x); length=%d\n", '"', boxinfo->name, - '"', (unsigned int) box->type, (int)box->len); - if (box->ops->dumpdata) { - (*box->ops->dumpdata)(box, out); - } -} - -static int jp2_jp_getdata(jp2_box_t *box, jas_stream_t *in) -{ - jp2_jp_t *jp = &box->data.jp; - if (jp2_getuint32(in, &jp->magic)) { - return -1; - } - return 0; -} - -static int jp2_ftyp_getdata(jp2_box_t *box, jas_stream_t *in) -{ - jp2_ftyp_t *ftyp = &box->data.ftyp; - int i; - if (jp2_getuint32(in, &ftyp->majver) || jp2_getuint32(in, &ftyp->minver)) { - return -1; - } - ftyp->numcompatcodes = ((box->len - JP2_BOX_HDRLEN) - 8) / 4; - if (ftyp->numcompatcodes > JP2_FTYP_MAXCOMPATCODES) { - return -1; - } - for (i = 0; i < ftyp->numcompatcodes; ++i) { - if (jp2_getuint32(in, &ftyp->compatcodes[i])) { - return -1; - } - } - return 0; -} - -static int jp2_ihdr_getdata(jp2_box_t *box, jas_stream_t *in) -{ - jp2_ihdr_t *ihdr = &box->data.ihdr; - if (jp2_getuint32(in, &ihdr->height) || jp2_getuint32(in, &ihdr->width) || - jp2_getuint16(in, &ihdr->numcmpts) || jp2_getuint8(in, &ihdr->bpc) || - jp2_getuint8(in, &ihdr->comptype) || jp2_getuint8(in, &ihdr->csunk) || - jp2_getuint8(in, &ihdr->ipr)) { - return -1; - } - return 0; -} - -static int jp2_bpcc_getdata(jp2_box_t *box, jas_stream_t *in) -{ - jp2_bpcc_t *bpcc = &box->data.bpcc; - int i; - bpcc->numcmpts = box->len - JP2_BOX_HDRLEN; - if (!(bpcc->bpcs = jas_malloc(bpcc->numcmpts * sizeof(uint_fast8_t)))) { - return -1; - } - for (i = 0; i < bpcc->numcmpts; ++i) { - if (jp2_getuint8(in, &bpcc->bpcs[i])) { - return -1; - } - } - return 0; -} - -static void jp2_colr_dumpdata(jp2_box_t *box, FILE *out) -{ - jp2_colr_t *colr = &box->data.colr; - fprintf(out, "method=%d; pri=%d; approx=%d\n", (int)colr->method, (int)colr->pri, (int)colr->approx); - switch (colr->method) { - case JP2_COLR_ENUM: - fprintf(out, "csid=%d\n", (int)colr->csid); - break; - case JP2_COLR_ICC: - jas_memdump(out, colr->iccp, colr->iccplen); - break; - } -} - -static int jp2_colr_getdata(jp2_box_t *box, jas_stream_t *in) -{ - jp2_colr_t *colr = &box->data.colr; - colr->csid = 0; - colr->iccp = 0; - colr->iccplen = 0; - - if (jp2_getuint8(in, &colr->method) || jp2_getuint8(in, &colr->pri) || - jp2_getuint8(in, &colr->approx)) { - return -1; - } - switch (colr->method) { - case JP2_COLR_ENUM: - if (jp2_getuint32(in, &colr->csid)) { - return -1; - } - break; - case JP2_COLR_ICC: - colr->iccplen = box->len - JP2_BOX_HDRLEN - 3; - if (!(colr->iccp = jas_malloc(colr->iccplen * sizeof(uint_fast8_t)))) { - return -1; - } - if (jas_stream_read(in, colr->iccp, colr->iccplen) != colr->iccplen) { - return -1; - } - break; - } - return 0; -} - -static void jp2_cdef_dumpdata(jp2_box_t *box, FILE *out) -{ - jp2_cdef_t *cdef = &box->data.cdef; - int i; - for (i = 0; i < cdef->numchans; ++i) { - fprintf(out, "channo=%d; type=%d; assoc=%d\n", - (int)cdef->ents[i].channo, (int)cdef->ents[i].type, - (int)cdef->ents[i].assoc); - } -} - -static void jp2_colr_destroy(jp2_box_t *box) -{ - jp2_colr_t *colr = &box->data.colr; - if (colr->iccp) { - free(colr->iccp); - } -} - -static int jp2_cdef_getdata(jp2_box_t *box, jas_stream_t *in) -{ - jp2_cdef_t *cdef = &box->data.cdef; - jp2_cdefchan_t *chan; - int channo; - if (jp2_getuint16(in, &cdef->numchans)) { - return -1; - } - if (!(cdef->ents = jas_malloc(cdef->numchans * sizeof(jp2_cdefchan_t)))) { - return -1; - } - for (channo = 0; channo < cdef->numchans; ++channo) { - chan = &cdef->ents[channo]; - if (jp2_getuint16(in, &chan->channo) || jp2_getuint16(in, &chan->type) || - jp2_getuint16(in, &chan->assoc)) { - return -1; - } - } - return 0; -} - -/******************************************************************************\ -* Box output. -\******************************************************************************/ - -int jp2_box_put(jp2_box_t *box, jas_stream_t *out) -{ - jas_stream_t *tmpstream; - bool dataflag; - - tmpstream = 0; - - dataflag = !(box->info->flags & (JP2_BOX_SUPER | JP2_BOX_NODATA)); - - if (dataflag) { - tmpstream = jas_stream_memopen(0, 0); - if (box->ops->putdata) { - if ((*box->ops->putdata)(box, tmpstream)) { - goto error; - } - } - box->len = jas_stream_tell(tmpstream) + JP2_BOX_HDRLEN; - jas_stream_rewind(tmpstream); - } - /* There was code here in official Jasper to handle 64 bit lengths, - but it was based on determining whether box->len fits in 32 bits. - But box->len is a 32 bit data type, so it fits in 32 bits by - definition. Either this encoder is incapable of making boxes with - lengths that don't fit in 32 bits, or it passes invalid values of - box->len to us. We assume the former because it's easier. - */ - if (jp2_putuint32(out, box->len)) { - goto error; - } - if (jp2_putuint32(out, box->type)) { - goto error; - } - - if (dataflag) { - if (jas_stream_copy(out, tmpstream, box->len - JP2_BOX_HDRLEN)) { - goto error; - } - jas_stream_close(tmpstream); - } - - return 0; - abort(); - -error: - - if (tmpstream) { - jas_stream_close(tmpstream); - } - return -1; -} - -static int jp2_jp_putdata(jp2_box_t *box, jas_stream_t *out) -{ - jp2_jp_t *jp = &box->data.jp; - if (jp2_putuint32(out, jp->magic)) { - return -1; - } - return 0; -} - -static int jp2_ftyp_putdata(jp2_box_t *box, jas_stream_t *out) -{ - jp2_ftyp_t *ftyp = &box->data.ftyp; - int i; - if (jp2_putuint32(out, ftyp->majver) || jp2_putuint32(out, ftyp->minver)) { - return -1; - } - for (i = 0; i < ftyp->numcompatcodes; ++i) { - if (jp2_putuint32(out, ftyp->compatcodes[i])) { - return -1; - } - } - return 0; -} - -static int jp2_ihdr_putdata(jp2_box_t *box, jas_stream_t *out) -{ - jp2_ihdr_t *ihdr = &box->data.ihdr; - if (jp2_putuint32(out, ihdr->height) || jp2_putuint32(out, ihdr->width) || - jp2_putuint16(out, ihdr->numcmpts) || jp2_putuint8(out, ihdr->bpc) || - jp2_putuint8(out, ihdr->comptype) || jp2_putuint8(out, ihdr->csunk) || - jp2_putuint8(out, ihdr->ipr)) { - return -1; - } - return 0; -} - -static int jp2_bpcc_putdata(jp2_box_t *box, jas_stream_t *out) -{ - jp2_bpcc_t *bpcc = &box->data.bpcc; - int i; - for (i = 0; i < bpcc->numcmpts; ++i) { - if (jp2_putuint8(out, bpcc->bpcs[i])) { - return -1; - } - } - return 0; -} - -static int jp2_colr_putdata(jp2_box_t *box, jas_stream_t *out) -{ - jp2_colr_t *colr = &box->data.colr; - if (jp2_putuint8(out, colr->method) || jp2_putuint8(out, colr->pri) || - jp2_putuint8(out, colr->approx)) { - return -1; - } - switch (colr->method) { - case JP2_COLR_ENUM: - if (jp2_putuint32(out, colr->csid)) { - return -1; - } - break; - case JP2_COLR_ICC: - /* XXX - not implemented */ - abort(); - break; - } - return 0; -} - -static int jp2_cdef_putdata(jp2_box_t *box, jas_stream_t *out) -{ - jp2_cdef_t *cdef = &box->data.cdef; - int i; - jp2_cdefchan_t *ent; - - if (jp2_putuint16(out, cdef->numchans)) { - return -1; - } - - for (i = 0; i < cdef->numchans; ++i) { - ent = &cdef->ents[i]; - if (jp2_putuint16(out, ent->channo) || - jp2_putuint16(out, ent->type) || - jp2_putuint16(out, ent->assoc)) { - return -1; - } - } - return 0; -} - -/******************************************************************************\ -* Input operations for primitive types. -\******************************************************************************/ - -static int jp2_getuint8(jas_stream_t *in, uint_fast8_t *val) -{ - int c; - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - if (val) { - *val = c; - } - return 0; -} - -static int jp2_getuint16(jas_stream_t *in, uint_fast16_t *val) -{ - uint_fast16_t v; - int c; - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - v = c; - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - v = (v << 8) | c; - if (val) { - *val = v; - } - return 0; -} - -static int jp2_getuint32(jas_stream_t *in, uint_fast32_t *val) -{ - uint_fast32_t v; - int c; - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - v = c; - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - v = (v << 8) | c; - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - v = (v << 8) | c; - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - v = (v << 8) | c; - if (val) { - *val = v; - } - return 0; -} - -static int jp2_getuint64(jas_stream_t *in, uint_fast64_t *val) -{ - abort(); -} - -/******************************************************************************\ -* Output operations for primitive types. -\******************************************************************************/ - -static int jp2_putuint8(jas_stream_t *out, uint_fast8_t val) -{ - if (jas_stream_putc(out, val & 0xff) == EOF) { - return -1; - } - return 0; -} - -static int jp2_putuint16(jas_stream_t *out, uint_fast16_t val) -{ - if (jas_stream_putc(out, (val >> 8) & 0xff) == EOF || - jas_stream_putc(out, val & 0xff) == EOF) { - return -1; - } - return 0; -} - -static int jp2_putuint32(jas_stream_t *out, uint_fast32_t val) -{ - if (jas_stream_putc(out, (val >> 24) & 0xff) == EOF || - jas_stream_putc(out, (val >> 16) & 0xff) == EOF || - jas_stream_putc(out, (val >> 8) & 0xff) == EOF || - jas_stream_putc(out, val & 0xff) == EOF) { - return -1; - } - return 0; -} - -/******************************************************************************\ -* Miscellaneous code. -\******************************************************************************/ - -jp2_boxinfo_t *jp2_boxinfolookup(int type) -{ - jp2_boxinfo_t *boxinfo; - for (boxinfo = jp2_boxinfos; boxinfo->name; ++boxinfo) { - if (boxinfo->type == type) { - return boxinfo; - } - } - return &jp2_boxinfo_unk; -} - - - - - -static void jp2_cmap_destroy(jp2_box_t *box) -{ - jp2_cmap_t *cmap = &box->data.cmap; - if (cmap->ents) { - jas_free(cmap->ents); - } -} - -static int jp2_cmap_getdata(jp2_box_t *box, jas_stream_t *in) -{ - jp2_cmap_t *cmap = &box->data.cmap; - jp2_cmapent_t *ent; - int i; - - cmap->numchans = (box->len - JP2_BOX_HDRLEN) / 4; - if (!(cmap->ents = jas_malloc(cmap->numchans * sizeof(jp2_cmapent_t)))) { - return -1; - } - for (i = 0; i < cmap->numchans; ++i) { - ent = &cmap->ents[i]; - if (jp2_getuint16(in, &ent->cmptno) || - jp2_getuint8(in, &ent->map) || - jp2_getuint8(in, &ent->pcol)) { - return -1; - } - } - - return 0; -} - -static int jp2_cmap_putdata(jp2_box_t *box, jas_stream_t *out) -{ - return -1; -} - -static void jp2_cmap_dumpdata(jp2_box_t *box, FILE *out) -{ - jp2_cmap_t *cmap = &box->data.cmap; - int i; - jp2_cmapent_t *ent; - fprintf(stderr, "numchans = %d\n", (int) cmap->numchans); - for (i = 0; i < cmap->numchans; ++i) { - ent = &cmap->ents[i]; - fprintf(stderr, "cmptno=%d; map=%d; pcol=%d\n", - (int) ent->cmptno, (int) ent->map, (int) ent->pcol); - } -} - -static void jp2_pclr_destroy(jp2_box_t *box) -{ - jp2_pclr_t *pclr = &box->data.pclr; - if (pclr->lutdata) { - jas_free(pclr->lutdata); - } -} - -static int jp2_pclr_getdata(jp2_box_t *box, jas_stream_t *in) -{ - jp2_pclr_t *pclr = &box->data.pclr; - int lutsize; - int i; - int j; - int_fast32_t x; - - pclr->lutdata = 0; - - if (jp2_getuint16(in, &pclr->numlutents) || - jp2_getuint8(in, &pclr->numchans)) { - return -1; - } - lutsize = pclr->numlutents * pclr->numchans; - if (!(pclr->lutdata = jas_malloc(lutsize * sizeof(int_fast32_t)))) { - return -1; - } - if (!(pclr->bpc = jas_malloc(pclr->numchans * sizeof(uint_fast8_t)))) { - return -1; - } - for (i = 0; i < pclr->numchans; ++i) { - if (jp2_getuint8(in, &pclr->bpc[i])) { - return -1; - } - } - for (i = 0; i < pclr->numlutents; ++i) { - for (j = 0; j < pclr->numchans; ++j) { - if (jp2_getint(in, (pclr->bpc[j] & 0x80) != 0, - (pclr->bpc[j] & 0x7f) + 1, &x)) { - return -1; - } - pclr->lutdata[i * pclr->numchans + j] = x; - } - } - return 0; -} - -static int jp2_pclr_putdata(jp2_box_t *box, jas_stream_t *out) -{ - /* This code from official Jasper must be part of unfinished work. - It generates an unused variable warning. - jp2_pclr_t *pclr = &box->data.pclr; - */ - return -1; -} - -static void jp2_pclr_dumpdata(jp2_box_t *box, FILE *out) -{ - jp2_pclr_t *pclr = &box->data.pclr; - int i; - int j; - fprintf(out, "numents=%d; numchans=%d\n", (int) pclr->numlutents, - (int) pclr->numchans); - for (i = 0; i < pclr->numlutents; ++i) { - for (j = 0; j < pclr->numchans; ++j) { - fprintf(out, "LUT[%d][%d]=%d\n", i, j, - (int)pclr->lutdata[i * pclr->numchans + j]); - } - } -} - -static int jp2_getint(jas_stream_t *in, int s, int n, int_fast32_t *val) -{ - int c; - int i; - uint_fast32_t v; - int m; - - m = (n + 7) / 8; - - v = 0; - for (i = 0; i < m; ++i) { - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - v = (v << 8) | c; - } - v &= ONES(n); - if (s) { - int sb; - sb = v & (1 << (8 * m - 1)); - *val = ((~v) + 1) & ONES(8 * m); - if (sb) { - *val = -*val; - } - } else { - *val = v; - } - - return 0; -} - -jp2_cdefchan_t *jp2_cdef_lookup(jp2_cdef_t *cdef, int channo) -{ - int i; - jp2_cdefchan_t *cdefent; - for (i = 0; i < cdef->numchans; ++i) { - cdefent = &cdef->ents[i]; - if (cdefent->channo == channo) { - return cdefent; - } - } - return 0; -} diff --git a/converter/other/jpeg2000/libjasper/jp2/jp2_cod.h b/converter/other/jpeg2000/libjasper/jp2/jp2_cod.h deleted file mode 100644 index 96b48d1..0000000 --- a/converter/other/jpeg2000/libjasper/jp2/jp2_cod.h +++ /dev/null @@ -1,347 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * JP2 Library - * - * $Id$ - */ - -#ifndef JP2_COD_H -#define JP2_COD_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include "jasper/jas_types.h" - -/******************************************************************************\ -* Macros. -\******************************************************************************/ - -#define JP2_SPTOBPC(s, p) \ - ((((p) - 1) & 0x7f) | (((s) & 1) << 7)) - -/******************************************************************************\ -* Box class. -\******************************************************************************/ - -#define JP2_BOX_HDRLEN 8 - -/* Box types. */ -#define JP2_BOX_JP 0x6a502020 /* Signature */ -#define JP2_BOX_FTYP 0x66747970 /* File Type */ -#define JP2_BOX_JP2H 0x6a703268 /* JP2 Header */ -#define JP2_BOX_IHDR 0x69686472 /* Image Header */ -#define JP2_BOX_BPCC 0x62706363 /* Bits Per Component */ -#define JP2_BOX_COLR 0x636f6c72 /* Color Specification */ -#define JP2_BOX_PCLR 0x70636c72 /* Palette */ -#define JP2_BOX_CMAP 0x636d6170 /* Component Mapping */ -#define JP2_BOX_CDEF 0x63646566 /* Channel Definition */ -#define JP2_BOX_RES 0x72657320 /* Resolution */ -#define JP2_BOX_RESC 0x72657363 /* Capture Resolution */ -#define JP2_BOX_RESD 0x72657364 /* Default Display Resolution */ -#define JP2_BOX_JP2C 0x6a703263 /* Contiguous Code Stream */ -#define JP2_BOX_JP2I 0x6a703269 /* Intellectual Property */ -#define JP2_BOX_XML 0x786d6c20 /* XML */ -#define JP2_BOX_UUID 0x75756964 /* UUID */ -#define JP2_BOX_UINF 0x75696e66 /* UUID Info */ -#define JP2_BOX_ULST 0x75637374 /* UUID List */ -#define JP2_BOX_URL 0x75726c20 /* URL */ - -#define JP2_BOX_SUPER 0x01 -#define JP2_BOX_NODATA 0x02 - -/* JP box data. */ - -#define JP2_JP_MAGIC 0x0d0a870a -#define JP2_JP_LEN 12 - -typedef struct { - uint_fast32_t magic; -} jp2_jp_t; - -/* FTYP box data. */ - -#define JP2_FTYP_MAXCOMPATCODES 32 -#define JP2_FTYP_MAJVER 0x6a703220 -#define JP2_FTYP_MINVER 0 -#define JP2_FTYP_COMPATCODE JP2_FTYP_MAJVER - -typedef struct { - uint_fast32_t majver; - uint_fast32_t minver; - uint_fast32_t numcompatcodes; - uint_fast32_t compatcodes[JP2_FTYP_MAXCOMPATCODES]; -} jp2_ftyp_t; - -/* IHDR box data. */ - -#define JP2_IHDR_COMPTYPE 7 -#define JP2_IHDR_BPCNULL 255 - -typedef struct { - uint_fast32_t width; - uint_fast32_t height; - uint_fast16_t numcmpts; - uint_fast8_t bpc; - uint_fast8_t comptype; - uint_fast8_t csunk; - uint_fast8_t ipr; -} jp2_ihdr_t; - -/* BPCC box data. */ - -typedef struct { - uint_fast16_t numcmpts; - uint_fast8_t *bpcs; -} jp2_bpcc_t; - -/* COLR box data. */ - -#define JP2_COLR_ENUM 1 -#define JP2_COLR_ICC 2 -#define JP2_COLR_PRI 0 - -#define JP2_COLR_SRGB 16 -#define JP2_COLR_SGRAY 17 -#define JP2_COLR_SYCC 18 - -typedef struct { - uint_fast8_t method; - uint_fast8_t pri; - uint_fast8_t approx; - uint_fast32_t csid; - uint_fast8_t *iccp; - int iccplen; - /* XXX - Someday we ought to add ICC profile data here. */ -} jp2_colr_t; - -/* PCLR box data. */ - -typedef struct { - uint_fast16_t numlutents; - uint_fast8_t numchans; - int_fast32_t *lutdata; - uint_fast8_t *bpc; -} jp2_pclr_t; - -/* CDEF box per-channel data. */ - -#define JP2_CDEF_RGB_R 1 -#define JP2_CDEF_RGB_G 2 -#define JP2_CDEF_RGB_B 3 - -#define JP2_CDEF_YCBCR_Y 1 -#define JP2_CDEF_YCBCR_CB 2 -#define JP2_CDEF_YCBCR_CR 3 - -#define JP2_CDEF_GRAY_Y 1 - -#define JP2_CDEF_TYPE_COLOR 0 -#define JP2_CDEF_TYPE_OPACITY 1 -#define JP2_CDEF_TYPE_UNSPEC 65535 -#define JP2_CDEF_ASOC_ALL 0 -#define JP2_CDEF_ASOC_NONE 65535 - -typedef struct { - uint_fast16_t channo; - uint_fast16_t type; - uint_fast16_t assoc; -} jp2_cdefchan_t; - -/* CDEF box data. */ - -typedef struct { - uint_fast16_t numchans; - jp2_cdefchan_t *ents; -} jp2_cdef_t; - -typedef struct { - uint_fast16_t cmptno; - uint_fast8_t map; - uint_fast8_t pcol; -} jp2_cmapent_t; - -typedef struct { - uint_fast16_t numchans; - jp2_cmapent_t *ents; -} jp2_cmap_t; - -#define JP2_CMAP_DIRECT 0 -#define JP2_CMAP_PALETTE 1 - -/* Generic box. */ - -struct jp2_boxops_s; -typedef struct { - - struct jp2_boxops_s *ops; - struct jp2_boxinfo_s *info; - - uint_fast32_t type; - uint_fast32_t len; - - union { - jp2_jp_t jp; - jp2_ftyp_t ftyp; - jp2_ihdr_t ihdr; - jp2_bpcc_t bpcc; - jp2_colr_t colr; - jp2_pclr_t pclr; - jp2_cdef_t cdef; - jp2_cmap_t cmap; - } data; - -} jp2_box_t; - -typedef struct jp2_boxops_s { - void (*init)(jp2_box_t *box); - void (*destroy)(jp2_box_t *box); - int (*getdata)(jp2_box_t *box, jas_stream_t *in); - int (*putdata)(jp2_box_t *box, jas_stream_t *out); - void (*dumpdata)(jp2_box_t *box, FILE *out); -} jp2_boxops_t; - -/******************************************************************************\ -* -\******************************************************************************/ - -typedef struct jp2_boxinfo_s { - int type; - const char *name; - int flags; - jp2_boxops_t ops; -} jp2_boxinfo_t; - -/******************************************************************************\ -* Box class. -\******************************************************************************/ - -jp2_box_t *jp2_box_create(int type); -void jp2_box_destroy(jp2_box_t *box); -jp2_box_t *jp2_box_get(jas_stream_t *in); -int jp2_box_put(jp2_box_t *box, jas_stream_t *out); - -#define JP2_DTYPETOBPC(dtype) \ - ((JAS_IMAGE_CDT_GETSGND(dtype) << 7) | (JAS_IMAGE_CDT_GETPREC(dtype) - 1)) -#define JP2_BPCTODTYPE(bpc) \ - (JAS_IMAGE_CDT_SETSGND(bpc >> 7) | JAS_IMAGE_CDT_SETPREC((bpc & 0x7f) + 1)) - -#define ICC_CS_RGB 0x52474220 -#define ICC_CS_YCBCR 0x59436272 -#define ICC_CS_GRAY 0x47524159 - -jp2_cdefchan_t *jp2_cdef_lookup(jp2_cdef_t *cdef, int channo); - -#endif diff --git a/converter/other/jpeg2000/libjasper/jp2/jp2_dec.c b/converter/other/jpeg2000/libjasper/jp2/jp2_dec.c deleted file mode 100644 index a9463a5..0000000 --- a/converter/other/jpeg2000/libjasper/jp2/jp2_dec.c +++ /dev/null @@ -1,667 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -#include "jasper/jas_image.h" -#include "jasper/jas_stream.h" -#include "jasper/jas_math.h" -#include "jasper/jas_debug.h" -#include "jasper/jas_malloc.h" -#include "jasper/jas_version.h" - -#include "jp2_cod.h" -#include "jp2_dec.h" - -#define JP2_VALIDATELEN (JAS_MIN(JP2_JP_LEN + 16, JAS_STREAM_MAXPUTBACK)) - - - -static jp2_dec_t * -jp2_dec_create(void) { - - jp2_dec_t *dec; - - dec = jas_malloc(sizeof(jp2_dec_t)); - if (dec) { - dec->ihdr = 0; - dec->bpcc = 0; - dec->cdef = 0; - dec->pclr = 0; - dec->image = 0; - dec->chantocmptlut = 0; - dec->cmap = 0; - dec->colr = 0; - } - return dec; -} - - - -static void -jp2_dec_destroy(jp2_dec_t *dec) { - - if (dec->ihdr) - jp2_box_destroy(dec->ihdr); - - if (dec->bpcc) - jp2_box_destroy(dec->bpcc); - - if (dec->cdef) - jp2_box_destroy(dec->cdef); - - if (dec->pclr) - jp2_box_destroy(dec->pclr); - - if (dec->image) - jas_image_destroy(dec->image); - - if (dec->cmap) - jp2_box_destroy(dec->cmap); - - if (dec->colr) - jp2_box_destroy(dec->colr); - - if (dec->chantocmptlut) - jas_free(dec->chantocmptlut); - - jas_free(dec); -} - - - -static int -jp2_getct(int colorspace, int type, int assoc) { - - if (type == 1 && assoc == 0) - return JAS_IMAGE_CT_OPACITY; - - if (type == 0 && assoc >= 1 && assoc <= 65534) { - switch (colorspace) { - case JAS_IMAGE_CS_RGB: - switch (assoc) { - case JP2_CDEF_RGB_R: - return JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_RGB_R); - break; - case JP2_CDEF_RGB_G: - return JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_RGB_G); - break; - case JP2_CDEF_RGB_B: - return JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_RGB_B); - break; - } - break; - case JAS_IMAGE_CS_YCBCR: - switch (assoc) { - case JP2_CDEF_YCBCR_Y: - return JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_YCBCR_Y); - break; - case JP2_CDEF_YCBCR_CB: - return JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_YCBCR_CB); - break; - case JP2_CDEF_YCBCR_CR: - return JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_YCBCR_CR); - break; - } - break; - case JAS_IMAGE_CS_GRAY: - switch (assoc) { - case JP2_CDEF_GRAY_Y: - return JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_GRAY_Y); - break; - } - break; -#if 0 - case JAS_IMAGE_CS_ICC: -#endif - default: - return JAS_IMAGE_CT_COLOR(assoc - 1); - break; - } - } - return JAS_IMAGE_CT_UNKNOWN; -} - - - -static int -jp2_getcs(jp2_colr_t *colr) { - - if (colr->method == JP2_COLR_ENUM) { - switch (colr->csid) { - case JP2_COLR_SRGB: - return JAS_IMAGE_CS_RGB; - break; - case JP2_COLR_SYCC: - return JAS_IMAGE_CS_YCBCR; - break; - case JP2_COLR_SGRAY: - return JAS_IMAGE_CS_GRAY; - break; - } - } - return JAS_IMAGE_CS_UNKNOWN; -} - - - -static int -fromiccpcs(int cs) { - - switch (cs) { - case ICC_CS_RGB: - return JAS_IMAGE_CS_RGB; - break; - case ICC_CS_YCBCR: - return JAS_IMAGE_CS_YCBCR; - break; - case ICC_CS_GRAY: - return JAS_IMAGE_CS_GRAY; - break; - } - return JAS_IMAGE_CS_UNKNOWN; -} - - - -jas_image_t * -jp2_decode(jas_stream_t *in, char *optstr) { - - jp2_box_t *box; - int found; - jas_image_t *image; - jp2_dec_t *dec; - bool samedtype; - int dtype; - int i; - jp2_cmap_t *cmapd; - jp2_pclr_t *pclrd; - int channo; - int newcmptno; - int_fast32_t *lutents; - jp2_cmapent_t *cmapent; - unsigned char *iccp; - int cs; - - dec = 0; - box = 0; - image = 0; - - if (!(dec = jp2_dec_create())) { - goto error; - } - - /* Get the first box. This should be a JP box. */ - if (!(box = jp2_box_get(in))) { - jas_eprintf("error: cannot get box\n"); - goto error; - } - if (box->type != JP2_BOX_JP) { - jas_eprintf("error: expecting signature box\n"); - goto error; - } - if (box->data.jp.magic != JP2_JP_MAGIC) { - jas_eprintf("incorrect magic number\n"); - goto error; - } - jp2_box_destroy(box); - box = 0; - - /* Get the second box. This should be a FTYP box. */ - if (!(box = jp2_box_get(in))) { - goto error; - } - if (box->type != JP2_BOX_FTYP) { - jas_eprintf("expecting file type box\n"); - goto error; - } - jp2_box_destroy(box); - box = 0; - - /* Get more boxes... */ - found = 0; - while ((box = jp2_box_get(in))) { - if (jas_getdbglevel() >= 1) { - fprintf(stderr, "box type %s\n", box->info->name); - } - switch (box->type) { - case JP2_BOX_JP2C: - found = 1; - break; - case JP2_BOX_IHDR: - if (!dec->ihdr) { - dec->ihdr = box; - box = 0; - } - break; - case JP2_BOX_BPCC: - if (!dec->bpcc) { - dec->bpcc = box; - box = 0; - } - break; - case JP2_BOX_CDEF: - if (!dec->cdef) { - dec->cdef = box; - box = 0; - } - break; - case JP2_BOX_PCLR: - if (!dec->pclr) { - dec->pclr = box; - box = 0; - } - break; - case JP2_BOX_CMAP: - if (!dec->cmap) { - dec->cmap = box; - box = 0; - } - break; - case JP2_BOX_COLR: - if (!dec->colr) { - dec->colr = box; - box = 0; - } - break; - } - if (box) { - jp2_box_destroy(box); - box = 0; - } - if (found) { - break; - } - } - - if (!found) { - jas_eprintf("error: no code stream found\n"); - goto error; - } - - if (!(dec->image = jpc_decode(in, optstr))) { - jas_eprintf("error: cannot decode code stream\n"); - goto error; - } - - /* An IHDR box must be present. */ - if (!dec->ihdr) { - jas_eprintf("error: missing IHDR box\n"); - goto error; - } - - /* Does the number of components indicated in the IHDR box match - the value specified in the code stream? */ - if (dec->ihdr->data.ihdr.numcmpts != jas_image_numcmpts(dec->image)) { - jas_eprintf("warning: number of components mismatch\n"); - } - - /* At least one component must be present. */ - if (!jas_image_numcmpts(dec->image)) { - jas_eprintf("error: no components\n"); - goto error; - } - - /* Determine if all components have the same data type. */ - samedtype = true; - dtype = jas_image_cmptdtype(dec->image, 0); - for (i = 1; i < jas_image_numcmpts(dec->image); ++i) { - if (jas_image_cmptdtype(dec->image, i) != dtype) { - samedtype = false; - break; - } - } - - /* Is the component data type indicated in the IHDR box consistent - with the data in the code stream? */ - if ((samedtype && dec->ihdr->data.ihdr.bpc != JP2_DTYPETOBPC(dtype)) || - (!samedtype && dec->ihdr->data.ihdr.bpc != JP2_IHDR_BPCNULL)) { - jas_eprintf("warning: component data type mismatch\n"); - } - - /* Can we handle the compression type? */ - if (dec->ihdr->data.ihdr.comptype != JP2_IHDR_COMPTYPE) { - jas_eprintf("error: not capable of this compression type\n"); - goto error; - } - - if (dec->bpcc) { - /* Is the number of components indicated in the BPCC box - consistent with the code stream data? */ - if (dec->bpcc->data.bpcc.numcmpts != jas_image_numcmpts( - dec->image)) { - jas_eprintf("warning: number of components mismatch\n"); - } - /* Is the component data type information indicated in the BPCC - box consistent with the code stream data? */ - if (!samedtype) { - for (i = 0; i < jas_image_numcmpts(dec->image); ++i) { - if (jas_image_cmptdtype(dec->image, i) != - JP2_BPCTODTYPE(dec->bpcc->data.bpcc.bpcs[i])) { - jas_eprintf("warning: component data type mismatch\n"); - } - } - } else { - jas_eprintf("warning: superfluous BPCC box\n"); - } - } - - /* A COLR box must be present. */ - if (!dec->colr) { - jas_eprintf("error: no COLR box\n"); - goto error; - } - - switch (dec->colr->data.colr.method) { - case JP2_COLR_ENUM: - jas_image_setcolorspace(dec->image, jp2_getcs(&dec->colr->data.colr)); - break; - case JP2_COLR_ICC: - if (dec->colr->data.colr.iccplen < 128) { - abort(); - } - iccp = dec->colr->data.colr.iccp; - cs = (iccp[16] << 24) | (iccp[17] << 16) | (iccp[18] << 8) | - iccp[19]; - if (jas_getdbglevel() > 1) - jas_eprintf("ICC Profile CS %08x\n", cs); - jas_image_setcolorspace(dec->image, fromiccpcs(cs)); - break; - } - - /* If a CMAP box is present, a PCLR box must also be present. */ - if (dec->cmap && !dec->pclr) { - jas_eprintf("warning: missing PCLR box or superfluous CMAP box\n"); - jp2_box_destroy(dec->cmap); - dec->cmap = 0; - } - - /* If a CMAP box is not present, a PCLR box must not be present. */ - if (!dec->cmap && dec->pclr) { - jas_eprintf("warning: missing CMAP box or superfluous PCLR box\n"); - jp2_box_destroy(dec->pclr); - dec->pclr = 0; - } - - /* Determine the number of channels (which is essentially the number - of components after any palette mappings have been applied). */ - dec->numchans = dec->cmap ? - dec->cmap->data.cmap.numchans : - jas_image_numcmpts(dec->image); - - /* Perform a basic sanity check on the CMAP box if present. */ - if (dec->cmap) { - for (i = 0; i < dec->numchans; ++i) { - /* Is the component number reasonable? */ - if (dec->cmap->data.cmap.ents[i].cmptno >= - jas_image_numcmpts(dec->image)) { - jas_eprintf("error: invalid component number in CMAP box\n"); - goto error; - } - /* Is the LUT index reasonable? */ - if (dec->cmap->data.cmap.ents[i].pcol >= - dec->pclr->data.pclr.numchans) { - jas_eprintf("error: invalid CMAP LUT index\n"); - goto error; - } - } - } - - /* Allocate space for the channel-number to component-number LUT. */ - dec->chantocmptlut = jas_malloc(dec->numchans * sizeof(uint_fast16_t)); - if (!dec->chantocmptlut) { - jas_eprintf("error: no memory\n"); - goto error; - } - - if (!dec->cmap) { - for (i = 0; i < dec->numchans; ++i) { - dec->chantocmptlut[i] = i; - } - } else { - cmapd = &dec->cmap->data.cmap; - pclrd = &dec->pclr->data.pclr; - for (channo = 0; channo < cmapd->numchans; ++channo) { - cmapent = &cmapd->ents[channo]; - if (cmapent->map == JP2_CMAP_DIRECT) { - dec->chantocmptlut[channo] = channo; - } else if (cmapent->map == JP2_CMAP_PALETTE) { - lutents = jas_malloc(pclrd->numlutents * sizeof(int_fast32_t)); - for (i = 0; i < pclrd->numlutents; ++i) { - lutents[i] = - pclrd->lutdata[cmapent->pcol + i * pclrd->numchans]; - } - newcmptno = jas_image_numcmpts(dec->image); - jas_image_depalettize( - dec->image, cmapent->cmptno, pclrd->numlutents, lutents, - JP2_BPCTODTYPE(pclrd->bpc[cmapent->pcol]), newcmptno); - dec->chantocmptlut[channo] = newcmptno; - jas_free(lutents); -#if 0 - if (dec->cdef) { - jp2_cdef_t * const cdefd = &dec->cdef->data.cdef; - cdefent = jp2_cdef_lookup(cdefd, channo); - if (!cdefent) { - abort(); - } - jas_image_setcmpttype( - dec->image, newcmptno, - jp2_getct(jas_image_colorspace(dec->image), - cdefent->type, cdefent->assoc)); - } else { - jas_image_setcmpttype( - dec->image, newcmptno, - jp2_getct(jas_image_colorspace(dec->image), - 0, - channo + 1)); - } -#endif - } - } - } - - /* Mark all components as being of unknown type. */ - - for (i = 0; i < jas_image_numcmpts(dec->image); ++i) { - jas_image_setcmpttype(dec->image, i, JAS_IMAGE_CT_UNKNOWN); - } - - /* Determine the type of each component. */ - if (dec->cdef) { - unsigned int i; - for (i = 0; i < dec->numchans; ++i) { - jas_image_setcmpttype( - dec->image, - dec->chantocmptlut[dec->cdef->data.cdef.ents[i].channo], - jp2_getct(jas_image_colorspace(dec->image), - dec->cdef->data.cdef.ents[i].type, - dec->cdef->data.cdef.ents[i].assoc)); - } - } else { - unsigned int i; - for (i = 0; i < dec->numchans; ++i) { - jas_image_setcmpttype(dec->image, dec->chantocmptlut[i], - jp2_getct(jas_image_colorspace(dec->image), 0, i + 1)); - } - } - - /* Delete any components that are not of interest. */ - for (i = jas_image_numcmpts(dec->image) - 1; i >= 0; --i) { - if (jas_image_cmpttype(dec->image, i) == JAS_IMAGE_CT_UNKNOWN) { - jas_image_delcmpt(dec->image, i); - } - } - - /* Ensure that some components survived. */ - if (!jas_image_numcmpts(dec->image)) { - jas_eprintf("error: no components\n"); - goto error; - } - - /* Prevent the image from being destroyed later. */ - image = dec->image; - dec->image = 0; - - jp2_dec_destroy(dec); - - return image; - -error: - if (box) { - jp2_box_destroy(box); - } - if (dec) { - jp2_dec_destroy(dec); - } - return 0; -} - - - -int -jp2_validate(jas_stream_t *in) { - - char buf[JP2_VALIDATELEN]; - int i; - int n; - - assert(JAS_STREAM_MAXPUTBACK >= JP2_VALIDATELEN); - - /* Read the validation data (i.e., the data used for detecting - the format). */ - if ((n = jas_stream_read(in, buf, JP2_VALIDATELEN)) < 0) { - return -1; - } - - /* Put the validation data back onto the stream, so that the - stream position will not be changed. */ - for (i = n - 1; i >= 0; --i) { - if (jas_stream_ungetc(in, buf[i]) == EOF) { - return -1; - } - } - - /* Did we read enough data? */ - if (n < JP2_VALIDATELEN) { - return -1; - } - - /* Is the box type correct? */ - if (((buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]) != - JP2_BOX_JP) - { - return -1; - } - - return 0; -} - - - diff --git a/converter/other/jpeg2000/libjasper/jp2/jp2_dec.h b/converter/other/jpeg2000/libjasper/jp2/jp2_dec.h deleted file mode 100644 index 300be10..0000000 --- a/converter/other/jpeg2000/libjasper/jp2/jp2_dec.h +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -#ifndef JP2_DEC_H -#define JP2_DEC_H - -#include "jasper/jas_image.h" -#include "jasper/jas_stream.h" -#include "jp2_cod.h" - -typedef struct { - - jp2_box_t *pclr; - jp2_box_t *cdef; - jp2_box_t *ihdr; - jp2_box_t *bpcc; - jp2_box_t *cmap; - jp2_box_t *colr; - jas_image_t *image; - uint_fast16_t numchans; - uint_fast16_t *chantocmptlut; - -} jp2_dec_t; - -#endif diff --git a/converter/other/jpeg2000/libjasper/jp2/jp2_enc.c b/converter/other/jpeg2000/libjasper/jp2/jp2_enc.c deleted file mode 100644 index 1253824..0000000 --- a/converter/other/jpeg2000/libjasper/jp2/jp2_enc.c +++ /dev/null @@ -1,414 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * JP2 Library - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include "jasper/jas_malloc.h" -#include "jasper/jas_image.h" -#include "jasper/jas_stream.h" - -#include "jp2_cod.h" - -static uint_fast32_t jp2_gettypeasoc(int colorspace, int ctype); - -/******************************************************************************\ -* Functions. -\******************************************************************************/ - -int jp2_encode(jas_image_t *image, jas_stream_t *out, char *optstr) -{ - jp2_box_t *box; - jp2_ftyp_t *ftyp; - jp2_ihdr_t *ihdr; - jas_stream_t *tmpstream; - int allcmptssame; - jp2_bpcc_t *bpcc; - long len; - uint_fast16_t cmptno; - jp2_colr_t *colr; - char buf[4096]; - uint_fast32_t overhead; - jp2_cdefchan_t *cdefchanent; - jp2_cdef_t *cdef; - int i; - uint_fast32_t typeasoc; - - box = 0; - tmpstream = 0; - - /* Output the signature box. */ - - if (!(box = jp2_box_create(JP2_BOX_JP))) { - goto error; - } - box->data.jp.magic = JP2_JP_MAGIC; - if (jp2_box_put(box, out)) { - goto error; - } - jp2_box_destroy(box); - box = 0; - - /* Output the file type box. */ - - if (!(box = jp2_box_create(JP2_BOX_FTYP))) { - goto error; - } - ftyp = &box->data.ftyp; - ftyp->majver = JP2_FTYP_MAJVER; - ftyp->minver = JP2_FTYP_MINVER; - ftyp->numcompatcodes = 1; - ftyp->compatcodes[0] = JP2_FTYP_COMPATCODE; - if (jp2_box_put(box, out)) { - goto error; - } - jp2_box_destroy(box); - box = 0; - - /* - * Generate the data portion of the JP2 header box. - * We cannot simply output the header for this box - * since we do not yet know the correct value for the length - * field. - */ - - if (!(tmpstream = jas_stream_memopen(0, 0))) { - goto error; - } - - /* Generate image header box. */ - - if (!(box = jp2_box_create(JP2_BOX_IHDR))) { - goto error; - } - ihdr = &box->data.ihdr; - ihdr->width = jas_image_width(image); - ihdr->height = jas_image_height(image); - ihdr->numcmpts = jas_image_numcmpts(image); - allcmptssame = 0; - ihdr->bpc = allcmptssame ? JP2_SPTOBPC(jas_image_cmptsgnd(image, 0), - jas_image_cmptprec(image, 0)) : JP2_IHDR_BPCNULL; - ihdr->comptype = JP2_IHDR_COMPTYPE; - ihdr->csunk = 0; - ihdr->ipr = 0; - if (jp2_box_put(box, tmpstream)) { - goto error; - } - jp2_box_destroy(box); - box = 0; - - /* Generate bits per component box. */ - - if (!allcmptssame) { - if (!(box = jp2_box_create(JP2_BOX_BPCC))) { - goto error; - } - bpcc = &box->data.bpcc; - bpcc->numcmpts = jas_image_numcmpts(image); - if (!(bpcc->bpcs = jas_malloc(bpcc->numcmpts * - sizeof(uint_fast8_t)))) { - goto error; - } - for (cmptno = 0; cmptno < bpcc->numcmpts; ++cmptno) { - bpcc->bpcs[cmptno] = JP2_SPTOBPC(jas_image_cmptsgnd(image, - cmptno), jas_image_cmptprec(image, cmptno)); - } - if (jp2_box_put(box, tmpstream)) { - goto error; - } - jp2_box_destroy(box); - box = 0; - } - - /* Generate color specification box. */ - - if (!(box = jp2_box_create(JP2_BOX_COLR))) { - goto error; - } - colr = &box->data.colr; - colr->method = JP2_COLR_ENUM; - colr->pri = JP2_COLR_PRI; - colr->approx = 0; - colr->csid = (jas_image_colorspace(image) == JAS_IMAGE_CS_RGB) ? JP2_COLR_SRGB : - JP2_COLR_SGRAY; - if (jp2_box_put(box, tmpstream)) { - goto error; - } - jp2_box_destroy(box); - box = 0; - - if (!(jas_image_colorspace(image) == JAS_IMAGE_CS_RGB && - jas_image_numcmpts(image) == 3 && - jas_image_getcmptbytype(image, 0) == - JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_RGB_R) && - jas_image_getcmptbytype(image, 1) == - JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_RGB_G) && - jas_image_getcmptbytype(image, 2) == - JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_RGB_B)) && - !(jas_image_colorspace(image) == JAS_IMAGE_CS_YCBCR && - jas_image_numcmpts(image) != 3 && - jas_image_getcmptbytype(image, 0) == - JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_YCBCR_Y) && - jas_image_getcmptbytype(image, 1) == - JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_YCBCR_CB) && - jas_image_getcmptbytype(image, 2) == - JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_YCBCR_CR)) && - !(jas_image_colorspace(image) == JAS_IMAGE_CS_GRAY && - jas_image_numcmpts(image) == 1 && - jas_image_getcmptbytype(image, 0) == - JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_GRAY_Y))) { - - if (!(box = jp2_box_create(JP2_BOX_CDEF))) { - goto error; - } - cdef = &box->data.cdef; - cdef->numchans = jas_image_numcmpts(image); - cdef->ents = jas_malloc(cdef->numchans * sizeof(jp2_cdefchan_t)); - for (i = 0; i < jas_image_numcmpts(image); ++i) { - cdefchanent = &cdef->ents[i]; - cdefchanent->channo = i; - typeasoc = jp2_gettypeasoc(jas_image_colorspace(image), jas_image_cmpttype(image, i)); - cdefchanent->type = typeasoc >> 16; - cdefchanent->assoc = typeasoc & 0x7fff; - } - jp2_box_destroy(box); - box = 0; - } - - /* Determine the total length of the JP2 header box. */ - - len = jas_stream_tell(tmpstream); - jas_stream_rewind(tmpstream); - - /* - * Output the JP2 header box and all of the boxes which it contains. - */ - - if (!(box = jp2_box_create(JP2_BOX_JP2H))) { - goto error; - } - box->len = len + JP2_BOX_HDRLEN; - if (jp2_box_put(box, out)) { - goto error; - } - jp2_box_destroy(box); - box = 0; - - if (jas_stream_copy(out, tmpstream, len)) { - goto error; - } - - jas_stream_close(tmpstream); - tmpstream = 0; - - /* - * Output the contiguous code stream box. - */ - - if (!(box = jp2_box_create(JP2_BOX_JP2C))) { - goto error; - } - box->len = 0; - if (jp2_box_put(box, out)) { - goto error; - } - jp2_box_destroy(box); - box = 0; - - /* Output the JPEG-2000 code stream. */ - - overhead = jas_stream_getrwcount(out); - sprintf(buf, "%s\n_jp2overhead=%lu\n", (optstr ? optstr : ""), - (unsigned long) overhead); - - if (jpc_encode(image, out, buf)) { - goto error; - } - - return 0; - abort(); - -error: - - if (box) { - jp2_box_destroy(box); - } - if (tmpstream) { - jas_stream_close(tmpstream); - } - return -1; -} - - -static uint_fast32_t jp2_gettypeasoc(int colorspace, int ctype) -{ - int type; - int asoc; - - if (ctype & JAS_IMAGE_CT_OPACITY) { - type = JP2_CDEF_TYPE_OPACITY; - asoc = JP2_CDEF_ASOC_ALL; - goto done; - } - - type = JP2_CDEF_TYPE_UNSPEC; - asoc = JP2_CDEF_ASOC_NONE; - switch (colorspace) { - case JAS_IMAGE_CS_RGB: - switch (JAS_IMAGE_CT_COLOR(ctype)) { - case JAS_IMAGE_CT_RGB_R: - type = JP2_CDEF_TYPE_COLOR; - asoc = JP2_CDEF_RGB_R; - break; - case JAS_IMAGE_CT_RGB_G: - type = JP2_CDEF_TYPE_COLOR; - asoc = JP2_CDEF_RGB_G; - break; - case JAS_IMAGE_CT_RGB_B: - type = JP2_CDEF_TYPE_COLOR; - asoc = JP2_CDEF_RGB_B; - break; - } - break; - case JAS_IMAGE_CS_YCBCR: - switch (JAS_IMAGE_CT_COLOR(ctype)) { - case JAS_IMAGE_CT_YCBCR_Y: - type = JP2_CDEF_TYPE_COLOR; - asoc = JP2_CDEF_YCBCR_Y; - break; - case JAS_IMAGE_CT_YCBCR_CB: - type = JP2_CDEF_TYPE_COLOR; - asoc = JP2_CDEF_YCBCR_CB; - break; - case JAS_IMAGE_CT_YCBCR_CR: - type = JP2_CDEF_TYPE_COLOR; - asoc = JP2_CDEF_YCBCR_CR; - break; - } - break; - case JAS_IMAGE_CS_GRAY: - type = JP2_CDEF_TYPE_COLOR; - asoc = JP2_CDEF_GRAY_Y; - break; - } - -done: - return (type << 16) | asoc; -} - diff --git a/converter/other/jpeg2000/libjasper/jpc/Makefile b/converter/other/jpeg2000/libjasper/jpc/Makefile deleted file mode 100644 index ffc4c64..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -ifeq ($(SRCDIR)x,x) - SRCDIR = $(CURDIR)/../../../../.. - BUILDDIR = $(SRCDIR) -endif -SUBDIR = converter/other/jpeg2000/libjasper/jpc -VPATH=.:$(SRCDIR)/$(SUBDIR) - -JASPERSRCDIR=$(SRCDIR)/$(SUBDIR)/.. - -include $(BUILDDIR)/config.mk - -LIB_OBJECTS = jpc_bs.o jpc_cs.o jpc_dec.o jpc_enc.o \ - jpc_math.o jpc_mct.o jpc_mqcod.o jpc_mqdec.o jpc_mqenc.o \ - jpc_qmfb.o jpc_tagtree.o jpc_t1cod.o jpc_t1dec.o jpc_t1enc.o \ - jpc_tsfb.o jpc_t2cod.o jpc_t2dec.o jpc_t2enc.o jpc_util.o - -MERGE_OBJECTS = - -all: partlist $(LIB_OBJECTS) - -include $(JASPERSRCDIR)/common.mk - diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_bs.c b/converter/other/jpeg2000/libjasper/jpc/jpc_bs.c deleted file mode 100644 index c66fcd9..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_bs.c +++ /dev/null @@ -1,474 +0,0 @@ -/* - * Copyright (c) 1999-2000, Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Bit Stream Class - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include -#include - -#include "jasper/jas_malloc.h" -#include "jasper/jas_math.h" -#include "jasper/jas_debug.h" - -#include "jpc_bs.h" - -/******************************************************************************\ -* Code for opening and closing bit streams. -\******************************************************************************/ - -/* Allocate a new bit stream. */ -static jpc_bitstream_t *jpc_bitstream_alloc() -{ - jpc_bitstream_t *bitstream; - - /* Allocate memory for the new bit stream object. */ - if (!(bitstream = jas_malloc(sizeof(jpc_bitstream_t)))) { - return 0; - } - /* Initialize all of the data members. */ - bitstream->stream_ = 0; - bitstream->cnt_ = 0; - bitstream->flags_ = 0; - bitstream->openmode_ = 0; - - return bitstream; -} - -/* Open a bit stream from a stream. */ -jpc_bitstream_t *jpc_bitstream_sopen(jas_stream_t *stream, const char *mode) -{ - jpc_bitstream_t *bitstream; - - if (!(bitstream = jpc_bitstream_alloc())) { - return 0; - } - - /* By default, do not close the underlying (character) stream, upon - the close of the bit stream. */ - bitstream->flags_ = JPC_BITSTREAM_NOCLOSE; - - bitstream->stream_ = stream; - bitstream->openmode_ = (mode[0] == 'w') ? JPC_BITSTREAM_WRITE : - JPC_BITSTREAM_READ; - - /* Mark the data buffer as empty. */ - bitstream->cnt_ = (bitstream->openmode_ == JPC_BITSTREAM_READ) ? 0 : 8; - bitstream->buf_ = 0; - - return bitstream; -} - -/* Close a bit stream. */ -int jpc_bitstream_close(jpc_bitstream_t *bitstream) -{ - int ret = 0; - - /* Align to the next byte boundary while considering the effects of - bit stuffing. */ - if (jpc_bitstream_align(bitstream)) { - ret = -1; - } - - /* If necessary, close the underlying (character) stream. */ - if (!(bitstream->flags_ & JPC_BITSTREAM_NOCLOSE) && bitstream->stream_) { - if (jas_stream_close(bitstream->stream_)) { - ret = -1; - } - bitstream->stream_ = 0; - } - - jas_free(bitstream); - return ret; -} - -/******************************************************************************\ -* Code for reading/writing from/to bit streams. -\******************************************************************************/ - -/* Get a bit from a bit stream. */ -int jpc_bitstream_getbit_func(jpc_bitstream_t *bitstream) -{ - int ret; - JAS_DBGLOG(1000, ("jpc_bitstream_getbit_func(%p)\n", bitstream)); - ret = jpc_bitstream_getbit_macro(bitstream); - JAS_DBGLOG(1000, ("jpc_bitstream_getbit_func -> %d\n", ret)); - return ret; -} - -/* Put a bit to a bit stream. */ -int jpc_bitstream_putbit_func(jpc_bitstream_t *bitstream, int b) -{ - int ret; - JAS_DBGLOG(1000, ("jpc_bitstream_putbit_func(%p, %d)\n", bitstream, b)); - ret = jpc_bitstream_putbit_macro(bitstream, b); - JAS_DBGLOG(1000, ("jpc_bitstream_putbit_func() -> %d\n", ret)); - return ret; -} - -/* Get one or more bits from a bit stream. */ -long jpc_bitstream_getbits(jpc_bitstream_t *bitstream, int n) -{ - long v; - int u; - - /* We can reliably get at most 31 bits since ISO/IEC 9899 only - guarantees that a long can represent values up to 2^31-1. */ - assert(n >= 0 && n < 32); - - /* Get the number of bits requested from the specified bit stream. */ - v = 0; - while (--n >= 0) { - if ((u = jpc_bitstream_getbit(bitstream)) < 0) { - return -1; - } - v = (v << 1) | u; - } - return v; -} - -/* Put one or more bits to a bit stream. */ -int jpc_bitstream_putbits(jpc_bitstream_t *bitstream, int n, long v) -{ - int m; - - /* We can reliably put at most 31 bits since ISO/IEC 9899 only - guarantees that a long can represent values up to 2^31-1. */ - assert(n >= 0 && n < 32); - /* Ensure that only the bits to be output are nonzero. */ - assert(!(v & (~JAS_ONES(n)))); - - /* Put the desired number of bits to the specified bit stream. */ - m = n - 1; - while (--n >= 0) { - if (jpc_bitstream_putbit(bitstream, (v >> m) & 1) == EOF) { - return EOF; - } - v <<= 1; - } - return 0; -} - -/******************************************************************************\ -* Code for buffer filling and flushing. -\******************************************************************************/ - -/* Fill the buffer for a bit stream. */ -int jpc_bitstream_fillbuf(jpc_bitstream_t *bitstream) -{ - int c; - /* Note: The count has already been decremented by the caller. */ - assert(bitstream->openmode_ & JPC_BITSTREAM_READ); - assert(bitstream->cnt_ <= 0); - - if (bitstream->flags_ & JPC_BITSTREAM_ERR) { - bitstream->cnt_ = 0; - return -1; - } - - if (bitstream->flags_ & JPC_BITSTREAM_EOF) { - bitstream->buf_ = 0x7f; - bitstream->cnt_ = 7; - return 1; - } - - bitstream->buf_ = (bitstream->buf_ << 8) & 0xffff; - if ((c = jas_stream_getc((bitstream)->stream_)) == EOF) { - bitstream->flags_ |= JPC_BITSTREAM_EOF; - return 1; - } - bitstream->cnt_ = (bitstream->buf_ == 0xff00) ? 6 : 7; - bitstream->buf_ |= c & ((1 << (bitstream->cnt_ + 1)) - 1); - return (bitstream->buf_ >> bitstream->cnt_) & 1; -} - - -/******************************************************************************\ -* Code related to flushing. -\******************************************************************************/ - -/* Does the bit stream need to be aligned to a byte boundary (considering - the effects of bit stuffing)? */ -int jpc_bitstream_needalign(jpc_bitstream_t *bitstream) -{ - if (bitstream->openmode_ & JPC_BITSTREAM_READ) { - /* The bit stream is open for reading. */ - /* If there are any bits buffered for reading, or the - previous byte forced a stuffed bit, alignment is - required. */ - if ((bitstream->cnt_ < 8 && bitstream->cnt_ > 0) || - ((bitstream->buf_ >> 8) & 0xff) == 0xff) { - return 1; - } - } else if (bitstream->openmode_ & JPC_BITSTREAM_WRITE) { - /* The bit stream is open for writing. */ - /* If there are any bits buffered for writing, or the - previous byte forced a stuffed bit, alignment is - required. */ - if ((bitstream->cnt_ < 8 && bitstream->cnt_ >= 0) || - ((bitstream->buf_ >> 8) & 0xff) == 0xff) { - return 1; - } - } else { - /* This should not happen. Famous last words, eh? :-) */ - assert(0); - return -1; - } - return 0; -} - -/* How many additional bytes would be output if we align the bit stream? */ -int jpc_bitstream_pending(jpc_bitstream_t *bitstream) -{ - if (bitstream->openmode_ & JPC_BITSTREAM_WRITE) { - /* The bit stream is being used for writing. */ -#if 1 - /* XXX - Is this really correct? Check someday... */ - if (bitstream->cnt_ < 8) { - return 1; - } -#else - if (bitstream->cnt_ < 8) { - if (((bitstream->buf_ >> 8) & 0xff) == 0xff) { - return 2; - } - return 1; - } -#endif - return 0; - } else { - /* This operation should not be invoked on a bit stream that - is being used for reading. */ - return -1; - } -} - -/* Align the bit stream to a byte boundary. */ -int jpc_bitstream_align(jpc_bitstream_t *bitstream) -{ - int ret; - if (bitstream->openmode_ & JPC_BITSTREAM_READ) { - ret = jpc_bitstream_inalign(bitstream, 0, 0); - } else if (bitstream->openmode_ & JPC_BITSTREAM_WRITE) { - ret = jpc_bitstream_outalign(bitstream, 0); - } - return ret; -} - -/* Align a bit stream in the input case. */ -int jpc_bitstream_inalign(jpc_bitstream_t *bitstream, int fillmask, - int filldata) -{ - int n; - int v; - int u; - int numfill; - int m; - - numfill = 7; - m = 0; - v = 0; - if (bitstream->cnt_ > 0) { - n = bitstream->cnt_; - } else if (!bitstream->cnt_) { - n = ((bitstream->buf_ & 0xff) == 0xff) ? 7 : 0; - } else { - n = 0; - } - if (n > 0) { - if ((u = jpc_bitstream_getbits(bitstream, n)) < 0) { - return -1; - } - m += n; - v = (v << n) | u; - } - if ((bitstream->buf_ & 0xff) == 0xff) { - if ((u = jpc_bitstream_getbits(bitstream, 7)) < 0) { - return -1; - } - v = (v << 7) | u; - m += 7; - } - if (m > numfill) { - v >>= m - numfill; - } else { - filldata >>= numfill - m; - fillmask >>= numfill - m; - } - if (((~(v ^ filldata)) & fillmask) != fillmask) { - /* The actual fill pattern does not match the expected one. */ - return 1; - } - - return 0; -} - -/* Align a bit stream in the output case. */ -int jpc_bitstream_outalign(jpc_bitstream_t *bitstream, int filldata) -{ - int n; - int v; - - /* Ensure that this bit stream is open for writing. */ - assert(bitstream->openmode_ & JPC_BITSTREAM_WRITE); - - /* Ensure that the first bit of fill data is zero. */ - /* Note: The first bit of fill data must be zero. If this were not - the case, the fill data itself could cause further bit stuffing to - be required (which would cause numerous complications). */ - assert(!(filldata & (~0x3f))); - - if (!bitstream->cnt_) { - if ((bitstream->buf_ & 0xff) == 0xff) { - n = 7; - v = filldata; - } else { - n = 0; - v = 0; - } - } else if (bitstream->cnt_ > 0 && bitstream->cnt_ < 8) { - n = bitstream->cnt_; - v = filldata >> (7 - n); - } else { - n = 0; - v = 0; - return 0; - } - - /* Write the appropriate fill data to the bit stream. */ - if (n > 0) { - if (jpc_bitstream_putbits(bitstream, n, v)) { - return -1; - } - } - if (bitstream->cnt_ < 8) { - assert(bitstream->cnt_ >= 0 && bitstream->cnt_ < 8); - assert((bitstream->buf_ & 0xff) != 0xff); - /* Force the pending byte of output to be written to the - underlying (character) stream. */ - if (jas_stream_putc(bitstream->stream_, bitstream->buf_ & 0xff) == EOF) { - return -1; - } - bitstream->cnt_ = 8; - bitstream->buf_ = (bitstream->buf_ << 8) & 0xffff; - } - - return 0; -} diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_bs.h b/converter/other/jpeg2000/libjasper/jpc/jpc_bs.h deleted file mode 100644 index edb0a2d..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_bs.h +++ /dev/null @@ -1,280 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Bit Stream Class - * - * $Id$ - */ - -#ifndef JPC_BS_H -#define JPC_BS_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include - -#include "jasper/jas_types.h" -#include "jasper/jas_stream.h" - -/******************************************************************************\ -* Constants. -\******************************************************************************/ - -/* - * Bit stream open mode flags. - */ - -/* Bit stream open for reading. */ -#define JPC_BITSTREAM_READ 0x01 -/* Bit stream open for writing. */ -#define JPC_BITSTREAM_WRITE 0x02 - -/* - * Bit stream flags. - */ - -/* Do not close underlying character stream. */ -#define JPC_BITSTREAM_NOCLOSE 0x01 -/* End of file has been reached while reading. */ -#define JPC_BITSTREAM_EOF 0x02 -/* An I/O error has occurred. */ -#define JPC_BITSTREAM_ERR 0x04 - -/******************************************************************************\ -* Types. -\******************************************************************************/ - -/* Bit stream class. */ - -typedef struct { - - /* Some miscellaneous flags. */ - int flags_; - - /* The input/output buffer. */ - uint_fast16_t buf_; - - /* The number of bits remaining in the byte being read/written. */ - int cnt_; - - /* The underlying stream associated with this bit stream. */ - jas_stream_t *stream_; - - /* The mode in which this bit stream was opened. */ - int openmode_; - -} jpc_bitstream_t; - -/******************************************************************************\ -* Functions/macros for opening and closing bit streams.. -\******************************************************************************/ - -/* Open a stream as a bit stream. */ -jpc_bitstream_t *jpc_bitstream_sopen(jas_stream_t *stream, const char *mode); - -/* Close a bit stream. */ -int jpc_bitstream_close(jpc_bitstream_t *bitstream); - -/******************************************************************************\ -* Functions/macros for reading from and writing to bit streams.. -\******************************************************************************/ - -/* Read a bit from a bit stream. */ -#if defined(DEBUG) -#define jpc_bitstream_getbit(bitstream) \ - jpc_bitstream_getbit_func(bitstream) -#else -#define jpc_bitstream_getbit(bitstream) \ - jpc_bitstream_getbit_macro(bitstream) -#endif - -/* Write a bit to a bit stream. */ -#if defined(DEBUG) -#define jpc_bitstream_putbit(bitstream, v) \ - jpc_bitstream_putbit_func(bitstream, v) -#else -#define jpc_bitstream_putbit(bitstream, v) \ - jpc_bitstream_putbit_macro(bitstream, v) -#endif - -/* Read one or more bits from a bit stream. */ -long jpc_bitstream_getbits(jpc_bitstream_t *bitstream, int n); - -/* Write one or more bits to a bit stream. */ -int jpc_bitstream_putbits(jpc_bitstream_t *bitstream, int n, long v); - -/******************************************************************************\ -* Functions/macros for flushing and aligning bit streams. -\******************************************************************************/ - -/* Align the current position within the bit stream to the next byte - boundary. */ -int jpc_bitstream_align(jpc_bitstream_t *bitstream); - -/* Align the current position in the bit stream with the next byte boundary, - ensuring that certain bits consumed in the process match a particular - pattern. */ -int jpc_bitstream_inalign(jpc_bitstream_t *bitstream, int fillmask, - int filldata); - -/* Align the current position in the bit stream with the next byte boundary, - writing bits from the specified pattern (if necessary) in the process. */ -int jpc_bitstream_outalign(jpc_bitstream_t *bitstream, int filldata); - -/* Check if a bit stream needs alignment. */ -int jpc_bitstream_needalign(jpc_bitstream_t *bitstream); - -/* How many additional bytes would be output if the bit stream was aligned? */ -int jpc_bitstream_pending(jpc_bitstream_t *bitstream); - -/******************************************************************************\ -* Functions/macros for querying state information for bit streams. -\******************************************************************************/ - -/* Has EOF been encountered on a bit stream? */ -#define jpc_bitstream_eof(bitstream) \ - ((bitstream)->flags_ & JPC_BITSTREAM_EOF) - -/******************************************************************************\ -* Internals. -\******************************************************************************/ - -/* DO NOT DIRECTLY INVOKE ANY OF THE MACROS OR FUNCTIONS BELOW. THEY ARE - FOR INTERNAL USE ONLY. */ - -int jpc_bitstream_getbit_func(jpc_bitstream_t *bitstream); - -int jpc_bitstream_putbit_func(jpc_bitstream_t *bitstream, int v); - -int jpc_bitstream_fillbuf(jpc_bitstream_t *bitstream); - -#define jpc_bitstream_getbit_macro(bitstream) \ - (assert((bitstream)->openmode_ & JPC_BITSTREAM_READ), \ - (--(bitstream)->cnt_ >= 0) ? \ - (((bitstream)->buf_ >> (bitstream)->cnt_) & 1) : \ - jpc_bitstream_fillbuf(bitstream)) - -#define jpc_bitstream_putbit_macro(bitstream, bit) \ - (assert((bitstream)->openmode_ & JPC_BITSTREAM_WRITE), \ - (--(bitstream)->cnt_ < 0) ? \ - ((bitstream)->buf_ = ((bitstream)->buf_ << 8) & 0xffff, \ - (bitstream)->cnt_ = ((bitstream)->buf_ == 0xff00) ? 6 : 7, \ - (bitstream)->buf_ |= ((bit) & 1) << (bitstream)->cnt_, \ - (jas_stream_putc((bitstream)->stream_, (bitstream)->buf_ >> 8) == EOF) \ - ? (EOF) : ((bit) & 1)) : \ - ((bitstream)->buf_ |= ((bit) & 1) << (bitstream)->cnt_, \ - (bit) & 1)) - -#endif diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_cod.h b/converter/other/jpeg2000/libjasper/jpc/jpc_cod.h deleted file mode 100644 index 9b3ddbe..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_cod.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * $Id$ - */ - -#ifndef JPC_COD_H -#define JPC_COD_H - -/******************************************************************************\ -* Constants. -\******************************************************************************/ - -/* The nominal word size used by this implementation. */ -#define JPC_PREC 32 - -#endif diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_cs.c b/converter/other/jpeg2000/libjasper/jpc/jpc_cs.c deleted file mode 100644 index 559f36c..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_cs.c +++ /dev/null @@ -1,1614 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * JPEG-2000 Code Stream Library - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include -#include - -#include "jasper/jas_malloc.h" -#include "jasper/jas_debug.h" - -#include "jpc_cs.h" - -/******************************************************************************\ -* Types. -\******************************************************************************/ - -/* Marker segment table entry. */ -typedef struct { - int id; - const char *name; - jpc_msops_t ops; -} jpc_mstabent_t; - -/******************************************************************************\ -* Local prototypes. -\******************************************************************************/ - -static jpc_mstabent_t *jpc_mstab_lookup(int id); - -static int jpc_poc_dumpparms(jpc_ms_t *ms, FILE *out); -static int jpc_poc_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out); -static int jpc_poc_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in); -static void jpc_poc_destroyparms(jpc_ms_t *ms); - -static int jpc_unk_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in); -static int jpc_sot_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in); -static int jpc_siz_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in); -static int jpc_cod_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in); -static int jpc_coc_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in); -static int jpc_qcd_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in); -static int jpc_qcc_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in); -static int jpc_rgn_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in); -static int jpc_sop_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in); -static int jpc_ppm_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in); -static int jpc_ppt_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in); -static int jpc_crg_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in); -static int jpc_com_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in); - -static int jpc_sot_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out); -static int jpc_siz_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out); -static int jpc_cod_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out); -static int jpc_coc_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out); -static int jpc_qcd_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out); -static int jpc_qcc_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out); -static int jpc_rgn_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out); -static int jpc_unk_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out); -static int jpc_sop_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out); -static int jpc_ppm_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out); -static int jpc_ppt_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out); -static int jpc_crg_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out); -static int jpc_com_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out); - -static int jpc_sot_dumpparms(jpc_ms_t *ms, FILE *out); -static int jpc_siz_dumpparms(jpc_ms_t *ms, FILE *out); -static int jpc_cod_dumpparms(jpc_ms_t *ms, FILE *out); -static int jpc_coc_dumpparms(jpc_ms_t *ms, FILE *out); -static int jpc_qcd_dumpparms(jpc_ms_t *ms, FILE *out); -static int jpc_qcc_dumpparms(jpc_ms_t *ms, FILE *out); -static int jpc_rgn_dumpparms(jpc_ms_t *ms, FILE *out); -static int jpc_unk_dumpparms(jpc_ms_t *ms, FILE *out); -static int jpc_sop_dumpparms(jpc_ms_t *ms, FILE *out); -static int jpc_ppm_dumpparms(jpc_ms_t *ms, FILE *out); -static int jpc_ppt_dumpparms(jpc_ms_t *ms, FILE *out); -static int jpc_crg_dumpparms(jpc_ms_t *ms, FILE *out); -static int jpc_com_dumpparms(jpc_ms_t *ms, FILE *out); - -static void jpc_siz_destroyparms(jpc_ms_t *ms); -static void jpc_qcd_destroyparms(jpc_ms_t *ms); -static void jpc_qcc_destroyparms(jpc_ms_t *ms); -static void jpc_cod_destroyparms(jpc_ms_t *ms); -static void jpc_coc_destroyparms(jpc_ms_t *ms); -static void jpc_unk_destroyparms(jpc_ms_t *ms); -static void jpc_ppm_destroyparms(jpc_ms_t *ms); -static void jpc_ppt_destroyparms(jpc_ms_t *ms); -static void jpc_crg_destroyparms(jpc_ms_t *ms); -static void jpc_com_destroyparms(jpc_ms_t *ms); - -static void jpc_qcx_destroycompparms(jpc_qcxcp_t *compparms); -static int jpc_qcx_getcompparms(jpc_qcxcp_t *compparms, jpc_cstate_t *cstate, - jas_stream_t *in, uint_fast16_t len); -static int jpc_qcx_putcompparms(jpc_qcxcp_t *compparms, jpc_cstate_t *cstate, - jas_stream_t *out); -static void jpc_cox_destroycompparms(jpc_coxcp_t *compparms); -static int jpc_cox_getcompparms(jpc_ms_t *ms, jpc_cstate_t *cstate, - jas_stream_t *in, int prtflag, jpc_coxcp_t *compparms); -static int jpc_cox_putcompparms(jpc_ms_t *ms, jpc_cstate_t *cstate, - jas_stream_t *out, int prtflag, jpc_coxcp_t *compparms); - -/******************************************************************************\ -* Global data. -\******************************************************************************/ - -static jpc_mstabent_t jpc_mstab[] = { - {JPC_MS_SOC, "SOC", {0, 0, 0, 0}}, - {JPC_MS_SOT, "SOT", {0, jpc_sot_getparms, jpc_sot_putparms, - jpc_sot_dumpparms}}, - {JPC_MS_SOD, "SOD", {0, 0, 0, 0}}, - {JPC_MS_EOC, "EOC", {0, 0, 0, 0}}, - {JPC_MS_SIZ, "SIZ", {jpc_siz_destroyparms, jpc_siz_getparms, - jpc_siz_putparms, jpc_siz_dumpparms}}, - {JPC_MS_COD, "COD", {jpc_cod_destroyparms, jpc_cod_getparms, - jpc_cod_putparms, jpc_cod_dumpparms}}, - {JPC_MS_COC, "COC", {jpc_coc_destroyparms, jpc_coc_getparms, - jpc_coc_putparms, jpc_coc_dumpparms}}, - {JPC_MS_RGN, "RGN", {0, jpc_rgn_getparms, jpc_rgn_putparms, - jpc_rgn_dumpparms}}, - {JPC_MS_QCD, "QCD", {jpc_qcd_destroyparms, jpc_qcd_getparms, - jpc_qcd_putparms, jpc_qcd_dumpparms}}, - {JPC_MS_QCC, "QCC", {jpc_qcc_destroyparms, jpc_qcc_getparms, - jpc_qcc_putparms, jpc_qcc_dumpparms}}, - {JPC_MS_POC, "POC", {jpc_poc_destroyparms, jpc_poc_getparms, - jpc_poc_putparms, jpc_poc_dumpparms}}, - {JPC_MS_TLM, "TLM", {0, jpc_unk_getparms, jpc_unk_putparms, 0}}, - {JPC_MS_PLM, "PLM", {0, jpc_unk_getparms, jpc_unk_putparms, 0}}, - {JPC_MS_PPM, "PPM", {jpc_ppm_destroyparms, jpc_ppm_getparms, - jpc_ppm_putparms, jpc_ppm_dumpparms}}, - {JPC_MS_PPT, "PPT", {jpc_ppt_destroyparms, jpc_ppt_getparms, - jpc_ppt_putparms, jpc_ppt_dumpparms}}, - {JPC_MS_SOP, "SOP", {0, jpc_sop_getparms, jpc_sop_putparms, - jpc_sop_dumpparms}}, - {JPC_MS_EPH, "EPH", {0, 0, 0, 0}}, - {JPC_MS_CRG, "CRG", {0, jpc_crg_getparms, jpc_crg_putparms, - jpc_crg_dumpparms}}, - {JPC_MS_COM, "COM", {jpc_com_destroyparms, jpc_com_getparms, - jpc_com_putparms, jpc_com_dumpparms}}, - {-1, "UNKNOWN", {jpc_unk_destroyparms, jpc_unk_getparms, - jpc_unk_putparms, jpc_unk_dumpparms}} -}; - -/******************************************************************************\ -* Code stream manipulation functions. -\******************************************************************************/ - -/* Create a code stream state object. */ -jpc_cstate_t *jpc_cstate_create() -{ - jpc_cstate_t *cstate; - if (!(cstate = jas_malloc(sizeof(jpc_cstate_t)))) { - return 0; - } - cstate->numcomps = 0; - return cstate; -} - -/* Destroy a code stream state object. */ -void jpc_cstate_destroy(jpc_cstate_t *cstate) -{ - jas_free(cstate); -} - -/* Read a marker segment from a stream. */ -jpc_ms_t *jpc_getms(jas_stream_t *in, jpc_cstate_t *cstate) -{ - jpc_ms_t *ms; - jpc_mstabent_t *mstabent; - jas_stream_t *tmpstream; - - if (!(ms = jpc_ms_create(0))) { - return 0; - } - - /* Get the marker type. */ - if (jpc_getuint16(in, &ms->id) || ms->id < JPC_MS_MIN || - ms->id > JPC_MS_MAX) { - jpc_ms_destroy(ms); - return 0; - } - - mstabent = jpc_mstab_lookup(ms->id); - ms->ops = &mstabent->ops; - - /* Get the marker segment length and parameters if present. */ - /* Note: It is tacitly assumed that a marker segment cannot have - parameters unless it has a length field. That is, there cannot - be a parameters field without a length field and vice versa. */ - if (JPC_MS_HASPARMS(ms->id)) { - /* Get the length of the marker segment. */ - if (jpc_getuint16(in, &ms->len) || ms->len < 3) { - jpc_ms_destroy(ms); - return 0; - } - /* Calculate the length of the marker segment parameters. */ - ms->len -= 2; - /* Create and prepare a temporary memory stream from which to - read the marker segment parameters. */ - /* Note: This approach provides a simple way of ensuring that - we never read beyond the end of the marker segment (even if - the marker segment length is errantly set too small). */ - if (!(tmpstream = jas_stream_memopen(0, 0))) { - jpc_ms_destroy(ms); - return 0; - } - if (jas_stream_copy(tmpstream, in, ms->len) || - jas_stream_seek(tmpstream, 0, SEEK_SET) < 0) { - jas_stream_close(tmpstream); - jpc_ms_destroy(ms); - return 0; - } - /* Get the marker segment parameters. */ - if ((*ms->ops->getparms)(ms, cstate, tmpstream)) { - ms->ops = 0; - jpc_ms_destroy(ms); - jas_stream_close(tmpstream); - return 0; - } - - if (jas_getdbglevel() > 0) { - jpc_ms_dump(ms, stderr); - } - - if (jas_stream_tell(tmpstream) != ms->len) { - fprintf(stderr, - "warning: trailing garbage in marker segment (%ld bytes)\n", - ms->len - jas_stream_tell(tmpstream)); - } - - /* Close the temporary stream. */ - jas_stream_close(tmpstream); - - } else { - /* There are no marker segment parameters. */ - ms->len = 0; - - if (jas_getdbglevel() > 0) { - jpc_ms_dump(ms, stderr); - } - } - - /* Update the code stream state information based on the type of - marker segment read. */ - /* Note: This is a bit of a hack, but I'm not going to define another - type of virtual function for this one special case. */ - if (ms->id == JPC_MS_SIZ) { - cstate->numcomps = ms->parms.siz.numcomps; - } - - return ms; -} - -/* Write a marker segment to a stream. */ -int jpc_putms(jas_stream_t *out, jpc_cstate_t *cstate, jpc_ms_t *ms) -{ - jas_stream_t *tmpstream; - int len; - - /* Output the marker segment type. */ - if (jpc_putuint16(out, ms->id)) { - return -1; - } - - /* Output the marker segment length and parameters if necessary. */ - if (ms->ops->putparms) { - /* Create a temporary stream in which to buffer the - parameter data. */ - if (!(tmpstream = jas_stream_memopen(0, 0))) { - return -1; - } - if ((*ms->ops->putparms)(ms, cstate, tmpstream)) { - jas_stream_close(tmpstream); - return -1; - } - /* Get the number of bytes of parameter data written. */ - if ((len = jas_stream_tell(tmpstream)) < 0) { - jas_stream_close(tmpstream); - return -1; - } - ms->len = len; - /* Write the marker segment length and parameter data to - the output stream. */ - if (jas_stream_seek(tmpstream, 0, SEEK_SET) < 0 || - jpc_putuint16(out, ms->len + 2) || - jas_stream_copy(out, tmpstream, ms->len) < 0) { - jas_stream_close(tmpstream); - return -1; - } - /* Close the temporary stream. */ - jas_stream_close(tmpstream); - } - - /* This is a bit of a hack, but I'm not going to define another - type of virtual function for this one special case. */ - if (ms->id == JPC_MS_SIZ) { - cstate->numcomps = ms->parms.siz.numcomps; - } - - if (jas_getdbglevel() > 0) { - jpc_ms_dump(ms, stderr); - } - - return 0; -} - -/******************************************************************************\ -* Marker segment operations. -\******************************************************************************/ - -/* Create a marker segment of the specified type. */ -jpc_ms_t *jpc_ms_create(int type) -{ - jpc_ms_t *ms; - jpc_mstabent_t *mstabent; - - if (!(ms = jas_malloc(sizeof(jpc_ms_t)))) { - return 0; - } - ms->id = type; - ms->len = 0; - mstabent = jpc_mstab_lookup(ms->id); - ms->ops = &mstabent->ops; - memset(&ms->parms, 0, sizeof(jpc_msparms_t)); - return ms; -} - -/* Destroy a marker segment. */ -void jpc_ms_destroy(jpc_ms_t *ms) -{ - if (ms->ops && ms->ops->destroyparms) { - (*ms->ops->destroyparms)(ms); - } - jas_free(ms); -} - -/* Dump a marker segment to a stream for debugging. */ -void jpc_ms_dump(jpc_ms_t *ms, FILE *out) -{ - jpc_mstabent_t *mstabent; - mstabent = jpc_mstab_lookup(ms->id); - fprintf(out, "type = 0x%04x (%s);", - (unsigned int)ms->id, mstabent->name); - if (JPC_MS_HASPARMS(ms->id)) { - fprintf(out, " len = %d;", (int)ms->len + 2); - if (ms->ops->dumpparms) { - (*ms->ops->dumpparms)(ms, out); - } else { - fprintf(out, "\n"); - } - } else { - fprintf(out, "\n"); - } -} - -/******************************************************************************\ -* SOT marker segment operations. -\******************************************************************************/ - -static int jpc_sot_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in) -{ - jpc_sot_t *sot = &ms->parms.sot; - if (jpc_getuint16(in, &sot->tileno) || - jpc_getuint32(in, &sot->len) || - jpc_getuint8(in, &sot->partno) || - jpc_getuint8(in, &sot->numparts)) { - return -1; - } - if (jas_stream_eof(in)) { - return -1; - } - return 0; -} - -static int jpc_sot_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out) -{ - jpc_sot_t *sot = &ms->parms.sot; - if (jpc_putuint16(out, sot->tileno) || - jpc_putuint32(out, sot->len) || - jpc_putuint8(out, sot->partno) || - jpc_putuint8(out, sot->numparts)) { - return -1; - } - return 0; -} - -static int jpc_sot_dumpparms(jpc_ms_t *ms, FILE *out) -{ - jpc_sot_t *sot = &ms->parms.sot; - fprintf(out, "tileno = %d; len = %d; partno = %d; numparts = %d\n", - (int)sot->tileno, (int)sot->len, sot->partno, sot->numparts); - return 0; -} - -/******************************************************************************\ -* SIZ marker segment operations. -\******************************************************************************/ - -static void jpc_siz_destroyparms(jpc_ms_t *ms) -{ - jpc_siz_t *siz = &ms->parms.siz; - if (siz->comps) { - jas_free(siz->comps); - } -} - -static int jpc_siz_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in) -{ - jpc_siz_t *siz = &ms->parms.siz; - int i; - uint_fast8_t tmp; - if (jpc_getuint16(in, &siz->caps) || - jpc_getuint32(in, &siz->width) || - jpc_getuint32(in, &siz->height) || - jpc_getuint32(in, &siz->xoff) || - jpc_getuint32(in, &siz->yoff) || - jpc_getuint32(in, &siz->tilewidth) || - jpc_getuint32(in, &siz->tileheight) || - jpc_getuint32(in, &siz->tilexoff) || - jpc_getuint32(in, &siz->tileyoff) || - jpc_getuint16(in, &siz->numcomps)) { - return -1; - } - if (!siz->width || !siz->height || !siz->tilewidth || - !siz->tileheight || !siz->numcomps) { - return -1; - } - if (!(siz->comps = jas_malloc(siz->numcomps * sizeof(jpc_sizcomp_t)))) { - return -1; - } - for (i = 0; i < siz->numcomps; ++i) { - if (jpc_getuint8(in, &tmp) || - jpc_getuint8(in, &siz->comps[i].hsamp) || - jpc_getuint8(in, &siz->comps[i].vsamp)) { - jas_free(siz->comps); - return -1; - } - siz->comps[i].sgnd = (tmp >> 7) & 1; - siz->comps[i].prec = (tmp & 0x7f) + 1; - } - if (jas_stream_eof(in)) { - jas_free(siz->comps); - return -1; - } - return 0; -} - -static int jpc_siz_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out) -{ - jpc_siz_t *siz = &ms->parms.siz; - int i; - assert(siz->width && siz->height && siz->tilewidth && - siz->tileheight && siz->numcomps); - if (jpc_putuint16(out, siz->caps) || - jpc_putuint32(out, siz->width) || - jpc_putuint32(out, siz->height) || - jpc_putuint32(out, siz->xoff) || - jpc_putuint32(out, siz->yoff) || - jpc_putuint32(out, siz->tilewidth) || - jpc_putuint32(out, siz->tileheight) || - jpc_putuint32(out, siz->tilexoff) || - jpc_putuint32(out, siz->tileyoff) || - jpc_putuint16(out, siz->numcomps)) { - return -1; - } - for (i = 0; i < siz->numcomps; ++i) { - if (jpc_putuint8(out, ((siz->comps[i].sgnd & 1) << 7) | - ((siz->comps[i].prec - 1) & 0x7f)) || - jpc_putuint8(out, siz->comps[i].hsamp) || - jpc_putuint8(out, siz->comps[i].vsamp)) { - return -1; - } - } - return 0; -} - -static int jpc_siz_dumpparms(jpc_ms_t *ms, FILE *out) -{ - jpc_siz_t *siz = &ms->parms.siz; - int i; - fprintf(out, "caps = 0x%02x;\n", (unsigned int)siz->caps); - fprintf(out, "width = %d; height = %d; xoff = %d; yoff = %d;\n", - (int)siz->width, (int)siz->height, (int)siz->xoff, (int)siz->yoff); - fprintf(out, "tilewidth = %d; tileheight = %d; tilexoff = %d; " - "tileyoff = %d;\n", - (int)siz->tilewidth, (int)siz->tileheight, - (int)siz->tilexoff, (int)siz->tileyoff); - for (i = 0; i < siz->numcomps; ++i) { - fprintf(out, "prec[%d] = %d; sgnd[%d] = %d; hsamp[%d] = %d; " - "vsamp[%d] = %d\n", i, siz->comps[i].prec, i, - siz->comps[i].sgnd, i, siz->comps[i].hsamp, i, - siz->comps[i].vsamp); - } - return 0; -} - -/*****************************************************************************\ -* COD marker segment operations. -\*****************************************************************************/ - -static void jpc_cod_destroyparms(jpc_ms_t *ms) -{ - jpc_cod_t *cod = &ms->parms.cod; - jpc_cox_destroycompparms(&cod->compparms); -} - -static int jpc_cod_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in) -{ - jpc_cod_t *cod = &ms->parms.cod; - if (jpc_getuint8(in, &cod->csty)) { - return -1; - } - if (jpc_getuint8(in, &cod->prg) || - jpc_getuint16(in, &cod->numlyrs) || - jpc_getuint8(in, &cod->mctrans)) { - return -1; - } - if (jpc_cox_getcompparms(ms, cstate, in, - (cod->csty & JPC_COX_PRT) != 0, &cod->compparms)) { - return -1; - } - if (jas_stream_eof(in)) { - jpc_cod_destroyparms(ms); - return -1; - } - return 0; -} - -static int jpc_cod_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out) -{ - jpc_cod_t *cod = &ms->parms.cod; - assert(cod->numlyrs > 0 && cod->compparms.numdlvls <= 32); - assert(cod->compparms.numdlvls == cod->compparms.numrlvls - 1); - if (jpc_putuint8(out, cod->compparms.csty) || - jpc_putuint8(out, cod->prg) || - jpc_putuint16(out, cod->numlyrs) || - jpc_putuint8(out, cod->mctrans)) { - return -1; - } - if (jpc_cox_putcompparms(ms, cstate, out, - (cod->csty & JPC_COX_PRT) != 0, &cod->compparms)) { - return -1; - } - return 0; -} - -static int jpc_cod_dumpparms(jpc_ms_t *ms, FILE *out) -{ - jpc_cod_t *cod = &ms->parms.cod; - int i; - fprintf(out, "csty = 0x%02x;\n", cod->compparms.csty); - fprintf(out, "numdlvls = %d; qmfbid = %d; mctrans = %d\n", - cod->compparms.numdlvls, cod->compparms.qmfbid, cod->mctrans); - fprintf(out, "prg = %d; numlyrs = %d;\n", - cod->prg, (int)cod->numlyrs); - fprintf(out, "cblkwidthval = %d; cblkheightval = %d; " - "cblksty = 0x%02x;\n", cod->compparms.cblkwidthval, cod->compparms.cblkheightval, - cod->compparms.cblksty); - if (cod->csty & JPC_COX_PRT) { - for (i = 0; i < cod->compparms.numrlvls; ++i) { - fprintf(stderr, "prcwidth[%d] = %d, prcheight[%d] = %d\n", - i, cod->compparms.rlvls[i].parwidthval, - i, cod->compparms.rlvls[i].parheightval); - } - } - return 0; -} - -/*****************************************************************************\ -* COC marker segment operations. -\*****************************************************************************/ - -static void jpc_coc_destroyparms(jpc_ms_t *ms) -{ - jpc_coc_t *coc = &ms->parms.coc; - jpc_cox_destroycompparms(&coc->compparms); -} - -static int jpc_coc_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in) -{ - jpc_coc_t *coc = &ms->parms.coc; - uint_fast8_t tmp; - if (cstate->numcomps <= 256) { - if (jpc_getuint8(in, &tmp)) { - return -1; - } - coc->compno = tmp; - } else { - if (jpc_getuint16(in, &coc->compno)) { - return -1; - } - } - if (jpc_getuint8(in, &coc->compparms.csty)) { - return -1; - } - if (jpc_cox_getcompparms(ms, cstate, in, - (coc->compparms.csty & JPC_COX_PRT) != 0, &coc->compparms)) { - return -1; - } - if (jas_stream_eof(in)) { - return -1; - } - return 0; -} - -static int jpc_coc_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out) -{ - jpc_coc_t *coc = &ms->parms.coc; - assert(coc->compparms.numdlvls <= 32); - if (cstate->numcomps <= 256) { - if (jpc_putuint8(out, coc->compno)) { - return -1; - } - } else { - if (jpc_putuint16(out, coc->compno)) { - return -1; - } - } - if (jpc_putuint8(out, coc->compparms.csty)) { - return -1; - } - if (jpc_cox_putcompparms(ms, cstate, out, - (coc->compparms.csty & JPC_COX_PRT) != 0, &coc->compparms)) { - return -1; - } - return 0; -} - -static int jpc_coc_dumpparms(jpc_ms_t *ms, FILE *out) -{ - jpc_coc_t *coc = &ms->parms.coc; - fprintf(out, "compno = %d; csty = 0x%02x; numdlvls = %d;\n", - (int)coc->compno, coc->compparms.csty, coc->compparms.numdlvls); - fprintf(out, "cblkwidthval = %d; cblkheightval = %d; " - "cblksty = 0x%02x; qmfbid = %d;\n", coc->compparms.cblkwidthval, - coc->compparms.cblkheightval, coc->compparms.cblksty, - coc->compparms.qmfbid); - return 0; -} -/******************************************************************************\ -* COD/COC marker segment operation helper functions. -\******************************************************************************/ - -static void jpc_cox_destroycompparms(jpc_coxcp_t *compparms) -{ -} - -static int jpc_cox_getcompparms(jpc_ms_t *ms, jpc_cstate_t *cstate, - jas_stream_t *in, int prtflag, jpc_coxcp_t *compparms) -{ - uint_fast8_t tmp; - int i; - if (jpc_getuint8(in, &compparms->numdlvls) || - jpc_getuint8(in, &compparms->cblkwidthval) || - jpc_getuint8(in, &compparms->cblkheightval) || - jpc_getuint8(in, &compparms->cblksty) || - jpc_getuint8(in, &compparms->qmfbid)) { - return -1; - } - compparms->numrlvls = compparms->numdlvls + 1; - if (prtflag) { - for (i = 0; i < compparms->numrlvls; ++i) { - if (jpc_getuint8(in, &tmp)) { - jpc_cox_destroycompparms(compparms); - return -1; - } - compparms->rlvls[i].parwidthval = tmp & 0xf; - compparms->rlvls[i].parheightval = (tmp >> 4) & 0xf; - } -/* Sigh. This bit should be in the same field in both COC and COD mrk segs. */ -compparms->csty |= JPC_COX_PRT; - } else { - } - if (jas_stream_eof(in)) { - jpc_cox_destroycompparms(compparms); - return -1; - } - return 0; -} - -static int jpc_cox_putcompparms(jpc_ms_t *ms, jpc_cstate_t *cstate, - jas_stream_t *out, int prtflag, jpc_coxcp_t *compparms) -{ - int i; - assert(compparms->numdlvls <= 32); - if (jpc_putuint8(out, compparms->numdlvls) || - jpc_putuint8(out, compparms->cblkwidthval) || - jpc_putuint8(out, compparms->cblkheightval) || - jpc_putuint8(out, compparms->cblksty) || - jpc_putuint8(out, compparms->qmfbid)) { - return -1; - } - if (prtflag) { - for (i = 0; i < compparms->numrlvls; ++i) { - if (jpc_putuint8(out, - ((compparms->rlvls[i].parheightval & 0xf) << 4) | - (compparms->rlvls[i].parwidthval & 0xf))) { - return -1; - } - } - } - return 0; -} - -/******************************************************************************\ -* RGN marker segment operations. -\******************************************************************************/ - -static int jpc_rgn_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in) -{ - jpc_rgn_t *rgn = &ms->parms.rgn; - uint_fast8_t tmp; - if (cstate->numcomps <= 256) { - if (jpc_getuint8(in, &tmp)) { - return -1; - } - rgn->compno = tmp; - } else { - if (jpc_getuint16(in, &rgn->compno)) { - return -1; - } - } - if (jpc_getuint8(in, &rgn->roisty) || - jpc_getuint8(in, &rgn->roishift)) { - return -1; - } - return 0; -} - -static int jpc_rgn_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out) -{ - jpc_rgn_t *rgn = &ms->parms.rgn; - if (cstate->numcomps <= 256) { - if (jpc_putuint8(out, rgn->compno)) { - return -1; - } - } else { - if (jpc_putuint16(out, rgn->compno)) { - return -1; - } - } - if (jpc_putuint8(out, rgn->roisty) || - jpc_putuint8(out, rgn->roishift)) { - return -1; - } - return 0; -} - -static int jpc_rgn_dumpparms(jpc_ms_t *ms, FILE *out) -{ - jpc_rgn_t *rgn = &ms->parms.rgn; - fprintf(out, "compno = %d; roisty = %d; roishift = %d\n", - (int)rgn->compno, rgn->roisty, rgn->roishift); - return 0; -} - -/******************************************************************************\ -* QCD marker segment operations. -\******************************************************************************/ - -static void jpc_qcd_destroyparms(jpc_ms_t *ms) -{ - jpc_qcd_t *qcd = &ms->parms.qcd; - jpc_qcx_destroycompparms(&qcd->compparms); -} - -static int jpc_qcd_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in) -{ - jpc_qcxcp_t *compparms = &ms->parms.qcd.compparms; - return jpc_qcx_getcompparms(compparms, cstate, in, ms->len); -} - -static int jpc_qcd_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out) -{ - jpc_qcxcp_t *compparms = &ms->parms.qcd.compparms; - return jpc_qcx_putcompparms(compparms, cstate, out); -} - -static int jpc_qcd_dumpparms(jpc_ms_t *ms, FILE *out) -{ - jpc_qcd_t *qcd = &ms->parms.qcd; - int i; - fprintf(out, "qntsty = %d; numguard = %d; numstepsizes = %d\n", - (int) qcd->compparms.qntsty, qcd->compparms.numguard, qcd->compparms.numstepsizes); - for (i = 0; i < qcd->compparms.numstepsizes; ++i) { - fprintf(out, "expn[%d] = 0x%04x; mant[%d] = 0x%04x;\n", - i, (unsigned) JPC_QCX_GETEXPN(qcd->compparms.stepsizes[i]), - i, (unsigned) JPC_QCX_GETMANT(qcd->compparms.stepsizes[i])); - } - return 0; -} - -/******************************************************************************\ -* QCC marker segment operations. -\******************************************************************************/ - -static void jpc_qcc_destroyparms(jpc_ms_t *ms) -{ - jpc_qcc_t *qcc = &ms->parms.qcc; - jpc_qcx_destroycompparms(&qcc->compparms); -} - -static int jpc_qcc_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in) -{ - jpc_qcc_t *qcc = &ms->parms.qcc; - uint_fast8_t tmp; - int len; - len = ms->len; - if (cstate->numcomps <= 256) { - jpc_getuint8(in, &tmp); - qcc->compno = tmp; - --len; - } else { - jpc_getuint16(in, &qcc->compno); - len -= 2; - } - if (jpc_qcx_getcompparms(&qcc->compparms, cstate, in, len)) { - return -1; - } - if (jas_stream_eof(in)) { - jpc_qcc_destroyparms(ms); - return -1; - } - return 0; -} - -static int jpc_qcc_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out) -{ - jpc_qcc_t *qcc = &ms->parms.qcc; - if (cstate->numcomps <= 256) { - jpc_putuint8(out, qcc->compno); - } else { - jpc_putuint16(out, qcc->compno); - } - if (jpc_qcx_putcompparms(&qcc->compparms, cstate, out)) { - return -1; - } - return 0; -} - -static int jpc_qcc_dumpparms(jpc_ms_t *ms, FILE *out) -{ - jpc_qcc_t *qcc = &ms->parms.qcc; - int i; - fprintf(out, "compno = %d; qntsty = %d; numguard = %d; " - "numstepsizes = %d\n", - (int)qcc->compno, qcc->compparms.qntsty, qcc->compparms.numguard, - qcc->compparms.numstepsizes); - for (i = 0; i < qcc->compparms.numstepsizes; ++i) { - fprintf(out, "expn[%d] = 0x%04x; mant[%d] = 0x%04x;\n", - i, (unsigned) JPC_QCX_GETEXPN(qcc->compparms.stepsizes[i]), - i, (unsigned) JPC_QCX_GETMANT(qcc->compparms.stepsizes[i])); - } - return 0; -} - -/*****************************************************************************\ -* QCD/QCC marker segment helper functions. -\*****************************************************************************/ - -static void jpc_qcx_destroycompparms(jpc_qcxcp_t *compparms) -{ - if (compparms->stepsizes) { - jas_free(compparms->stepsizes); - } -} - -static int jpc_qcx_getcompparms(jpc_qcxcp_t *compparms, jpc_cstate_t *cstate, - jas_stream_t *in, uint_fast16_t len) -{ - uint_fast8_t tmp; - int n; - int i; - n = 0; - jpc_getuint8(in, &tmp); - ++n; - compparms->qntsty = tmp & 0x1f; - compparms->numguard = (tmp >> 5) & 7; - switch (compparms->qntsty) { - case JPC_QCX_SIQNT: - compparms->numstepsizes = 1; - break; - case JPC_QCX_NOQNT: - compparms->numstepsizes = (len - n); - break; - case JPC_QCX_SEQNT: - /* XXX - this is a hack */ - compparms->numstepsizes = (len - n) / 2; - break; - } -if (compparms->numstepsizes > 0) { - compparms->stepsizes = jas_malloc(compparms->numstepsizes * - sizeof(uint_fast32_t)); - assert(compparms->stepsizes); - for (i = 0; i < compparms->numstepsizes; ++i) { - if (compparms->qntsty == JPC_QCX_NOQNT) { - jpc_getuint8(in, &tmp); - compparms->stepsizes[i] = JPC_QCX_EXPN(tmp >> 3); - } else { - jpc_getuint16(in, &compparms->stepsizes[i]); - } - } -} else { - compparms->stepsizes = 0; -} - if (jas_stream_error(in) || jas_stream_eof(in)) { - jpc_qcx_destroycompparms(compparms); - return -1; - } - return 0; -} - -static int jpc_qcx_putcompparms(jpc_qcxcp_t *compparms, jpc_cstate_t *cstate, - jas_stream_t *out) -{ - int i; - jpc_putuint8(out, ((compparms->numguard & 7) << 5) | compparms->qntsty); - for (i = 0; i < compparms->numstepsizes; ++i) { - if (compparms->qntsty == JPC_QCX_NOQNT) { - jpc_putuint8(out, JPC_QCX_GETEXPN( - compparms->stepsizes[i]) << 3); - } else { - jpc_putuint16(out, compparms->stepsizes[i]); - } - } - return 0; -} - -/******************************************************************************\ -* SOP marker segment operations. -\******************************************************************************/ - -static int jpc_sop_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in) -{ - jpc_sop_t *sop = &ms->parms.sop; - if (jpc_getuint16(in, &sop->seqno)) { - return -1; - } - return 0; -} - -static int jpc_sop_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out) -{ - jpc_sop_t *sop = &ms->parms.sop; - if (jpc_putuint16(out, sop->seqno)) { - return -1; - } - return 0; -} - -static int jpc_sop_dumpparms(jpc_ms_t *ms, FILE *out) -{ - jpc_sop_t *sop = &ms->parms.sop; - fprintf(out, "seqno = %d;\n", (int)sop->seqno); - return 0; -} - -/******************************************************************************\ -* PPM marker segment operations. -\******************************************************************************/ - -static void jpc_ppm_destroyparms(jpc_ms_t *ms) -{ - jpc_ppm_t *ppm = &ms->parms.ppm; - if (ppm->data) { - jas_free(ppm->data); - } -} - -static int jpc_ppm_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in) -{ - jpc_ppm_t *ppm = &ms->parms.ppm; - - ppm->data = 0; - - if (ms->len < 1) { - goto error; - } - if (jpc_getuint8(in, &ppm->ind)) { - goto error; - } - - ppm->len = ms->len - 1; - if (ppm->len > 0) { - if (!(ppm->data = jas_malloc(ppm->len * sizeof(unsigned char)))) { - goto error; - } - if (jas_stream_read(in, ppm->data, ppm->len) != ppm->len) { - goto error; - } - } else { - ppm->data = 0; - } - return 0; - -error: - jpc_ppm_destroyparms(ms); - return -1; -} - -static int jpc_ppm_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out) -{ - jpc_ppm_t *ppm = &ms->parms.ppm; - if (jas_stream_write(out, (char *) ppm->data, ppm->len) != ppm->len) { - return -1; - } - return 0; -} - -static int jpc_ppm_dumpparms(jpc_ms_t *ms, FILE *out) -{ - jpc_ppm_t *ppm = &ms->parms.ppm; - fprintf(out, "ind=%d; len = %d;\n", ppm->ind, (int)ppm->len); - if (ppm->len > 0) { - fprintf(out, "data =\n"); - jas_memdump(out, ppm->data, ppm->len); - } - return 0; -} - -/******************************************************************************\ -* PPT marker segment operations. -\******************************************************************************/ - -static void jpc_ppt_destroyparms(jpc_ms_t *ms) -{ - jpc_ppt_t *ppt = &ms->parms.ppt; - if (ppt->data) { - jas_free(ppt->data); - } -} - -static int jpc_ppt_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in) -{ - jpc_ppt_t *ppt = &ms->parms.ppt; - ppt->data = 0; - - if (ms->len < 1) { - goto error; - } - if (jpc_getuint8(in, &ppt->ind)) { - goto error; - } - ppt->len = ms->len - 1; - if (ppt->len > 0) { - if (!(ppt->data = jas_malloc(ppt->len * sizeof(unsigned char)))) { - goto error; - } - if (jas_stream_read(in, (char *) ppt->data, ppt->len) != ppt->len) { - goto error; - } - } else { - ppt->data = 0; - } - return 0; - -error: - jpc_ppt_destroyparms(ms); - return -1; -} - -static int jpc_ppt_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out) -{ - jpc_ppt_t *ppt = &ms->parms.ppt; - if (jpc_putuint8(out, ppt->ind)) { - return -1; - } - if (jas_stream_write(out, (char *) ppt->data, ppt->len) != ppt->len) { - return -1; - } - return 0; -} - -static int jpc_ppt_dumpparms(jpc_ms_t *ms, FILE *out) -{ - jpc_ppt_t *ppt = &ms->parms.ppt; - fprintf(out, "ind=%d; len = %d;\n", ppt->ind, (int)ppt->len); - if (ppt->len > 0) { - fprintf(out, "data =\n"); - jas_memdump(out, ppt->data, ppt->len); - } - return 0; -} - -/*****************************************************************************\ -* POC marker segment operations. -\*****************************************************************************/ - -static void jpc_poc_destroyparms(jpc_ms_t *ms) -{ - jpc_poc_t *poc = &ms->parms.poc; - if (poc->pchgs) { - jas_free(poc->pchgs); - } -} - -static int jpc_poc_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in) -{ - jpc_poc_t *poc = &ms->parms.poc; - jpc_pocpchg_t *pchg; - int pchgno; - uint_fast8_t tmp; - poc->numpchgs = (cstate->numcomps > 256) ? (ms->len / 9) : - (ms->len / 7); - if (!(poc->pchgs = jas_malloc(poc->numpchgs * sizeof(jpc_pocpchg_t)))) { - goto error; - } - for (pchgno = 0, pchg = poc->pchgs; pchgno < poc->numpchgs; ++pchgno, - ++pchg) { - if (jpc_getuint8(in, &pchg->rlvlnostart)) { - goto error; - } - if (cstate->numcomps > 256) { - if (jpc_getuint16(in, &pchg->compnostart)) { - goto error; - } - } else { - if (jpc_getuint8(in, &tmp)) { - goto error; - }; - pchg->compnostart = tmp; - } - if (jpc_getuint16(in, &pchg->lyrnoend) || - jpc_getuint8(in, &pchg->rlvlnoend)) { - goto error; - } - if (cstate->numcomps > 256) { - if (jpc_getuint16(in, &pchg->compnoend)) { - goto error; - } - } else { - if (jpc_getuint8(in, &tmp)) { - goto error; - } - pchg->compnoend = tmp; - } - if (jpc_getuint8(in, &pchg->prgord)) { - goto error; - } - if (pchg->rlvlnostart > pchg->rlvlnoend || - pchg->compnostart > pchg->compnoend) { - goto error; - } - } - return 0; - -error: - jpc_poc_destroyparms(ms); - return -1; -} - -static int jpc_poc_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out) -{ - jpc_poc_t *poc = &ms->parms.poc; - jpc_pocpchg_t *pchg; - int pchgno; - for (pchgno = 0, pchg = poc->pchgs; pchgno < poc->numpchgs; ++pchgno, - ++pchg) { - if (jpc_putuint8(out, pchg->rlvlnostart) || - ((cstate->numcomps > 256) ? - jpc_putuint16(out, pchg->compnostart) : - jpc_putuint8(out, pchg->compnostart)) || - jpc_putuint16(out, pchg->lyrnoend) || - jpc_putuint8(out, pchg->rlvlnoend) || - ((cstate->numcomps > 256) ? - jpc_putuint16(out, pchg->compnoend) : - jpc_putuint8(out, pchg->compnoend)) || - jpc_putuint8(out, pchg->prgord)) { - return -1; - } - } - return 0; -} - -static int jpc_poc_dumpparms(jpc_ms_t *ms, FILE *out) -{ - jpc_poc_t *poc = &ms->parms.poc; - jpc_pocpchg_t *pchg; - int pchgno; - for (pchgno = 0, pchg = poc->pchgs; pchgno < poc->numpchgs; - ++pchgno, ++pchg) { - fprintf(out, "po[%d] = %d; ", pchgno, pchg->prgord); - fprintf(out, "cs[%d] = %d; ce[%d] = %d; ", - pchgno, (int)pchg->compnostart, pchgno, (int)pchg->compnoend); - fprintf(out, "rs[%d] = %d; re[%d] = %d; ", - pchgno, pchg->rlvlnostart, pchgno, pchg->rlvlnoend); - fprintf(out, "le[%d] = %d\n", pchgno, (int)pchg->lyrnoend); - } - return 0; -} - -/******************************************************************************\ -* CRG marker segment operations. -\******************************************************************************/ - -static void jpc_crg_destroyparms(jpc_ms_t *ms) -{ - jpc_crg_t *crg = &ms->parms.crg; - if (crg->comps) { - jas_free(crg->comps); - } -} - -static int jpc_crg_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in) -{ - jpc_crg_t *crg = &ms->parms.crg; - jpc_crgcomp_t *comp; - uint_fast16_t compno; - crg->numcomps = cstate->numcomps; - if (!(crg->comps = jas_malloc(cstate->numcomps * sizeof(uint_fast16_t)))) { - return -1; - } - for (compno = 0, comp = crg->comps; compno < cstate->numcomps; - ++compno, ++comp) { - if (jpc_getuint16(in, &comp->hoff) || - jpc_getuint16(in, &comp->voff)) { - jpc_crg_destroyparms(ms); - return -1; - } - } - return 0; -} - -static int jpc_crg_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out) -{ - jpc_crg_t *crg = &ms->parms.crg; - int compno; - jpc_crgcomp_t *comp; - for (compno = 0, comp = crg->comps; compno < crg->numcomps; ++compno, - ++comp) { - if (jpc_putuint16(out, comp->hoff) || - jpc_putuint16(out, comp->voff)) { - return -1; - } - } - return 0; -} - -static int jpc_crg_dumpparms(jpc_ms_t *ms, FILE *out) -{ - jpc_crg_t *crg = &ms->parms.crg; - int compno; - jpc_crgcomp_t *comp; - for (compno = 0, comp = crg->comps; compno < crg->numcomps; ++compno, - ++comp) { - fprintf(out, "hoff[%d] = %d; voff[%d] = %d\n", - compno, (int)comp->hoff, compno, (int)comp->voff); - } - return 0; -} - -/******************************************************************************\ -* Operations for COM marker segment. -\******************************************************************************/ - -static void jpc_com_destroyparms(jpc_ms_t *ms) -{ - jpc_com_t *com = &ms->parms.com; - if (com->data) { - jas_free(com->data); - } -} - -static int jpc_com_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in) -{ - jpc_com_t *com = &ms->parms.com; - if (jpc_getuint16(in, &com->regid)) { - return -1; - } - com->len = ms->len - 2; - if (com->len > 0) { - if (!(com->data = jas_malloc(com->len))) { - return -1; - } - if (jas_stream_read(in, com->data, com->len) != com->len) { - return -1; - } - } else { - com->data = 0; - } - return 0; -} - -static int jpc_com_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out) -{ - jpc_com_t *com = &ms->parms.com; - if (jpc_putuint16(out, com->regid)) { - return -1; - } - if (jas_stream_write(out, com->data, com->len) != com->len) { - return -1; - } - return 0; -} - -static int jpc_com_dumpparms(jpc_ms_t *ms, FILE *out) -{ - jpc_com_t *com = &ms->parms.com; - int i; - int printable; - fprintf(out, "regid = %d;\n", (int)com->regid); - printable = 1; - for (i = 0, printable = 1; i < com->len && printable; ++i) { - if (!isprint(com->data[i])) - printable = 0; - } - if (printable) { - fprintf(out, "data = "); - fwrite(com->data, sizeof(char), com->len, out); - fprintf(out, "\n"); - } - return 0; -} - -/*****************************************************************************\ -* Operations for unknown types of marker segments. -\*****************************************************************************/ - -static void jpc_unk_destroyparms(jpc_ms_t *ms) -{ - jpc_unk_t *unk = &ms->parms.unk; - if (unk->data) { - jas_free(unk->data); - } -} - -static int jpc_unk_getparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in) -{ - jpc_unk_t *unk = &ms->parms.unk; - - if (ms->len > 0) { - if (!(unk->data = jas_malloc(ms->len * sizeof(unsigned char)))) { - return -1; - } - if (jas_stream_read(in, (char *) unk->data, ms->len) != ms->len) { - jas_free(unk->data); - return -1; - } - unk->len = ms->len; - } else { - unk->data = 0; - unk->len = 0; - } - return 0; -} - -static int jpc_unk_putparms(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out) -{ - return -1; -} - -static int jpc_unk_dumpparms(jpc_ms_t *ms, FILE *out) -{ - int i; - jpc_unk_t *unk = &ms->parms.unk; - for (i = 0; i < unk->len; ++i) { - fprintf(out, "%02x ", unk->data[i]); - } - return 0; -} - -/******************************************************************************\ -* Primitive I/O operations. -\******************************************************************************/ - -int jpc_getuint8(jas_stream_t *in, uint_fast8_t *val) -{ - int c; - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - if (val) { - *val = c; - } - return 0; -} - -int jpc_putuint8(jas_stream_t *out, uint_fast8_t val) -{ - if (jas_stream_putc(out, val & 0xff) == EOF) { - return -1; - } - return 0; -} - -int jpc_getuint16(jas_stream_t *in, uint_fast16_t *val) -{ - uint_fast16_t v; - int c; - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - v = c; - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - v = (v << 8) | c; - if (val) { - *val = v; - } - return 0; -} - -int jpc_putuint16(jas_stream_t *out, uint_fast16_t val) -{ - if (jas_stream_putc(out, (val >> 8) & 0xff) == EOF || - jas_stream_putc(out, val & 0xff) == EOF) { - return -1; - } - return 0; -} - -int jpc_getuint32(jas_stream_t *in, uint_fast32_t *val) -{ - uint_fast32_t v; - int c; - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - v = c; - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - v = (v << 8) | c; - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - v = (v << 8) | c; - if ((c = jas_stream_getc(in)) == EOF) { - return -1; - } - v = (v << 8) | c; - if (val) { - *val = v; - } - return 0; -} - -int jpc_putuint32(jas_stream_t *out, uint_fast32_t val) -{ - if (jas_stream_putc(out, (val >> 24) & 0xff) == EOF || - jas_stream_putc(out, (val >> 16) & 0xff) == EOF || - jas_stream_putc(out, (val >> 8) & 0xff) == EOF || - jas_stream_putc(out, val & 0xff) == EOF) { - return -1; - } - return 0; -} - -/******************************************************************************\ -* Miscellany -\******************************************************************************/ - -static jpc_mstabent_t *jpc_mstab_lookup(int id) -{ - jpc_mstabent_t *mstabent; - for (mstabent = jpc_mstab;; ++mstabent) { - if (mstabent->id == id || mstabent->id < 0) { - return mstabent; - } - } - assert(0); - return 0; -} - -int jpc_validate(jas_stream_t *in) -{ - int n; - int i; - unsigned char buf[2]; - - assert(JAS_STREAM_MAXPUTBACK >= 2); - - if ((n = jas_stream_read(in, (char *) buf, 2)) < 0) { - return -1; - } - for (i = n - 1; i >= 0; --i) { - if (jas_stream_ungetc(in, buf[i]) == EOF) { - return -1; - } - } - if (n < 2) { - return -1; - } - if (buf[0] == (JPC_MS_SOC >> 8) && buf[1] == (JPC_MS_SOC & 0xff)) { - return 0; - } - return -1; -} - -int jpc_getdata(jas_stream_t *in, jas_stream_t *out, long len) -{ - return jas_stream_copy(out, in, len); -} - -int jpc_putdata(jas_stream_t *out, jas_stream_t *in, long len) -{ - return jas_stream_copy(out, in, len); -} diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_cs.h b/converter/other/jpeg2000/libjasper/jpc/jpc_cs.h deleted file mode 100644 index 4bff677..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_cs.h +++ /dev/null @@ -1,812 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * JPEG-2000 Code Stream Library - * - * $Id$ - */ - -#ifndef JPC_CS_H -#define JPC_CS_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include "jasper/jas_image.h" -#include "jasper/jas_stream.h" - -#include "jpc_cod.h" - -/******************************************************************************\ -* Constants and Types. -\******************************************************************************/ - -/* The maximum number of resolution levels. */ -#define JPC_MAXRLVLS 33 - -/* The maximum number of bands. */ -#define JPC_MAXBANDS (3 * JPC_MAXRLVLS + 1) - -/* The maximum number of layers. */ -#define JPC_MAXLYRS 16384 - -/**************************************\ -* Code stream. -\**************************************/ - -/* - * Code stream states. - */ - -/* Initial. */ -#define JPC_CS_INIT 0 -/* Main header. */ -#define JPC_CS_MHDR 1 -/* Tile-part header. */ -#define JPC_CS_THDR 2 -/* Main trailer. */ -#define JPC_CS_MTLR 3 -/* Tile-part data. */ -#define JPC_CS_TDATA 4 - -/* - * Unfortunately, the code stream syntax was not designed in such a way that - * any given marker segment can be correctly decoded without additional state - * derived from previously decoded marker segments. - * For example, a RGN/COC/QCC marker segment cannot be decoded unless the - * number of components is known. - */ - -/* - * Code stream state information. - */ - -typedef struct { - - /* The number of components. */ - int numcomps; - -} jpc_cstate_t; - -/**************************************\ -* SOT marker segment parameters. -\**************************************/ - -typedef struct { - - /* The tile number. */ - uint_fast16_t tileno; - - /* The combined length of the marker segment and its auxiliary data - (i.e., packet data). */ - uint_fast32_t len; - - /* The tile-part instance. */ - uint_fast8_t partno; - - /* The number of tile-parts. */ - uint_fast8_t numparts; - -} jpc_sot_t; - -/**************************************\ -* SIZ marker segment parameters. -\**************************************/ - -/* Per component information. */ - -typedef struct { - - /* The precision of the samples. */ - uint_fast8_t prec; - - /* The signedness of the samples. */ - uint_fast8_t sgnd; - - /* The horizontal separation of samples with respect to the reference - grid. */ - uint_fast8_t hsamp; - - /* The vertical separation of samples with respect to the reference - grid. */ - uint_fast8_t vsamp; - -} jpc_sizcomp_t; - -/* SIZ marker segment parameters. */ - -typedef struct { - - /* The code stream capabilities. */ - uint_fast16_t caps; - - /* The width of the image in units of the reference grid. */ - uint_fast32_t width; - - /* The height of the image in units of the reference grid. */ - uint_fast32_t height; - - /* The horizontal offset from the origin of the reference grid to the - left side of the image area. */ - uint_fast32_t xoff; - - /* The vertical offset from the origin of the reference grid to the - top side of the image area. */ - uint_fast32_t yoff; - - /* The nominal width of a tile in units of the reference grid. */ - uint_fast32_t tilewidth; - - /* The nominal height of a tile in units of the reference grid. */ - uint_fast32_t tileheight; - - /* The horizontal offset from the origin of the reference grid to the - left side of the first tile. */ - uint_fast32_t tilexoff; - - /* The vertical offset from the origin of the reference grid to the - top side of the first tile. */ - uint_fast32_t tileyoff; - - /* The number of components. */ - uint_fast16_t numcomps; - - /* The per-component information. */ - jpc_sizcomp_t *comps; - -} jpc_siz_t; - -/**************************************\ -* COD marker segment parameters. -\**************************************/ - -/* - * Coding style constants. - */ - -/* Precincts may be used. */ -#define JPC_COX_PRT 0x01 -/* SOP marker segments may be used. */ -#define JPC_COD_SOP 0x02 -/* EPH marker segments may be used. */ -#define JPC_COD_EPH 0x04 - -/* - * Progression order constants. - */ - -/* Layer-resolution-component-precinct progressive - (i.e., progressive by fidelity). */ -#define JPC_COD_LRCPPRG 0 -/* Resolution-layer-component-precinct progressive - (i.e., progressive by resolution). */ -#define JPC_COD_RLCPPRG 1 -/* Resolution-precinct-component-layer progressive. */ -#define JPC_COD_RPCLPRG 2 -/* Precinct-component-resolution-layer progressive. */ -#define JPC_COD_PCRLPRG 3 -/* Component-position-resolution-layer progressive. */ -#define JPC_COD_CPRLPRG 4 - -/* - * Code block style constants. - */ - -#define JPC_COX_LAZY 0x01 /* Selective arithmetic coding bypass. */ -#define JPC_COX_RESET 0x02 /* Reset context probabilities. */ -#define JPC_COX_TERMALL 0x04 /* Terminate all coding passes. */ -#define JPC_COX_VSC 0x08 /* Vertical stripe causal context formation. */ -#define JPC_COX_PTERM 0x10 /* Predictable termination. */ -#define JPC_COX_SEGSYM 0x20 /* Use segmentation symbols. */ - -/* Transform constants. */ -#define JPC_COX_INS 0x00 /* Irreversible 9/7. */ -#define JPC_COX_RFT 0x01 /* Reversible 5/3. */ - -/* Multicomponent transform constants. */ -#define JPC_COD_NOMCT 0x00 /* No multicomponent transform. */ -#define JPC_COD_MCT 0x01 /* Multicomponent transform. */ - -/* Get the code block size value from the code block size exponent. */ -#define JPC_COX_CBLKSIZEEXPN(x) ((x) - 2) -/* Get the code block size exponent from the code block size value. */ -#define JPC_COX_GETCBLKSIZEEXPN(x) ((x) + 2) - -/* Per resolution-level information. */ - -typedef struct { - - /* The packet partition width. */ - uint_fast8_t parwidthval; - - /* The packet partition height. */ - uint_fast8_t parheightval; - -} jpc_coxrlvl_t; - -/* Per component information. */ - -typedef struct { - - /* The coding style. */ - uint_fast8_t csty; - - /* The number of decomposition levels. */ - uint_fast8_t numdlvls; - - /* The nominal code block width specifier. */ - uint_fast8_t cblkwidthval; - - /* The nominal code block height specifier. */ - uint_fast8_t cblkheightval; - - /* The style of coding passes. */ - uint_fast8_t cblksty; - - /* The QMFB employed. */ - uint_fast8_t qmfbid; - - /* The number of resolution levels. */ - int numrlvls; - - /* The per-resolution-level information. */ - jpc_coxrlvl_t rlvls[JPC_MAXRLVLS]; - -} jpc_coxcp_t; - -/* COD marker segment parameters. */ - -typedef struct { - - /* The general coding style. */ - uint_fast8_t csty; - - /* The progression order. */ - uint_fast8_t prg; - - /* The number of layers. */ - uint_fast16_t numlyrs; - - /* The multicomponent transform. */ - uint_fast8_t mctrans; - - /* Component-related parameters. */ - jpc_coxcp_t compparms; - -} jpc_cod_t; - -/* COC marker segment parameters. */ - -typedef struct { - - /* The component number. */ - uint_fast16_t compno; - - /* Component-related parameters. */ - jpc_coxcp_t compparms; - -} jpc_coc_t; - -/**************************************\ -* RGN marker segment parameters. -\**************************************/ - -/* The maxshift ROI style. */ -#define JPC_RGN_MAXSHIFT 0x00 - -typedef struct { - - /* The component to which the marker applies. */ - uint_fast16_t compno; - - /* The ROI style. */ - uint_fast8_t roisty; - - /* The ROI shift value. */ - uint_fast8_t roishift; - -} jpc_rgn_t; - -/**************************************\ -* QCD/QCC marker segment parameters. -\**************************************/ - -/* - * Quantization style constants. - */ - -#define JPC_QCX_NOQNT 0 /* No quantization. */ -#define JPC_QCX_SIQNT 1 /* Scalar quantization, implicit. */ -#define JPC_QCX_SEQNT 2 /* Scalar quantization, explicit. */ - -/* - * Stepsize manipulation macros. - */ - -#define JPC_QCX_GETEXPN(x) ((x) >> 11) -#define JPC_QCX_GETMANT(x) ((x) & 0x07ff) -#define JPC_QCX_EXPN(x) (assert(!((x) & (~0x1f))), (((x) & 0x1f) << 11)) -#define JPC_QCX_MANT(x) (assert(!((x) & (~0x7ff))), ((x) & 0x7ff)) - -/* Per component information. */ - -typedef struct { - - /* The quantization style. */ - uint_fast8_t qntsty; - - /* The number of step sizes. */ - int numstepsizes; - - /* The step sizes. */ - uint_fast16_t *stepsizes; - - /* The number of guard bits. */ - uint_fast8_t numguard; - -} jpc_qcxcp_t; - -/* QCC marker segment parameters. */ - -typedef struct { - - /* The component associated with this marker segment. */ - uint_fast16_t compno; - - /* The parameters. */ - jpc_qcxcp_t compparms; - -} jpc_qcc_t; - -/* QCD marker segment parameters. */ - -typedef struct { - - /* The parameters. */ - jpc_qcxcp_t compparms; - -} jpc_qcd_t; - -/**************************************\ -* POD marker segment parameters. -\**************************************/ - -typedef struct { - - /* The progression order. */ - uint_fast8_t prgord; - - /* The lower bound (inclusive) on the resolution level for the - progression order volume. */ - uint_fast8_t rlvlnostart; - - /* The upper bound (exclusive) on the resolution level for the - progression order volume. */ - uint_fast8_t rlvlnoend; - - /* The lower bound (inclusive) on the component for the progression - order volume. */ - uint_fast16_t compnostart; - - /* The upper bound (exclusive) on the component for the progression - order volume. */ - uint_fast16_t compnoend; - - /* The upper bound (exclusive) on the layer for the progression - order volume. */ - uint_fast16_t lyrnoend; - -} jpc_pocpchg_t; - -/* An alias for the above type. */ -typedef jpc_pocpchg_t jpc_pchg_t; - -/* POC marker segment parameters. */ - -typedef struct { - - /* The number of progression order changes. */ - int numpchgs; - - /* The per-progression-order-change information. */ - jpc_pocpchg_t *pchgs; - -} jpc_poc_t; - -/**************************************\ -* PPM/PPT marker segment parameters. -\**************************************/ - -/* PPM marker segment parameters. */ - -typedef struct { - - /* The index. */ - uint_fast8_t ind; - - /* The length. */ - uint_fast16_t len; - - /* The data. */ - unsigned char *data; - -} jpc_ppm_t; - -/* PPT marker segment parameters. */ - -typedef struct { - - /* The index. */ - uint_fast8_t ind; - - /* The length. */ - uint_fast32_t len; - - /* The data. */ - unsigned char *data; - -} jpc_ppt_t; - -/**************************************\ -* COM marker segment parameters. -\**************************************/ - -/* - * Registration IDs. - */ - -#define JPC_COM_BIN 0x00 -#define JPC_COM_LATIN 0x01 - -typedef struct { - - /* The registration ID. */ - uint_fast16_t regid; - - /* The length of the data in bytes. */ - uint_fast16_t len; - - /* The data. */ - unsigned char *data; - -} jpc_com_t; - -/**************************************\ -* SOP marker segment parameters. -\**************************************/ - -typedef struct { - - /* The sequence number. */ - uint_fast16_t seqno; - -} jpc_sop_t; - -/**************************************\ -* CRG marker segment parameters. -\**************************************/ - -/* Per component information. */ - -typedef struct { - - /* The horizontal offset. */ - uint_fast16_t hoff; - - /* The vertical offset. */ - uint_fast16_t voff; - -} jpc_crgcomp_t; - -typedef struct { - - /* The number of components. */ - int numcomps; - - /* Per component information. */ - jpc_crgcomp_t *comps; - -} jpc_crg_t; - -/**************************************\ -* Marker segment parameters for unknown marker type. -\**************************************/ - -typedef struct { - - /* The data. */ - unsigned char *data; - - /* The length. */ - uint_fast16_t len; - -} jpc_unk_t; - -/**************************************\ -* Generic marker segment parameters. -\**************************************/ - -typedef union { - int soc; /* unused */ - jpc_sot_t sot; - int sod; /* unused */ - int eoc; /* unused */ - jpc_siz_t siz; - jpc_cod_t cod; - jpc_coc_t coc; - jpc_rgn_t rgn; - jpc_qcd_t qcd; - jpc_qcc_t qcc; - jpc_poc_t poc; - /* jpc_plm_t plm; */ - /* jpc_plt_t plt; */ - jpc_ppm_t ppm; - jpc_ppt_t ppt; - jpc_sop_t sop; - int eph; /* unused */ - jpc_com_t com; - jpc_crg_t crg; - jpc_unk_t unk; -} jpc_msparms_t; - -/**************************************\ -* Marker segment. -\**************************************/ - -/* Marker segment IDs. */ - -/* The smallest valid marker value. */ -#define JPC_MS_MIN 0xff00 - -/* The largest valid marker value. */ -#define JPC_MS_MAX 0xffff - -/* The minimum marker value that cannot occur within packet data. */ -#define JPC_MS_INMIN 0xff80 -/* The maximum marker value that cannot occur within packet data. */ -#define JPC_MS_INMAX 0xffff - -/* Delimiting marker segments. */ -#define JPC_MS_SOC 0xff4f /* Start of code stream (SOC). */ -#define JPC_MS_SOT 0xff90 /* Start of tile-part (SOT). */ -#define JPC_MS_SOD 0xff93 /* Start of data (SOD). */ -#define JPC_MS_EOC 0xffd9 /* End of code stream (EOC). */ - -/* Fixed information marker segments. */ -#define JPC_MS_SIZ 0xff51 /* Image and tile size (SIZ). */ - -/* Functional marker segments. */ -#define JPC_MS_COD 0xff52 /* Coding style default (COD). */ -#define JPC_MS_COC 0xff53 /* Coding style component (COC). */ -#define JPC_MS_RGN 0xff5e /* Region of interest (RGN). */ -#define JPC_MS_QCD 0xff5c /* Quantization default (QCD). */ -#define JPC_MS_QCC 0xff5d /* Quantization component (QCC). */ -#define JPC_MS_POC 0xff5f /* Progression order default (POC). */ - -/* Pointer marker segments. */ -#define JPC_MS_TLM 0xff55 /* Tile-part lengths, main header (TLM). */ -#define JPC_MS_PLM 0xff57 /* Packet length, main header (PLM). */ -#define JPC_MS_PLT 0xff58 /* Packet length, tile-part header (PLT). */ -#define JPC_MS_PPM 0xff60 /* Packed packet headers, main header (PPM). */ -#define JPC_MS_PPT 0xff61 /* Packet packet headers, tile-part header (PPT). */ - -/* In bit stream marker segments. */ -#define JPC_MS_SOP 0xff91 /* Start of packet (SOP). */ -#define JPC_MS_EPH 0xff92 /* End of packet header (EPH). */ - -/* Informational marker segments. */ -#define JPC_MS_CRG 0xff63 /* Component registration (CRG). */ -#define JPC_MS_COM 0xff64 /* Comment (COM). */ - -/* Forward declaration. */ -struct jpc_msops_s; - -/* Generic marker segment class. */ - -typedef struct { - - /* The type of marker segment. */ - uint_fast16_t id; - - /* The length of the marker segment. */ - uint_fast16_t len; - - /* The starting offset within the stream. */ - uint_fast32_t off; - - /* The parameters of the marker segment. */ - jpc_msparms_t parms; - - /* The marker segment operations. */ - struct jpc_msops_s *ops; - -} jpc_ms_t; - -/* Marker segment operations (which depend on the marker segment type). */ - -typedef struct jpc_msops_s { - - /* Destroy the marker segment parameters. */ - void (*destroyparms)(jpc_ms_t *ms); - - /* Get the marker segment parameters from a stream. */ - int (*getparms)(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in); - - /* Put the marker segment parameters to a stream. */ - int (*putparms)(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out); - - /* Dump the marker segment parameters (for debugging). */ - int (*dumpparms)(jpc_ms_t *ms, FILE *out); - -} jpc_msops_t; - -/******************************************************************************\ -* Macros/Functions. -\******************************************************************************/ - -/* Create a code-stream state object. */ -jpc_cstate_t *jpc_cstate_create(void); - -/* Destroy a code-stream state object. */ -void jpc_cstate_destroy(jpc_cstate_t *cstate); - -/* Create a marker segment. */ -jpc_ms_t *jpc_ms_create(int type); - -/* Destroy a marker segment. */ -void jpc_ms_destroy(jpc_ms_t *ms); - -/* Does a marker segment have parameters? */ -#define JPC_MS_HASPARMS(x) \ - (!((x) == JPC_MS_SOC || (x) == JPC_MS_SOD || (x) == JPC_MS_EOC || \ - (x) == JPC_MS_EPH || ((x) >= 0xff30 && (x) <= 0xff3f))) - -/* Get the marker segment type. */ -#define jpc_ms_gettype(ms) \ - ((ms)->id) - -/* Read a marker segment from a stream. */ -jpc_ms_t *jpc_getms(jas_stream_t *in, jpc_cstate_t *cstate); - -/* Write a marker segment to a stream. */ -int jpc_putms(jas_stream_t *out, jpc_cstate_t *cstate, jpc_ms_t *ms); - -/* Copy code stream data from one stream to another. */ -int jpc_getdata(jas_stream_t *in, jas_stream_t *out, long n); - -/* Copy code stream data from one stream to another. */ -int jpc_putdata(jas_stream_t *out, jas_stream_t *in, long n); - -/* Dump a marker segment (for debugging). */ -void jpc_ms_dump(jpc_ms_t *ms, FILE *out); - -/* Read a 8-bit unsigned integer from a stream. */ -int jpc_getuint8(jas_stream_t *in, uint_fast8_t *val); - -/* Read a 16-bit unsigned integer from a stream. */ -int jpc_getuint16(jas_stream_t *in, uint_fast16_t *val); - -/* Read a 32-bit unsigned integer from a stream. */ -int jpc_getuint32(jas_stream_t *in, uint_fast32_t *val); - -/* Write a 8-bit unsigned integer to a stream. */ -int jpc_putuint8(jas_stream_t *out, uint_fast8_t val); - -/* Write a 16-bit unsigned integer to a stream. */ -int jpc_putuint16(jas_stream_t *out, uint_fast16_t val); - -/* Write a 32-bit unsigned integer to a stream. */ -int jpc_putuint32(jas_stream_t *out, uint_fast32_t val); - -#endif diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_dec.c b/converter/other/jpeg2000/libjasper/jpc/jpc_dec.c deleted file mode 100644 index cada97f..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_dec.c +++ /dev/null @@ -1,2351 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * $Id$ - */ - -/*****************************************************************************\ -* Includes. -\*****************************************************************************/ - -#include -#include -#include - -#include "pm.h" - -#include "jasper/jas_types.h" -#include "jasper/jas_math.h" -#include "jasper/jas_tvp.h" -#include "jasper/jas_malloc.h" -#include "jasper/jas_debug.h" - -#include "jpc_fix.h" -#include "jpc_dec.h" -#include "jpc_cs.h" -#include "jpc_mct.h" -#include "jpc_t2dec.h" -#include "jpc_t1dec.h" -#include "jpc_math.h" - -/*****************************************************************************\ -* -\*****************************************************************************/ - -#define JPC_MHSOC 0x0001 - /* In the main header, expecting a SOC marker segment. */ -#define JPC_MHSIZ 0x0002 - /* In the main header, expecting a SIZ marker segment. */ -#define JPC_MH 0x0004 - /* In the main header, expecting "other" marker segments. */ -#define JPC_TPHSOT 0x0008 - /* In a tile-part header, expecting a SOT marker segment. */ -#define JPC_TPH 0x0010 - /* In a tile-part header, expecting "other" marker segments. */ -#define JPC_MT 0x0020 - /* In the main trailer. */ - -typedef struct { - - uint_fast16_t id; - /* The marker segment type. */ - - int validstates; - /* The states in which this type of marker segment can be - validly encountered. */ - - int (*action)(jpc_dec_t *dec, jpc_ms_t *ms); - /* The action to take upon encountering this type of marker segment. */ - -} jpc_dec_mstabent_t; - -/******************************************************************************\ -* -\******************************************************************************/ - -/* COD/COC parameters have been specified. */ -#define JPC_CSET 0x0001 -/* QCD/QCC parameters have been specified. */ -#define JPC_QSET 0x0002 -/* COD/COC parameters set from a COC marker segment. */ -#define JPC_COC 0x0004 -/* QCD/QCC parameters set from a QCC marker segment. */ -#define JPC_QCC 0x0008 - -/******************************************************************************\ -* Local function prototypes. -\******************************************************************************/ - -static int jpc_dec_dump(jpc_dec_t *dec, FILE *out); - -jpc_ppxstab_t *jpc_ppxstab_create(void); -void jpc_ppxstab_destroy(jpc_ppxstab_t *tab); -int jpc_ppxstab_grow(jpc_ppxstab_t *tab, int maxents); -int jpc_ppxstab_insert(jpc_ppxstab_t *tab, jpc_ppxstabent_t *ent); -jpc_streamlist_t *jpc_ppmstabtostreams(jpc_ppxstab_t *tab); -int jpc_pptstabwrite(jas_stream_t *out, jpc_ppxstab_t *tab); -jpc_ppxstabent_t *jpc_ppxstabent_create(void); -void jpc_ppxstabent_destroy(jpc_ppxstabent_t *ent); - -int jpc_streamlist_numstreams(jpc_streamlist_t *streamlist); -jpc_streamlist_t *jpc_streamlist_create(void); -int jpc_streamlist_insert(jpc_streamlist_t *streamlist, int streamno, - jas_stream_t *stream); -jas_stream_t *jpc_streamlist_remove(jpc_streamlist_t *streamlist, int streamno); -void jpc_streamlist_destroy(jpc_streamlist_t *streamlist); -jas_stream_t *jpc_streamlist_get(jpc_streamlist_t *streamlist, int streamno); - -static void jpc_dec_cp_resetflags(jpc_dec_cp_t *cp); -static jpc_dec_cp_t *jpc_dec_cp_create(uint_fast16_t numcomps); -static int jpc_dec_cp_isvalid(jpc_dec_cp_t *cp); -static jpc_dec_cp_t *jpc_dec_cp_copy(jpc_dec_cp_t *cp); -static int jpc_dec_cp_setfromcod(jpc_dec_cp_t *cp, jpc_cod_t *cod); -static int jpc_dec_cp_setfromcoc(jpc_dec_cp_t *cp, jpc_coc_t *coc); -static int jpc_dec_cp_setfromcox(jpc_dec_cp_t *cp, jpc_dec_ccp_t *ccp, - jpc_coxcp_t *compparms, int flags); -static int jpc_dec_cp_setfromqcd(jpc_dec_cp_t *cp, jpc_qcd_t *qcd); -static int jpc_dec_cp_setfromqcc(jpc_dec_cp_t *cp, jpc_qcc_t *qcc); -static int jpc_dec_cp_setfromqcx(jpc_dec_cp_t *cp, jpc_dec_ccp_t *ccp, - jpc_qcxcp_t *compparms, int flags); -static int jpc_dec_cp_setfromrgn(jpc_dec_cp_t *cp, jpc_rgn_t *rgn); -static int jpc_dec_cp_prepare(jpc_dec_cp_t *cp); -static void jpc_dec_cp_destroy(jpc_dec_cp_t *cp); -static int jpc_dec_cp_setfrompoc(jpc_dec_cp_t *cp, jpc_poc_t *poc, int reset); -static int jpc_pi_addpchgfrompoc(jpc_pi_t *pi, jpc_poc_t *poc); - -static int jpc_dec_decode(jpc_dec_t *dec); -static jpc_dec_t *jpc_dec_create(jpc_dec_importopts_t *impopts, jas_stream_t *in); -static void jpc_dec_destroy(jpc_dec_t *dec); -static void jpc_dequantize(jas_matrix_t *x, jpc_fix_t absstepsize); -static void jpc_undo_roi(jas_matrix_t *x, int roishift, int bgshift, int numbps); -static jpc_fix_t jpc_calcabsstepsize(int stepsize, int numbits); -static int jpc_dec_tiledecode(jpc_dec_t *dec, jpc_dec_tile_t *tile); -static int jpc_dec_tileinit(jpc_dec_t *dec, jpc_dec_tile_t *tile); -static int jpc_dec_tilefini(jpc_dec_t *dec, jpc_dec_tile_t *tile); -static int jpc_dec_process_soc(jpc_dec_t *dec, jpc_ms_t *ms); -static int jpc_dec_process_sot(jpc_dec_t *dec, jpc_ms_t *ms); -static int jpc_dec_process_sod(jpc_dec_t *dec, jpc_ms_t *ms); -static int jpc_dec_process_eoc(jpc_dec_t *dec, jpc_ms_t *ms); -static int jpc_dec_process_siz(jpc_dec_t *dec, jpc_ms_t *ms); -static int jpc_dec_process_cod(jpc_dec_t *dec, jpc_ms_t *ms); -static int jpc_dec_process_coc(jpc_dec_t *dec, jpc_ms_t *ms); -static int jpc_dec_process_rgn(jpc_dec_t *dec, jpc_ms_t *ms); -static int jpc_dec_process_qcd(jpc_dec_t *dec, jpc_ms_t *ms); -static int jpc_dec_process_qcc(jpc_dec_t *dec, jpc_ms_t *ms); -static int jpc_dec_process_poc(jpc_dec_t *dec, jpc_ms_t *ms); -static int jpc_dec_process_ppm(jpc_dec_t *dec, jpc_ms_t *ms); -static int jpc_dec_process_ppt(jpc_dec_t *dec, jpc_ms_t *ms); -static int jpc_dec_process_com(jpc_dec_t *dec, jpc_ms_t *ms); -static int jpc_dec_process_unk(jpc_dec_t *dec, jpc_ms_t *ms); -static int jpc_dec_process_crg(jpc_dec_t *dec, jpc_ms_t *ms); -static int jpc_dec_parseopts(char *optstr, jpc_dec_importopts_t *opts); - -/******************************************************************************\ -* Global data. -\******************************************************************************/ - -jpc_dec_mstabent_t jpc_dec_mstab[] = { - {JPC_MS_SOC, JPC_MHSOC, jpc_dec_process_soc}, - {JPC_MS_SOT, JPC_MH | JPC_TPHSOT, jpc_dec_process_sot}, - {JPC_MS_SOD, JPC_TPH, jpc_dec_process_sod}, - {JPC_MS_EOC, JPC_TPHSOT, jpc_dec_process_eoc}, - {JPC_MS_SIZ, JPC_MHSIZ, jpc_dec_process_siz}, - {JPC_MS_COD, JPC_MH | JPC_TPH, jpc_dec_process_cod}, - {JPC_MS_COC, JPC_MH | JPC_TPH, jpc_dec_process_coc}, - {JPC_MS_RGN, JPC_MH | JPC_TPH, jpc_dec_process_rgn}, - {JPC_MS_QCD, JPC_MH | JPC_TPH, jpc_dec_process_qcd}, - {JPC_MS_QCC, JPC_MH | JPC_TPH, jpc_dec_process_qcc}, - {JPC_MS_POC, JPC_MH | JPC_TPH, jpc_dec_process_poc}, - {JPC_MS_TLM, JPC_MH, 0}, - {JPC_MS_PLM, JPC_MH, 0}, - {JPC_MS_PLT, JPC_TPH, 0}, - {JPC_MS_PPM, JPC_MH, jpc_dec_process_ppm}, - {JPC_MS_PPT, JPC_TPH, jpc_dec_process_ppt}, - {JPC_MS_SOP, 0, 0}, - {JPC_MS_CRG, JPC_MH, jpc_dec_process_crg}, - {JPC_MS_COM, JPC_MH | JPC_TPH, jpc_dec_process_com}, - {0, JPC_MH | JPC_TPH, jpc_dec_process_unk} -}; - -/*****************************************************************************\ -* The main entry point for the JPEG-2000 decoder. -\*****************************************************************************/ - -jas_image_t *jpc_decode(jas_stream_t *in, char *optstr) -{ - jpc_dec_importopts_t opts; - jpc_dec_t *dec; - jas_image_t *image; - - dec = 0; - - if (jpc_dec_parseopts(optstr, &opts)) { - goto error; - } - - jpc_initluts(); - - if (!(dec = jpc_dec_create(&opts, in))) { - goto error; - } - - /* Do most of the work. */ - if (jpc_dec_decode(dec)) { - goto error; - } - - if (jas_image_numcmpts(dec->image) >= 3) { - jas_image_setcolorspace(dec->image, JAS_IMAGE_CS_RGB); - jas_image_setcmpttype(dec->image, 0, - JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_RGB_R)); - jas_image_setcmpttype(dec->image, 1, - JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_RGB_G)); - jas_image_setcmpttype(dec->image, 2, - JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_RGB_B)); - } else { - jas_image_setcolorspace(dec->image, JAS_IMAGE_CS_GRAY); - jas_image_setcmpttype(dec->image, 0, - JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_GRAY_Y)); - } - - /* Save the return value. */ - image = dec->image; - - /* Stop the image from being discarded. */ - dec->image = 0; - - /* Destroy decoder. */ - jpc_dec_destroy(dec); - - return image; - -error: - if (dec) { - jpc_dec_destroy(dec); - } - return 0; -} - -typedef enum { - OPT_MAXLYRS, - OPT_MAXPKTS, - OPT_DEBUG -} optid_t; - -jas_taginfo_t decopts[] = { - {OPT_MAXLYRS, "maxlyrs"}, - {OPT_MAXPKTS, "maxpkts"}, - {OPT_DEBUG, "debug"}, - {-1, 0} -}; - -static int jpc_dec_parseopts(char *optstr, jpc_dec_importopts_t *opts) -{ - jas_tvparser_t *tvp; - - opts->debug = 0; - opts->maxlyrs = JPC_MAXLYRS; - opts->maxpkts = -1; - - if (!(tvp = jas_tvparser_create(optstr ? optstr : ""))) { - return -1; - } - - while (!jas_tvparser_next(tvp)) { - switch (jas_taginfo_nonull(jas_taginfos_lookup(decopts, - jas_tvparser_gettag(tvp)))->id) { - case OPT_MAXLYRS: - opts->maxlyrs = atoi(jas_tvparser_getval(tvp)); - break; - case OPT_DEBUG: - opts->debug = atoi(jas_tvparser_getval(tvp)); - break; - case OPT_MAXPKTS: - opts->maxpkts = atoi(jas_tvparser_getval(tvp)); - break; - default: - fprintf(stderr, "warning: ignoring invalid option %s\n", - jas_tvparser_gettag(tvp)); - break; - } - } - - jas_tvparser_destroy(tvp); - - return 0; -} - -/******************************************************************************\ -* Code for table-driven code stream decoder. -\******************************************************************************/ - -static jpc_dec_mstabent_t *jpc_dec_mstab_lookup(uint_fast16_t id) -{ - jpc_dec_mstabent_t *mstabent; - for (mstabent = jpc_dec_mstab; mstabent->id != 0; ++mstabent) { - if (mstabent->id == id) { - break; - } - } - return mstabent; -} - -static int jpc_dec_decode(jpc_dec_t *dec) -{ - jpc_ms_t *ms; - jpc_dec_mstabent_t *mstabent; - int ret; - jpc_cstate_t *cstate; - - if (!(cstate = jpc_cstate_create())) { - return -1; - } - dec->cstate = cstate; - - /* Initially, we should expect to encounter a SOC marker segment. */ - dec->state = JPC_MHSOC; - - for (;;) { - - /* Get the next marker segment in the code stream. */ - if (!(ms = jpc_getms(dec->in, cstate))) { - fprintf(stderr, "cannot get marker segment\n"); - return -1; - } - - mstabent = jpc_dec_mstab_lookup(ms->id); - assert(mstabent); - - /* Ensure that this type of marker segment is permitted - at this point in the code stream. */ - if (!(dec->state & mstabent->validstates)) { - fprintf(stderr, "unexpected marker segment type\n"); - jpc_ms_destroy(ms); - return -1; - } - - /* Process the marker segment. */ - if (mstabent->action) { - ret = (*mstabent->action)(dec, ms); - } else { - /* No explicit action is required. */ - ret = 0; - } - - /* Destroy the marker segment. */ - jpc_ms_destroy(ms); - - if (ret < 0) { - return -1; - } else if (ret > 0) { - break; - } - - } - - return 0; -} - -static int jpc_dec_process_crg(jpc_dec_t *dec, jpc_ms_t *ms) -{ - /* Ignore the information in the CRG marker segment for now. - This information serves no useful purpose for decoding anyhow. - Some other parts of the code need to be changed if these lines - are enabled. - */ -#ifdef USING_CRG - uint_fast16_t cmptno; - jpc_dec_cmpt_t *cmpt; - jpc_crg_t *crg; - - crg = &ms->parms.crg; - for (cmptno = 0, cmpt = dec->cmpts; cmptno < dec->numcomps; ++cmptno, - ++cmpt) { - cmpt->hsubstep = crg->comps[cmptno].hoff; - cmpt->vsubstep = crg->comps[cmptno].voff; - } -#endif - return 0; -} - -static int jpc_dec_process_soc(jpc_dec_t *dec, jpc_ms_t *ms) -{ - /* We should expect to encounter a SIZ marker segment next. */ - dec->state = JPC_MHSIZ; - - return 0; -} - -static int jpc_dec_process_sot(jpc_dec_t *dec, jpc_ms_t *ms) -{ - jpc_dec_tile_t *tile; - jpc_sot_t *sot = &ms->parms.sot; - jas_image_cmptparm_t *compinfos; - jas_image_cmptparm_t *compinfo; - jpc_dec_cmpt_t *cmpt; - uint_fast16_t cmptno; - - if (dec->state == JPC_MH) { - - compinfos = jas_malloc(dec->numcomps * sizeof(jas_image_cmptparm_t)); - assert(compinfos); - for (cmptno = 0, cmpt = dec->cmpts, compinfo = compinfos; - cmptno < dec->numcomps; ++cmptno, ++cmpt, ++compinfo) { - compinfo->tlx = 0; - compinfo->tly = 0; - compinfo->prec = cmpt->prec; - compinfo->sgnd = cmpt->sgnd; - compinfo->width = cmpt->width; - compinfo->height = cmpt->height; - compinfo->hstep = cmpt->hstep; - compinfo->vstep = cmpt->vstep; - } - - if (!(dec->image = jas_image_create(dec->numcomps, compinfos, - JAS_IMAGE_CS_UNKNOWN))) { - return -1; - } - jas_free(compinfos); - - /* Is the packet header information stored in PPM marker segments in - the main header? */ - if (dec->ppmstab) { - /* Convert the PPM marker segment data into a collection of streams - (one stream per tile-part). */ - if (!(dec->pkthdrstreams = jpc_ppmstabtostreams(dec->ppmstab))) { - abort(); - } - jpc_ppxstab_destroy(dec->ppmstab); - dec->ppmstab = 0; - } - } - - if (sot->len > 0) { - dec->curtileendoff = jas_stream_getrwcount(dec->in) - ms->len - - 4 + sot->len; - } else { - dec->curtileendoff = 0; - } - - if (sot->tileno > dec->numtiles) { - fprintf(stderr, "invalid tile number in SOT marker segment\n"); - return -1; - } - /* Set the current tile. */ - dec->curtile = &dec->tiles[sot->tileno]; - tile = dec->curtile; - /* Ensure that this is the expected part number. */ - if (sot->partno != tile->partno) { - return -1; - } - if (tile->numparts > 0 && sot->partno >= tile->numparts) { - return -1; - } - if (!tile->numparts && sot->numparts > 0) { - tile->numparts = sot->numparts; - } - - tile->pptstab = 0; - - switch (tile->state) { - case JPC_TILE_INIT: - /* This is the first tile-part for this tile. */ - tile->state = JPC_TILE_ACTIVE; - assert(!tile->cp); - if (!(tile->cp = jpc_dec_cp_copy(dec->cp))) { - return -1; - } - jpc_dec_cp_resetflags(dec->cp); - break; - default: - if (sot->numparts == sot->partno - 1) { - tile->state = JPC_TILE_ACTIVELAST; - } - break; - } - - /* Note: We do not increment the expected tile-part number until - all processing for this tile-part is complete. */ - - /* We should expect to encounter other tile-part header marker - segments next. */ - dec->state = JPC_TPH; - - return 0; -} - -static int jpc_dec_process_sod(jpc_dec_t *dec, jpc_ms_t *ms) -{ - jpc_dec_tile_t *tile; - int pos; - - if (!(tile = dec->curtile)) { - return -1; - } - - if (!tile->partno) { - if (!jpc_dec_cp_isvalid(tile->cp)) { - return -1; - } - jpc_dec_cp_prepare(tile->cp); - if (jpc_dec_tileinit(dec, tile)) { - return -1; - } - } - - /* Are packet headers stored in the main header or tile-part header? */ - if (dec->pkthdrstreams) { - /* Get the stream containing the packet header data for this - tile-part. */ - if (!(tile->pkthdrstream = jpc_streamlist_remove(dec->pkthdrstreams, 0))) { - return -1; - } - } - - if (tile->pptstab) { - if (!tile->pkthdrstream) { - if (!(tile->pkthdrstream = jas_stream_memopen(0, 0))) { - return -1; - } - } - pos = jas_stream_tell(tile->pkthdrstream); - jas_stream_seek(tile->pkthdrstream, 0, SEEK_END); - if (jpc_pptstabwrite(tile->pkthdrstream, tile->pptstab)) { - return -1; - } - jas_stream_seek(tile->pkthdrstream, pos, SEEK_SET); - jpc_ppxstab_destroy(tile->pptstab); - tile->pptstab = 0; - } - - if (jas_getdbglevel() >= 10) { - jpc_dec_dump(dec, stderr); - } - - if (jpc_dec_decodepkts(dec, (tile->pkthdrstream) ? tile->pkthdrstream : - dec->in, dec->in)) { - fprintf(stderr, "jpc_dec_decodepkts failed\n"); - return -1; - } - - /* Gobble any unconsumed tile data. */ - if (dec->curtileendoff > 0) { - uint_fast32_t curoff; - uint_fast32_t n; - curoff = jas_stream_getrwcount(dec->in); - if (curoff < dec->curtileendoff) { - n = dec->curtileendoff - curoff; - fprintf(stderr, - "warning: ignoring trailing garbage (%lu bytes)\n", - (unsigned long) n); - - while (n-- > 0) { - if (jas_stream_getc(dec->in) == EOF) { - fprintf(stderr, "read error\n"); - return -1; - } - } - } else if (curoff > dec->curtileendoff) { - fprintf(stderr, - "warning: not enough tile data (%lu bytes)\n", - (unsigned long) curoff - dec->curtileendoff); - } - - } - - if (tile->numparts > 0 && tile->partno == tile->numparts - 1) { - if (jpc_dec_tiledecode(dec, tile)) { - return -1; - } - jpc_dec_tilefini(dec, tile); - } - - dec->curtile = 0; - - /* Increment the expected tile-part number. */ - ++tile->partno; - - /* We should expect to encounter a SOT marker segment next. */ - dec->state = JPC_TPHSOT; - - return 0; -} - -static int jpc_dec_tileinit(jpc_dec_t *dec, jpc_dec_tile_t *tile) -{ - jpc_dec_tcomp_t *tcomp; - uint_fast16_t compno; - int rlvlno; - jpc_dec_rlvl_t *rlvl; - jpc_dec_band_t *band; - jpc_dec_prc_t *prc; - int bndno; - jpc_tsfb_band_t *bnd; - int bandno; - jpc_dec_ccp_t *ccp; - int prccnt; - jpc_dec_cblk_t *cblk; - int cblkcnt; - uint_fast32_t tlprcxstart; - uint_fast32_t tlprcystart; - uint_fast32_t brprcxend; - uint_fast32_t brprcyend; - uint_fast32_t tlcbgxstart; - uint_fast32_t tlcbgystart; - uint_fast32_t brcbgxend; - uint_fast32_t cbgxstart; - uint_fast32_t cbgystart; - uint_fast32_t cbgxend; - uint_fast32_t cbgyend; - uint_fast32_t tlcblkxstart; - uint_fast32_t tlcblkystart; - uint_fast32_t brcblkxend; - uint_fast32_t brcblkyend; - uint_fast32_t cblkxstart; - uint_fast32_t cblkystart; - uint_fast32_t cblkxend; - uint_fast32_t cblkyend; - uint_fast32_t tmpxstart; - uint_fast32_t tmpystart; - uint_fast32_t tmpxend; - uint_fast32_t tmpyend; - jpc_dec_cp_t *cp; - jpc_tsfb_band_t bnds[64]; - jpc_pchg_t *pchg; - int pchgno; - jpc_dec_cmpt_t *cmpt; - - cp = tile->cp; - tile->realmode = 0; - if (cp->mctid == JPC_MCT_ICT) { - tile->realmode = 1; - } - - for (compno = 0, tcomp = tile->tcomps, cmpt = dec->cmpts; compno < - dec->numcomps; ++compno, ++tcomp, ++cmpt) { - ccp = &tile->cp->ccps[compno]; - if (ccp->qmfbid == JPC_COX_INS) { - tile->realmode = 1; - } - tcomp->numrlvls = ccp->numrlvls; - if (!(tcomp->rlvls = jas_malloc(tcomp->numrlvls * - sizeof(jpc_dec_rlvl_t)))) { - return -1; - } - if (!(tcomp->data = jas_seq2d_create(JPC_CEILDIV(tile->xstart, - cmpt->hstep), JPC_CEILDIV(tile->ystart, cmpt->vstep), - JPC_CEILDIV(tile->xend, cmpt->hstep), JPC_CEILDIV(tile->yend, - cmpt->vstep)))) { - return -1; - } - if (!(tcomp->tsfb = jpc_cod_gettsfb(ccp->qmfbid, - tcomp->numrlvls - 1))) { - return -1; - } -{ - jpc_tsfb_getbands(tcomp->tsfb, jas_seq2d_xstart(tcomp->data), jas_seq2d_ystart(tcomp->data), jas_seq2d_xend(tcomp->data), jas_seq2d_yend(tcomp->data), bnds); -} - for (rlvlno = 0, rlvl = tcomp->rlvls; rlvlno < tcomp->numrlvls; - ++rlvlno, ++rlvl) { -rlvl->bands = 0; - rlvl->xstart = JPC_CEILDIVPOW2(tcomp->xstart, - tcomp->numrlvls - 1 - rlvlno); - rlvl->ystart = JPC_CEILDIVPOW2(tcomp->ystart, - tcomp->numrlvls - 1 - rlvlno); - rlvl->xend = JPC_CEILDIVPOW2(tcomp->xend, - tcomp->numrlvls - 1 - rlvlno); - rlvl->yend = JPC_CEILDIVPOW2(tcomp->yend, - tcomp->numrlvls - 1 - rlvlno); - rlvl->prcwidthexpn = ccp->prcwidthexpns[rlvlno]; - rlvl->prcheightexpn = ccp->prcheightexpns[rlvlno]; - tlprcxstart = JPC_FLOORDIVPOW2(rlvl->xstart, - rlvl->prcwidthexpn) << rlvl->prcwidthexpn; - tlprcystart = JPC_FLOORDIVPOW2(rlvl->ystart, - rlvl->prcheightexpn) << rlvl->prcheightexpn; - brprcxend = JPC_CEILDIVPOW2(rlvl->xend, - rlvl->prcwidthexpn) << rlvl->prcwidthexpn; - brprcyend = JPC_CEILDIVPOW2(rlvl->yend, - rlvl->prcheightexpn) << rlvl->prcheightexpn; - rlvl->numhprcs = (brprcxend - tlprcxstart) >> - rlvl->prcwidthexpn; - rlvl->numvprcs = (brprcyend - tlprcystart) >> - rlvl->prcheightexpn; - rlvl->numprcs = rlvl->numhprcs * rlvl->numvprcs; - - if (rlvl->xstart >= rlvl->xend || rlvl->ystart >= rlvl->yend) { - rlvl->bands = 0; - rlvl->numprcs = 0; - rlvl->numhprcs = 0; - rlvl->numvprcs = 0; - continue; - } - if (!rlvlno) { - tlcbgxstart = tlprcxstart; - tlcbgystart = tlprcystart; - brcbgxend = brprcxend; - rlvl->cbgwidthexpn = rlvl->prcwidthexpn; - rlvl->cbgheightexpn = rlvl->prcheightexpn; - } else { - tlcbgxstart = JPC_CEILDIVPOW2(tlprcxstart, 1); - tlcbgystart = JPC_CEILDIVPOW2(tlprcystart, 1); - brcbgxend = JPC_CEILDIVPOW2(brprcxend, 1); - rlvl->cbgwidthexpn = rlvl->prcwidthexpn - 1; - rlvl->cbgheightexpn = rlvl->prcheightexpn - 1; - } - rlvl->cblkwidthexpn = JAS_MIN(ccp->cblkwidthexpn, - rlvl->cbgwidthexpn); - rlvl->cblkheightexpn = JAS_MIN(ccp->cblkheightexpn, - rlvl->cbgheightexpn); - - rlvl->numbands = (!rlvlno) ? 1 : 3; - if (!(rlvl->bands = jas_malloc(rlvl->numbands * - sizeof(jpc_dec_band_t)))) { - return -1; - } - for (bandno = 0, band = rlvl->bands; - bandno < rlvl->numbands; ++bandno, ++band) { - bndno = (!rlvlno) ? 0 : (3 * (rlvlno - 1) + - bandno + 1); - bnd = &bnds[bndno]; - - band->orient = bnd->orient; - band->stepsize = ccp->stepsizes[bndno]; - band->analgain = JPC_NOMINALGAIN(ccp->qmfbid, - tcomp->numrlvls - 1, rlvlno, band->orient); - band->absstepsize = jpc_calcabsstepsize(band->stepsize, - cmpt->prec + band->analgain); - band->numbps = ccp->numguardbits + - JPC_QCX_GETEXPN(band->stepsize) - 1; - band->roishift = (ccp->roishift + band->numbps >= JPC_PREC) ? - (JPC_PREC - 1 - band->numbps) : ccp->roishift; - band->data = 0; - band->prcs = 0; - if (bnd->xstart == bnd->xend || bnd->ystart == bnd->yend) { - continue; - } - if (!(band->data = jas_seq2d_create(0, 0, 0, 0))) { - return -1; - } - jas_seq2d_bindsub(band->data, tcomp->data, bnd->locxstart, bnd->locystart, bnd->locxend, bnd->locyend); - jas_seq2d_setshift(band->data, bnd->xstart, bnd->ystart); - - assert(rlvl->numprcs); - - if (!(band->prcs = jas_malloc(rlvl->numprcs * sizeof(jpc_dec_prc_t)))) { - return -1; - } - -/************************************************/ - cbgxstart = tlcbgxstart; - cbgystart = tlcbgystart; - for (prccnt = rlvl->numprcs, prc = band->prcs; - prccnt > 0; --prccnt, ++prc) { - cbgxend = cbgxstart + (1 << rlvl->cbgwidthexpn); - cbgyend = cbgystart + (1 << rlvl->cbgheightexpn); - prc->xstart = JAS_MAX(cbgxstart, jas_seq2d_xstart(band->data)); - prc->ystart = JAS_MAX(cbgystart, jas_seq2d_ystart(band->data)); - prc->xend = JAS_MIN(cbgxend, jas_seq2d_xend(band->data)); - prc->yend = JAS_MIN(cbgyend, jas_seq2d_yend(band->data)); - if (prc->xend > prc->xstart && prc->yend > prc->ystart) { - tlcblkxstart = JPC_FLOORDIVPOW2(prc->xstart, - rlvl->cblkwidthexpn) << rlvl->cblkwidthexpn; - tlcblkystart = JPC_FLOORDIVPOW2(prc->ystart, - rlvl->cblkheightexpn) << rlvl->cblkheightexpn; - brcblkxend = JPC_CEILDIVPOW2U(prc->xend, - rlvl->cblkwidthexpn) << rlvl->cblkwidthexpn; - brcblkyend = JPC_CEILDIVPOW2U(prc->yend, - rlvl->cblkheightexpn) << rlvl->cblkheightexpn; - prc->numhcblks = (brcblkxend - tlcblkxstart) >> - rlvl->cblkwidthexpn; - prc->numvcblks = (brcblkyend - tlcblkystart) >> - rlvl->cblkheightexpn; - prc->numcblks = prc->numhcblks * prc->numvcblks; - assert(prc->numcblks > 0); - - if (!(prc->incltagtree = jpc_tagtree_create(prc->numhcblks, prc->numvcblks))) { - return -1; - } - if (!(prc->numimsbstagtree = jpc_tagtree_create(prc->numhcblks, prc->numvcblks))) { - return -1; - } - if (!(prc->cblks = jas_malloc(prc->numcblks * sizeof(jpc_dec_cblk_t)))) { - return -1; - } - - cblkxstart = cbgxstart; - cblkystart = cbgystart; - for (cblkcnt = prc->numcblks, cblk = prc->cblks; cblkcnt > 0;) { - cblkxend = cblkxstart + (1 << rlvl->cblkwidthexpn); - cblkyend = cblkystart + (1 << rlvl->cblkheightexpn); - tmpxstart = JAS_MAX(cblkxstart, prc->xstart); - tmpystart = JAS_MAX(cblkystart, prc->ystart); - tmpxend = JAS_MIN(cblkxend, prc->xend); - tmpyend = JAS_MIN(cblkyend, prc->yend); - if (tmpxend > tmpxstart && tmpyend > tmpystart) { - cblk->firstpassno = -1; - cblk->mqdec = 0; - cblk->nulldec = 0; - cblk->flags = 0; - cblk->numpasses = 0; - cblk->segs.head = 0; - cblk->segs.tail = 0; - cblk->curseg = 0; - cblk->numimsbs = 0; - cblk->numlenbits = 3; - cblk->flags = 0; - if (!(cblk->data = jas_seq2d_create(0, 0, 0, 0))) { - return -1; - } - jas_seq2d_bindsub(cblk->data, band->data, tmpxstart, tmpystart, tmpxend, tmpyend); - ++cblk; - --cblkcnt; - } - cblkxstart += 1 << rlvl->cblkwidthexpn; - if (cblkxstart >= cbgxend) { - cblkxstart = cbgxstart; - cblkystart += 1 << rlvl->cblkheightexpn; - } - } - - } else { - prc->cblks = 0; - prc->incltagtree = 0; - prc->numimsbstagtree = 0; - } - cbgxstart += 1 << rlvl->cbgwidthexpn; - if (cbgxstart >= brcbgxend) { - cbgxstart = tlcbgxstart; - cbgystart += 1 << rlvl->cbgheightexpn; - } - - } -/********************************************/ - } - } - } - -if (!(tile->pi = jpc_dec_pi_create(dec, tile))) -{ - return -1; -} - - for (pchgno = 0; pchgno < jpc_pchglist_numpchgs(tile->cp->pchglist); - ++pchgno) { - pchg = jpc_pchg_copy(jpc_pchglist_get(tile->cp->pchglist, pchgno)); - assert(pchg); - jpc_pi_addpchg(tile->pi, pchg); - } - jpc_pi_init(tile->pi); - - return 0; -} - -static int jpc_dec_tilefini(jpc_dec_t *dec, jpc_dec_tile_t *tile) -{ - jpc_dec_tcomp_t *tcomp; - int compno; - int bandno; - int rlvlno; - jpc_dec_band_t *band; - jpc_dec_rlvl_t *rlvl; - int prcno; - jpc_dec_prc_t *prc; - jpc_dec_seg_t *seg; - jpc_dec_cblk_t *cblk; - int cblkno; - -if (tile->tcomps) { - - for (compno = 0, tcomp = tile->tcomps; compno < dec->numcomps; - ++compno, ++tcomp) { - for (rlvlno = 0, rlvl = tcomp->rlvls; rlvlno < tcomp->numrlvls; - ++rlvlno, ++rlvl) { -if (!rlvl->bands) { - continue; -} - for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands; ++bandno, ++band) { -if (band->prcs) { - for (prcno = 0, prc = band->prcs; prcno < - rlvl->numprcs; ++prcno, ++prc) { -if (!prc->cblks) { - continue; -} - for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks; ++cblkno, ++cblk) { - - while (cblk->segs.head) { - seg = cblk->segs.head; - jpc_seglist_remove(&cblk->segs, seg); - jpc_seg_destroy(seg); - } - jas_matrix_destroy(cblk->data); - if (cblk->mqdec) { - jpc_mqdec_destroy(cblk->mqdec); - } - if (cblk->nulldec) { - jpc_bitstream_close(cblk->nulldec); - } - if (cblk->flags) { - jas_matrix_destroy(cblk->flags); - } - } - if (prc->incltagtree) { - jpc_tagtree_destroy(prc->incltagtree); - } - if (prc->numimsbstagtree) { - jpc_tagtree_destroy(prc->numimsbstagtree); - } - if (prc->cblks) { - jas_free(prc->cblks); - } - } -} - if (band->data) { - jas_matrix_destroy(band->data); - } - if (band->prcs) { - jas_free(band->prcs); - } - } - if (rlvl->bands) { - jas_free(rlvl->bands); - } - } - if (tcomp->rlvls) { - jas_free(tcomp->rlvls); - } - if (tcomp->data) { - jas_matrix_destroy(tcomp->data); - } - if (tcomp->tsfb) { - jpc_tsfb_destroy(tcomp->tsfb); - } - } -} - if (tile->cp) { - jpc_dec_cp_destroy(tile->cp); - tile->cp = 0; - } - if (tile->tcomps) { - jas_free(tile->tcomps); - tile->tcomps = 0; - } - if (tile->pi) { - jpc_pi_destroy(tile->pi); - tile->pi = 0; - } - if (tile->pkthdrstream) { - jas_stream_close(tile->pkthdrstream); - tile->pkthdrstream = 0; - } - if (tile->pptstab) { - jpc_ppxstab_destroy(tile->pptstab); - tile->pptstab = 0; - } - - tile->state = JPC_TILE_DONE; - - return 0; -} - -static int jpc_dec_tiledecode(jpc_dec_t *dec, jpc_dec_tile_t *tile) -{ - int i; - int j; - jpc_dec_tcomp_t *tcomp; - jpc_dec_rlvl_t *rlvl; - jpc_dec_band_t *band; - int compno; - int rlvlno; - int bandno; - int adjust; - int v; - jpc_dec_ccp_t *ccp; - jpc_dec_cmpt_t *cmpt; - - if (jpc_dec_decodecblks(dec, tile)) { - fprintf(stderr, "jpc_dec_decodecblks failed\n"); - return -1; - } - - /* Perform dequantization. */ - for (compno = 0, tcomp = tile->tcomps; compno < dec->numcomps; - ++compno, ++tcomp) { - ccp = &tile->cp->ccps[compno]; - for (rlvlno = 0, rlvl = tcomp->rlvls; rlvlno < tcomp->numrlvls; - ++rlvlno, ++rlvl) { - if (!rlvl->bands) { - continue; - } - for (bandno = 0, band = rlvl->bands; - bandno < rlvl->numbands; ++bandno, ++band) { - if (!band->data) { - continue; - } - jpc_undo_roi(band->data, band->roishift, ccp->roishift - - band->roishift, band->numbps); - if (tile->realmode) { - jas_matrix_asl(band->data, JPC_FIX_FRACBITS); - jpc_dequantize(band->data, band->absstepsize); - } - - } - } - } - - /* Apply an inverse wavelet transform if necessary. */ - for (compno = 0, tcomp = tile->tcomps; compno < dec->numcomps; - ++compno, ++tcomp) { - ccp = &tile->cp->ccps[compno]; - jpc_tsfb_synthesize(tcomp->tsfb, ((ccp->qmfbid == - JPC_COX_RFT) ? JPC_TSFB_RITIMODE : 0), tcomp->data); - } - - - /* Apply an inverse intercomponent transform if necessary. */ - switch (tile->cp->mctid) { - case JPC_MCT_RCT: - assert(dec->numcomps == 3); - jpc_irct(tile->tcomps[0].data, tile->tcomps[1].data, - tile->tcomps[2].data); - break; - case JPC_MCT_ICT: - assert(dec->numcomps == 3); - jpc_iict(tile->tcomps[0].data, tile->tcomps[1].data, - tile->tcomps[2].data); - break; - } - - /* Perform rounding and convert to integer values. */ - if (tile->realmode) { - for (compno = 0, tcomp = tile->tcomps; compno < dec->numcomps; - ++compno, ++tcomp) { - for (i = 0; i < jas_matrix_numrows(tcomp->data); ++i) { - for (j = 0; j < jas_matrix_numcols(tcomp->data); ++j) { - v = jas_matrix_get(tcomp->data, i, j); - v = jpc_fix_round(v); - jas_matrix_set(tcomp->data, i, j, jpc_fixtoint(v)); - } - } - } - } - - /* Perform level shift. */ - for (compno = 0, tcomp = tile->tcomps, cmpt = dec->cmpts; compno < - dec->numcomps; ++compno, ++tcomp, ++cmpt) { - adjust = cmpt->sgnd ? 0 : (1 << (cmpt->prec - 1)); - for (i = 0; i < jas_matrix_numrows(tcomp->data); ++i) { - for (j = 0; j < jas_matrix_numcols(tcomp->data); ++j) { - *jas_matrix_getref(tcomp->data, i, j) += adjust; - } - } - } - - /* Perform clipping. */ - for (compno = 0, tcomp = tile->tcomps, cmpt = dec->cmpts; compno < - dec->numcomps; ++compno, ++tcomp, ++cmpt) { - jpc_fix_t mn; - jpc_fix_t mx; - mn = cmpt->sgnd ? (-(1 << (cmpt->prec - 1))) : (0); - mx = cmpt->sgnd ? ((1 << (cmpt->prec - 1)) - 1) : ((1 << - cmpt->prec) - 1); - jas_matrix_clip(tcomp->data, mn, mx); - } - - /* XXX need to free tsfb struct */ - - /* Write the data for each component of the image. */ - for (compno = 0, tcomp = tile->tcomps, cmpt = dec->cmpts; compno < - dec->numcomps; ++compno, ++tcomp, ++cmpt) { - if (jas_image_writecmpt(dec->image, compno, tcomp->xstart - - JPC_CEILDIV(dec->xstart, cmpt->hstep), tcomp->ystart - - JPC_CEILDIV(dec->ystart, cmpt->vstep), jas_matrix_numcols( - tcomp->data), jas_matrix_numrows(tcomp->data), tcomp->data)) { - fprintf(stderr, "write component failed\n"); - return -4; - } - } - - return 0; -} - -static int jpc_dec_process_eoc(jpc_dec_t *dec, jpc_ms_t *ms) -{ - int tileno; - jpc_dec_tile_t *tile; - for (tileno = 0, tile = dec->tiles; tileno < dec->numtiles; ++tileno, - ++tile) { - if (tile->state == JPC_TILE_ACTIVE) { - if (jpc_dec_tiledecode(dec, tile)) { - return -1; - } - } - jpc_dec_tilefini(dec, tile); - } - - /* We are done processing the code stream. */ - dec->state = JPC_MT; - - return 1; -} - -static int jpc_dec_process_siz(jpc_dec_t *dec, jpc_ms_t *ms) -{ - jpc_siz_t *siz = &ms->parms.siz; - uint_fast16_t compno; - uint_fast32_t tileno; - jpc_dec_tile_t *tile; - jpc_dec_tcomp_t *tcomp; - uint_fast32_t htileno; - uint_fast32_t vtileno; - jpc_dec_cmpt_t *cmpt; - - dec->xstart = siz->xoff; - dec->ystart = siz->yoff; - dec->xend = siz->width; - dec->yend = siz->height; - dec->tilewidth = siz->tilewidth; - dec->tileheight = siz->tileheight; - dec->tilexoff = siz->tilexoff; - dec->tileyoff = siz->tileyoff; - dec->numcomps = siz->numcomps; - if (!(dec->cp = jpc_dec_cp_create(dec->numcomps))) { - return -1; - } - - if (!(dec->cmpts = jas_malloc(dec->numcomps * sizeof(jpc_dec_cmpt_t)))) { - return -1; - } - - for (compno = 0, cmpt = dec->cmpts; compno < dec->numcomps; ++compno, - ++cmpt) { - cmpt->prec = siz->comps[compno].prec; - cmpt->sgnd = siz->comps[compno].sgnd; - cmpt->hstep = siz->comps[compno].hsamp; - cmpt->vstep = siz->comps[compno].vsamp; - cmpt->width = JPC_CEILDIV(dec->xend, cmpt->hstep) - - JPC_CEILDIV(dec->xstart, cmpt->hstep); - cmpt->height = JPC_CEILDIV(dec->yend, cmpt->vstep) - - JPC_CEILDIV(dec->ystart, cmpt->vstep); - cmpt->hsubstep = 0; - cmpt->vsubstep = 0; - } - - dec->image = 0; - - dec->numhtiles = JPC_CEILDIV(dec->xend - dec->tilexoff, dec->tilewidth); - dec->numvtiles = JPC_CEILDIV(dec->yend - dec->tileyoff, dec->tileheight); - dec->numtiles = dec->numhtiles * dec->numvtiles; - if (!(dec->tiles = jas_malloc(dec->numtiles * sizeof(jpc_dec_tile_t)))) { - return -1; - } - - for (tileno = 0, tile = dec->tiles; tileno < dec->numtiles; ++tileno, - ++tile) { - htileno = tileno % dec->numhtiles; - vtileno = tileno / dec->numhtiles; - tile->realmode = 0; - tile->state = JPC_TILE_INIT; - tile->xstart = JAS_MAX(dec->tilexoff + htileno * dec->tilewidth, - dec->xstart); - tile->ystart = JAS_MAX(dec->tileyoff + vtileno * dec->tileheight, - dec->ystart); - tile->xend = JAS_MIN(dec->tilexoff + (htileno + 1) * - dec->tilewidth, dec->xend); - tile->yend = JAS_MIN(dec->tileyoff + (vtileno + 1) * - dec->tileheight, dec->yend); - tile->numparts = 0; - tile->partno = 0; - tile->pkthdrstream = 0; - tile->pkthdrstreampos = 0; - tile->pptstab = 0; - tile->cp = 0; - if (!(tile->tcomps = jas_malloc(dec->numcomps * - sizeof(jpc_dec_tcomp_t)))) { - return -1; - } - for (compno = 0, cmpt = dec->cmpts, tcomp = tile->tcomps; - compno < dec->numcomps; ++compno, ++cmpt, ++tcomp) { - tcomp->rlvls = 0; - tcomp->data = 0; - tcomp->xstart = JPC_CEILDIV(tile->xstart, cmpt->hstep); - tcomp->ystart = JPC_CEILDIV(tile->ystart, cmpt->vstep); - tcomp->xend = JPC_CEILDIV(tile->xend, cmpt->hstep); - tcomp->yend = JPC_CEILDIV(tile->yend, cmpt->vstep); - tcomp->tsfb = 0; - } - } - - dec->pkthdrstreams = 0; - - /* We should expect to encounter other main header marker segments - or an SOT marker segment next. */ - dec->state = JPC_MH; - - return 0; -} - -static int jpc_dec_process_cod(jpc_dec_t *dec, jpc_ms_t *ms) -{ - jpc_cod_t *cod = &ms->parms.cod; - jpc_dec_tile_t *tile; - - switch (dec->state) { - case JPC_MH: - jpc_dec_cp_setfromcod(dec->cp, cod); - break; - case JPC_TPH: - if (!(tile = dec->curtile)) { - return -1; - } - if (tile->partno != 0) { - return -1; - } - jpc_dec_cp_setfromcod(tile->cp, cod); - break; - } - return 0; -} - -static int jpc_dec_process_coc(jpc_dec_t *dec, jpc_ms_t *ms) -{ - jpc_coc_t *coc = &ms->parms.coc; - jpc_dec_tile_t *tile; - - if (coc->compno > dec->numcomps) { - fprintf(stderr, - "invalid component number in COC marker segment\n"); - return -1; - } - switch (dec->state) { - case JPC_MH: - jpc_dec_cp_setfromcoc(dec->cp, coc); - break; - case JPC_TPH: - if (!(tile = dec->curtile)) { - return -1; - } - if (tile->partno > 0) { - return -1; - } - jpc_dec_cp_setfromcoc(tile->cp, coc); - break; - } - return 0; -} - -static int jpc_dec_process_rgn(jpc_dec_t *dec, jpc_ms_t *ms) -{ - jpc_rgn_t *rgn = &ms->parms.rgn; - jpc_dec_tile_t *tile; - - if (rgn->compno > dec->numcomps) { - fprintf(stderr, - "invalid component number in RGN marker segment\n"); - return -1; - } - switch (dec->state) { - case JPC_MH: - jpc_dec_cp_setfromrgn(dec->cp, rgn); - break; - case JPC_TPH: - if (!(tile = dec->curtile)) { - return -1; - } - if (tile->partno > 0) { - return -1; - } - jpc_dec_cp_setfromrgn(tile->cp, rgn); - break; - } - - return 0; -} - -static int jpc_dec_process_qcd(jpc_dec_t *dec, jpc_ms_t *ms) -{ - jpc_qcd_t *qcd = &ms->parms.qcd; - jpc_dec_tile_t *tile; - - switch (dec->state) { - case JPC_MH: - jpc_dec_cp_setfromqcd(dec->cp, qcd); - break; - case JPC_TPH: - if (!(tile = dec->curtile)) { - return -1; - } - if (tile->partno > 0) { - return -1; - } - jpc_dec_cp_setfromqcd(tile->cp, qcd); - break; - } - return 0; -} - -static int jpc_dec_process_qcc(jpc_dec_t *dec, jpc_ms_t *ms) -{ - jpc_qcc_t *qcc = &ms->parms.qcc; - jpc_dec_tile_t *tile; - - if (qcc->compno > dec->numcomps) { - fprintf(stderr, - "invalid component number in QCC marker segment\n"); - return -1; - } - switch (dec->state) { - case JPC_MH: - jpc_dec_cp_setfromqcc(dec->cp, qcc); - break; - case JPC_TPH: - if (!(tile = dec->curtile)) { - return -1; - } - if (tile->partno > 0) { - return -1; - } - jpc_dec_cp_setfromqcc(tile->cp, qcc); - break; - } - return 0; -} - -static int jpc_dec_process_poc(jpc_dec_t *dec, jpc_ms_t *ms) -{ - jpc_poc_t *poc = &ms->parms.poc; - jpc_dec_tile_t *tile; - switch (dec->state) { - case JPC_MH: - if (jpc_dec_cp_setfrompoc(dec->cp, poc, 1)) { - return -1; - } - break; - case JPC_TPH: - if (!(tile = dec->curtile)) { - return -1; - } - if (!tile->partno) { - if (jpc_dec_cp_setfrompoc(tile->cp, poc, (!tile->partno))) { - return -1; - } - } else { - jpc_pi_addpchgfrompoc(tile->pi, poc); - } - break; - } - return 0; -} - -static int jpc_dec_process_ppm(jpc_dec_t *dec, jpc_ms_t *ms) -{ - jpc_ppm_t *ppm = &ms->parms.ppm; - jpc_ppxstabent_t *ppmstabent; - - if (!dec->ppmstab) { - if (!(dec->ppmstab = jpc_ppxstab_create())) { - return -1; - } - } - - if (!(ppmstabent = jpc_ppxstabent_create())) { - return -1; - } - ppmstabent->ind = ppm->ind; - ppmstabent->data = ppm->data; - ppm->data = 0; - ppmstabent->len = ppm->len; - if (jpc_ppxstab_insert(dec->ppmstab, ppmstabent)) { - return -1; - } - return 0; -} - -static int jpc_dec_process_ppt(jpc_dec_t *dec, jpc_ms_t *ms) -{ - jpc_ppt_t *ppt = &ms->parms.ppt; - jpc_dec_tile_t *tile; - jpc_ppxstabent_t *pptstabent; - - tile = dec->curtile; - if (!tile->pptstab) { - if (!(tile->pptstab = jpc_ppxstab_create())) { - return -1; - } - } - if (!(pptstabent = jpc_ppxstabent_create())) { - return -1; - } - pptstabent->ind = ppt->ind; - pptstabent->data = ppt->data; - ppt->data = 0; - pptstabent->len = ppt->len; - if (jpc_ppxstab_insert(tile->pptstab, pptstabent)) { - return -1; - } - return 0; -} - -static int jpc_dec_process_com(jpc_dec_t *dec, jpc_ms_t *ms) -{ - return 0; -} - -static int jpc_dec_process_unk(jpc_dec_t *dec, jpc_ms_t *ms) -{ - fprintf(stderr, "warning: ignoring unknown marker segment\n"); - jpc_ms_dump(ms, stderr); - return 0; -} - -/******************************************************************************\ -* -\******************************************************************************/ - -static jpc_dec_cp_t *jpc_dec_cp_create(uint_fast16_t numcomps) -{ - jpc_dec_cp_t *cp; - jpc_dec_ccp_t *ccp; - int compno; - - if (!(cp = jas_malloc(sizeof(jpc_dec_cp_t)))) { - return 0; - } - cp->flags = 0; - cp->numcomps = numcomps; - cp->prgord = 0; - cp->numlyrs = 0; - cp->mctid = 0; - cp->csty = 0; - if (!(cp->ccps = jas_malloc(cp->numcomps * sizeof(jpc_dec_ccp_t)))) { - return 0; - } - if (!(cp->pchglist = jpc_pchglist_create())) { - jas_free(cp->ccps); - return 0; - } - for (compno = 0, ccp = cp->ccps; compno < cp->numcomps; - ++compno, ++ccp) { - ccp->flags = 0; - ccp->numrlvls = 0; - ccp->cblkwidthexpn = 0; - ccp->cblkheightexpn = 0; - ccp->qmfbid = 0; - ccp->numstepsizes = 0; - ccp->numguardbits = 0; - ccp->roishift = 0; - ccp->cblkctx = 0; - } - return cp; -} - -static jpc_dec_cp_t *jpc_dec_cp_copy(jpc_dec_cp_t *cp) -{ - jpc_dec_cp_t *newcp; - jpc_dec_ccp_t *newccp; - jpc_dec_ccp_t *ccp; - int compno; - - if (!(newcp = jpc_dec_cp_create(cp->numcomps))) { - return 0; - } - newcp->flags = cp->flags; - newcp->prgord = cp->prgord; - newcp->numlyrs = cp->numlyrs; - newcp->mctid = cp->mctid; - newcp->csty = cp->csty; - jpc_pchglist_destroy(newcp->pchglist); - newcp->pchglist = 0; - if (!(newcp->pchglist = jpc_pchglist_copy(cp->pchglist))) { - jas_free(newcp); - return 0; - } - for (compno = 0, newccp = newcp->ccps, ccp = cp->ccps; - compno < cp->numcomps; - ++compno, ++newccp, ++ccp) { - *newccp = *ccp; - } - return newcp; -} - -static void jpc_dec_cp_resetflags(jpc_dec_cp_t *cp) -{ - int compno; - jpc_dec_ccp_t *ccp; - cp->flags &= (JPC_CSET | JPC_QSET); - for (compno = 0, ccp = cp->ccps; compno < cp->numcomps; - ++compno, ++ccp) { - ccp->flags = 0; - } -} - -static void jpc_dec_cp_destroy(jpc_dec_cp_t *cp) -{ - if (cp->ccps) { - jas_free(cp->ccps); - } - if (cp->pchglist) { - jpc_pchglist_destroy(cp->pchglist); - } - jas_free(cp); -} - -static int jpc_dec_cp_isvalid(jpc_dec_cp_t *cp) -{ - uint_fast16_t compcnt; - jpc_dec_ccp_t *ccp; - - if (!(cp->flags & JPC_CSET) || !(cp->flags & JPC_QSET)) { - return 0; - } - for (compcnt = cp->numcomps, ccp = cp->ccps; compcnt > 0; --compcnt, - ++ccp) { - /* Is there enough step sizes for the number of bands? */ - if ((ccp->qsty != JPC_QCX_SIQNT && ccp->numstepsizes < 3 * - ccp->numrlvls - 2) || (ccp->qsty == JPC_QCX_SIQNT && - ccp->numstepsizes != 1)) { - return 0; - } - } - return 1; -} - -static void calcstepsizes(uint_fast16_t refstepsize, int numrlvls, - uint_fast16_t *stepsizes) -{ - int bandno; - int numbands; - uint_fast16_t expn; - uint_fast16_t mant; - expn = JPC_QCX_GETEXPN(refstepsize); - mant = JPC_QCX_GETMANT(refstepsize); - numbands = 3 * numrlvls - 2; - for (bandno = 0; bandno < numbands; ++bandno) { - stepsizes[bandno] = JPC_QCX_MANT(mant) | JPC_QCX_EXPN(expn + - (numrlvls - 1) - (numrlvls - 1 - ((bandno > 0) ? ((bandno + 2) / 3) : (0)))); - } -} - -static int jpc_dec_cp_prepare(jpc_dec_cp_t *cp) -{ - jpc_dec_ccp_t *ccp; - int compno; - int i; - for (compno = 0, ccp = cp->ccps; compno < cp->numcomps; - ++compno, ++ccp) { - if (!(ccp->csty & JPC_COX_PRT)) { - for (i = 0; i < JPC_MAXRLVLS; ++i) { - ccp->prcwidthexpns[i] = 15; - ccp->prcheightexpns[i] = 15; - } - } - if (ccp->qsty == JPC_QCX_SIQNT) { - calcstepsizes(ccp->stepsizes[0], ccp->numrlvls, ccp->stepsizes); - } - } - return 0; -} - -static int jpc_dec_cp_setfromcod(jpc_dec_cp_t *cp, jpc_cod_t *cod) -{ - jpc_dec_ccp_t *ccp; - int compno; - cp->flags |= JPC_CSET; - cp->prgord = cod->prg; - if (cod->mctrans) { - cp->mctid = (cod->compparms.qmfbid == JPC_COX_INS) ? (JPC_MCT_ICT) : (JPC_MCT_RCT); - } else { - cp->mctid = JPC_MCT_NONE; - } - cp->numlyrs = cod->numlyrs; - cp->csty = cod->csty & (JPC_COD_SOP | JPC_COD_EPH); - for (compno = 0, ccp = cp->ccps; compno < cp->numcomps; - ++compno, ++ccp) { - jpc_dec_cp_setfromcox(cp, ccp, &cod->compparms, 0); - } - cp->flags |= JPC_CSET; - return 0; -} - -static int jpc_dec_cp_setfromcoc(jpc_dec_cp_t *cp, jpc_coc_t *coc) -{ - jpc_dec_cp_setfromcox(cp, &cp->ccps[coc->compno], &coc->compparms, JPC_COC); - return 0; -} - -static int jpc_dec_cp_setfromcox(jpc_dec_cp_t *cp, jpc_dec_ccp_t *ccp, - jpc_coxcp_t *compparms, int flags) -{ - int rlvlno; - if ((flags & JPC_COC) || !(ccp->flags & JPC_COC)) { - ccp->numrlvls = compparms->numdlvls + 1; - ccp->cblkwidthexpn = JPC_COX_GETCBLKSIZEEXPN( - compparms->cblkwidthval); - ccp->cblkheightexpn = JPC_COX_GETCBLKSIZEEXPN( - compparms->cblkheightval); - ccp->qmfbid = compparms->qmfbid; - ccp->cblkctx = compparms->cblksty; - ccp->csty = compparms->csty & JPC_COX_PRT; - for (rlvlno = 0; rlvlno < compparms->numrlvls; ++rlvlno) { - ccp->prcwidthexpns[rlvlno] = - compparms->rlvls[rlvlno].parwidthval; - ccp->prcheightexpns[rlvlno] = - compparms->rlvls[rlvlno].parheightval; - } - ccp->flags |= flags | JPC_CSET; - } - return 0; -} - -static int jpc_dec_cp_setfromqcd(jpc_dec_cp_t *cp, jpc_qcd_t *qcd) -{ - int compno; - jpc_dec_ccp_t *ccp; - for (compno = 0, ccp = cp->ccps; compno < cp->numcomps; - ++compno, ++ccp) { - jpc_dec_cp_setfromqcx(cp, ccp, &qcd->compparms, 0); - } - cp->flags |= JPC_QSET; - return 0; -} - -static int jpc_dec_cp_setfromqcc(jpc_dec_cp_t *cp, jpc_qcc_t *qcc) -{ - return jpc_dec_cp_setfromqcx(cp, &cp->ccps[qcc->compno], &qcc->compparms, JPC_QCC); -} - -static int jpc_dec_cp_setfromqcx(jpc_dec_cp_t *cp, jpc_dec_ccp_t *ccp, - jpc_qcxcp_t *compparms, int flags) -{ - int bandno; - if ((flags & JPC_QCC) || !(ccp->flags & JPC_QCC)) { - ccp->flags |= flags | JPC_QSET; - for (bandno = 0; bandno < compparms->numstepsizes; ++bandno) { - ccp->stepsizes[bandno] = compparms->stepsizes[bandno]; - } - ccp->numstepsizes = compparms->numstepsizes; - ccp->numguardbits = compparms->numguard; - ccp->qsty = compparms->qntsty; - } - return 0; -} - -static int jpc_dec_cp_setfromrgn(jpc_dec_cp_t *cp, jpc_rgn_t *rgn) -{ - jpc_dec_ccp_t *ccp; - ccp = &cp->ccps[rgn->compno]; - ccp->roishift = rgn->roishift; - return 0; -} - -static int jpc_pi_addpchgfrompoc(jpc_pi_t *pi, jpc_poc_t *poc) -{ - int pchgno; - jpc_pchg_t *pchg; - for (pchgno = 0; pchgno < poc->numpchgs; ++pchgno) { - if (!(pchg = jpc_pchg_copy(&poc->pchgs[pchgno]))) { - return -1; - } - if (jpc_pchglist_insert(pi->pchglist, -1, pchg)) { - return -1; - } - } - return 0; -} - -static int jpc_dec_cp_setfrompoc(jpc_dec_cp_t *cp, jpc_poc_t *poc, int reset) -{ - int pchgno; - jpc_pchg_t *pchg; - if (reset) { - while (jpc_pchglist_numpchgs(cp->pchglist) > 0) { - pchg = jpc_pchglist_remove(cp->pchglist, 0); - jpc_pchg_destroy(pchg); - } - } - for (pchgno = 0; pchgno < poc->numpchgs; ++pchgno) { - if (!(pchg = jpc_pchg_copy(&poc->pchgs[pchgno]))) { - return -1; - } - if (jpc_pchglist_insert(cp->pchglist, -1, pchg)) { - return -1; - } - } - return 0; -} - -static jpc_fix_t jpc_calcabsstepsize(int stepsize, int numbits) -{ - jpc_fix_t absstepsize; - int n; - - absstepsize = jpc_inttofix(1); - n = JPC_FIX_FRACBITS - 11; - absstepsize |= (n >= 0) ? (JPC_QCX_GETMANT(stepsize) << n) : - (JPC_QCX_GETMANT(stepsize) >> (-n)); - n = numbits - JPC_QCX_GETEXPN(stepsize); - absstepsize = (n >= 0) ? (absstepsize << n) : (absstepsize >> (-n)); - return absstepsize; -} - -static void jpc_dequantize(jas_matrix_t *x, jpc_fix_t absstepsize) -{ - int i; - int j; - int t; - - assert(absstepsize >= 0); - if (absstepsize == jpc_inttofix(1)) { - return; - } - - for (i = 0; i < jas_matrix_numrows(x); ++i) { - for (j = 0; j < jas_matrix_numcols(x); ++j) { - t = jas_matrix_get(x, i, j); - if (t) { - t = jpc_fix_mul(t, absstepsize); - } else { - t = 0; - } - jas_matrix_set(x, i, j, t); - } - } - -} - -static void jpc_undo_roi(jas_matrix_t *x, int roishift, int bgshift, int numbps) -{ - int i; - int j; - int thresh; - jpc_fix_t val; - jpc_fix_t mag; - bool warn; - uint_fast32_t mask; - - if (roishift == 0 && bgshift == 0) { - return; - } - thresh = 1 << roishift; - - warn = false; - for (i = 0; i < jas_matrix_numrows(x); ++i) { - for (j = 0; j < jas_matrix_numcols(x); ++j) { - val = jas_matrix_get(x, i, j); - mag = JAS_ABS(val); - if (mag >= thresh) { - /* We are dealing with ROI data. */ - mag >>= roishift; - val = (val < 0) ? (-mag) : mag; - jas_matrix_set(x, i, j, val); - } else { - /* We are dealing with non-ROI (i.e., background) data. */ - mag <<= bgshift; - mask = (1 << numbps) - 1; - /* Perform a basic sanity check on the sample value. */ - /* Some implementations write garbage in the unused - most-significant bit planes introduced by ROI shifting. - Here we ensure that any such bits are masked off. */ - if (mag & (~mask)) { - if (!warn) { - fprintf(stderr, - "warning: possibly corrupt code stream\n"); - warn = true; - } - mag &= mask; - } - val = (val < 0) ? (-mag) : mag; - jas_matrix_set(x, i, j, val); - } - } - } -} - -static jpc_dec_t *jpc_dec_create(jpc_dec_importopts_t *impopts, jas_stream_t *in) -{ - jpc_dec_t *dec; - - if (!(dec = jas_malloc(sizeof(jpc_dec_t)))) { - return 0; - } - - dec->image = 0; - dec->xstart = 0; - dec->ystart = 0; - dec->xend = 0; - dec->yend = 0; - dec->tilewidth = 0; - dec->tileheight = 0; - dec->tilexoff = 0; - dec->tileyoff = 0; - dec->numhtiles = 0; - dec->numvtiles = 0; - dec->numtiles = 0; - dec->tiles = 0; - dec->curtile = 0; - dec->numcomps = 0; - dec->in = in; - dec->cp = 0; - dec->maxlyrs = impopts->maxlyrs; - dec->maxpkts = impopts->maxpkts; -dec->numpkts = 0; - dec->ppmseqno = 0; - dec->state = 0; - dec->cmpts = 0; - dec->pkthdrstreams = 0; - dec->ppmstab = 0; - dec->curtileendoff = 0; - - return dec; -} - -static void jpc_dec_destroy(jpc_dec_t *dec) -{ - if (dec->cstate) { - jpc_cstate_destroy(dec->cstate); - } - if (dec->pkthdrstreams) { - jpc_streamlist_destroy(dec->pkthdrstreams); - } - if (dec->image) { - jas_image_destroy(dec->image); - } - - if (dec->cp) { - jpc_dec_cp_destroy(dec->cp); - } - - if (dec->cmpts) { - jas_free(dec->cmpts); - } - - if (dec->tiles) { - jas_free(dec->tiles); - } - - jas_free(dec); -} - -/******************************************************************************\ -* -\******************************************************************************/ - -void jpc_seglist_insert(jpc_dec_seglist_t *list, jpc_dec_seg_t *ins, jpc_dec_seg_t *node) -{ - jpc_dec_seg_t *prev; - jpc_dec_seg_t *next; - - prev = ins; - node->prev = prev; - next = prev ? (prev->next) : 0; - node->prev = prev; - node->next = next; - if (prev) { - prev->next = node; - } else { - list->head = node; - } - if (next) { - next->prev = node; - } else { - list->tail = node; - } -} - -void jpc_seglist_remove(jpc_dec_seglist_t *list, jpc_dec_seg_t *seg) -{ - jpc_dec_seg_t *prev; - jpc_dec_seg_t *next; - - prev = seg->prev; - next = seg->next; - if (prev) { - prev->next = next; - } else { - list->head = next; - } - if (next) { - next->prev = prev; - } else { - list->tail = prev; - } - seg->prev = 0; - seg->next = 0; -} - -jpc_dec_seg_t *jpc_seg_alloc(void) -{ - jpc_dec_seg_t *seg; - - if (!(seg = jas_malloc(sizeof(jpc_dec_seg_t)))) { - return 0; - } - seg->prev = 0; - seg->next = 0; - seg->passno = -1; - seg->numpasses = 0; - seg->maxpasses = 0; - seg->type = JPC_SEG_INVALID; - seg->stream = 0; - seg->cnt = 0; - seg->complete = 0; - seg->lyrno = -1; - return seg; -} - -void jpc_seg_destroy(jpc_dec_seg_t *seg) -{ - if (seg->stream) { - jas_stream_close(seg->stream); - } - jas_free(seg); -} - -static int jpc_dec_dump(jpc_dec_t *dec, FILE *out) -{ - jpc_dec_tile_t *tile; - int tileno; - jpc_dec_tcomp_t *tcomp; - uint_fast16_t compno; - jpc_dec_rlvl_t *rlvl; - int rlvlno; - jpc_dec_band_t *band; - int bandno; - jpc_dec_prc_t *prc; - int prcno; - jpc_dec_cblk_t *cblk; - int cblkno; - - for (tileno = 0, tile = dec->tiles; tileno < dec->numtiles; - ++tileno, ++tile) { - for (compno = 0, tcomp = tile->tcomps; compno < dec->numcomps; - ++compno, ++tcomp) { - for (rlvlno = 0, rlvl = tcomp->rlvls; rlvlno < - tcomp->numrlvls; ++rlvlno, ++rlvl) { - fprintf(out, "RESOLUTION LEVEL %d\n", rlvlno); - fprintf(out, "xs =%d, ys = %d, xe = %d, ye = %d, " - "w = %d, h = %d\n", - (int)rlvl->xstart, (int)rlvl->ystart, - (int)rlvl->xend, (int)rlvl->yend, - (int)(rlvl->xend - rlvl->xstart), - (int)(rlvl->yend - rlvl->ystart)); - for (bandno = 0, band = rlvl->bands; - bandno < rlvl->numbands; ++bandno, ++band) { - fprintf(out, "BAND %d\n", bandno); - fprintf(out, "xs =%d, ys = %d, xe = %d, ye = %d, " - "w = %d, h = %d\n", - (int)jas_seq2d_xstart(band->data), - (int)jas_seq2d_ystart(band->data), - (int)jas_seq2d_xend(band->data), - (int)jas_seq2d_yend(band->data), - (int)(jas_seq2d_xend(band->data) - - jas_seq2d_xstart(band->data)), - (int)(jas_seq2d_yend(band->data) - - jas_seq2d_ystart(band->data))); - for (prcno = 0, prc = band->prcs; - prcno < rlvl->numprcs; - ++prcno, ++prc) { - fprintf(out, "CODE BLOCK GROUP %d\n", prcno); - fprintf(out, "xs =%d, ys = %d, xe = %d, ye = %d, " - "w = %d, h = %d\n", - (int)prc->xstart, (int)prc->ystart, - (int)prc->xend, (int)prc->yend, - (int)(prc->xend - prc->xstart), - (int)(prc->yend - prc->ystart)); - for (cblkno = 0, cblk = prc->cblks; - cblkno < prc->numcblks; - ++cblkno, ++cblk) { - fprintf(out, "CODE BLOCK %d\n", cblkno); - fprintf(out, "xs =%d, ys = %d, xe = %d, ye = %d, " - "w = %d, h = %d\n", - (int)jas_seq2d_xstart(cblk->data), - (int)jas_seq2d_ystart(cblk->data), - (int)jas_seq2d_xend(cblk->data), - (int)jas_seq2d_yend(cblk->data), - (int)(jas_seq2d_xend(cblk->data) - - jas_seq2d_xstart(cblk->data)), - (int)(jas_seq2d_yend(cblk->data) - - jas_seq2d_ystart(cblk->data))); - } - } - } - } - } - } - return 0; -} - -jpc_streamlist_t *jpc_streamlist_create() -{ - jpc_streamlist_t *streamlist; - int i; - - if (!(streamlist = jas_malloc(sizeof(jpc_streamlist_t)))) { - return 0; - } - streamlist->numstreams = 0; - streamlist->maxstreams = 100; - if (!(streamlist->streams = jas_malloc(streamlist->maxstreams * - sizeof(jas_stream_t *)))) { - jas_free(streamlist); - return 0; - } - for (i = 0; i < streamlist->maxstreams; ++i) { - streamlist->streams[i] = 0; - } - return streamlist; -} - -int jpc_streamlist_insert(jpc_streamlist_t *streamlist, int streamno, - jas_stream_t *stream) -{ - jas_stream_t **newstreams; - int newmaxstreams; - int i; - /* Grow the array of streams if necessary. */ - if (streamlist->numstreams >= streamlist->maxstreams) { - newmaxstreams = streamlist->maxstreams + 1024; - if (!(newstreams = jas_realloc(streamlist->streams, - (newmaxstreams + 1024) * sizeof(jas_stream_t *)))) { - return -1; - } - for (i = streamlist->numstreams; i < streamlist->maxstreams; ++i) { - streamlist->streams[i] = 0; - } - streamlist->maxstreams = newmaxstreams; - streamlist->streams = newstreams; - } - if (streamno != streamlist->numstreams) { - /* Can only handle insertion at start of list. */ - return -1; - } - streamlist->streams[streamno] = stream; - ++streamlist->numstreams; - return 0; -} - -jas_stream_t *jpc_streamlist_remove(jpc_streamlist_t *streamlist, int streamno) -{ - jas_stream_t *stream; - int i; - if (streamno >= streamlist->numstreams) { - abort(); - } - stream = streamlist->streams[streamno]; - for (i = streamno + 1; i < streamlist->numstreams; ++i) { - streamlist->streams[i - 1] = streamlist->streams[i]; - } - --streamlist->numstreams; - return stream; -} - -void jpc_streamlist_destroy(jpc_streamlist_t *streamlist) -{ - int streamno; - if (streamlist->streams) { - for (streamno = 0; streamno < streamlist->numstreams; - ++streamno) { - jas_stream_close(streamlist->streams[streamno]); - } - jas_free(streamlist->streams); - } - jas_free(streamlist); -} - -jas_stream_t *jpc_streamlist_get(jpc_streamlist_t *streamlist, int streamno) -{ - assert(streamno < streamlist->numstreams); - return streamlist->streams[streamno]; -} - -int jpc_streamlist_numstreams(jpc_streamlist_t *streamlist) -{ - return streamlist->numstreams; -} - -jpc_ppxstab_t *jpc_ppxstab_create() -{ - jpc_ppxstab_t *tab; - - if (!(tab = jas_malloc(sizeof(jpc_ppxstab_t)))) { - return 0; - } - tab->numents = 0; - tab->maxents = 0; - tab->ents = 0; - return tab; -} - -void jpc_ppxstab_destroy(jpc_ppxstab_t *tab) -{ - int i; - for (i = 0; i < tab->numents; ++i) { - jpc_ppxstabent_destroy(tab->ents[i]); - } - if (tab->ents) { - jas_free(tab->ents); - } - jas_free(tab); -} - -int jpc_ppxstab_grow(jpc_ppxstab_t *tab, int maxents) -{ - jpc_ppxstabent_t **newents; - if (tab->maxents < maxents) { - newents = (tab->ents) ? jas_realloc(tab->ents, maxents * - sizeof(jpc_ppxstabent_t *)) : jas_malloc(maxents * sizeof(jpc_ppxstabent_t *)); - if (!newents) { - return -1; - } - tab->ents = newents; - tab->maxents = maxents; - } - return 0; -} - -int jpc_ppxstab_insert(jpc_ppxstab_t *tab, jpc_ppxstabent_t *ent) -{ - int inspt; - int i; - - for (i = 0; i < tab->numents; ++i) { - if (tab->ents[i]->ind > ent->ind) { - break; - } - } - inspt = i; - - if (tab->numents >= tab->maxents) { - if (jpc_ppxstab_grow(tab, tab->maxents + 128)) { - return -1; - } - } - - for (i = tab->numents; i > inspt; --i) { - tab->ents[i] = tab->ents[i - 1]; - } - tab->ents[i] = ent; - ++tab->numents; - - return 0; -} - -jpc_streamlist_t *jpc_ppmstabtostreams(jpc_ppxstab_t *tab) -{ - jpc_streamlist_t *streams; - unsigned char *dataptr; - uint_fast32_t datacnt; - uint_fast32_t tpcnt; - jpc_ppxstabent_t *ent; - int entno; - jas_stream_t *stream; - int n; - - if (!(streams = jpc_streamlist_create())) { - goto error; - } - - if (!tab->numents) { - return streams; - } - - entno = 0; - ent = tab->ents[entno]; - dataptr = ent->data; - datacnt = ent->len; - for (;;) { - - /* Get the length of the packet header data for the current - tile-part. */ - if (datacnt < 4) { - goto error; - } - if (!(stream = jas_stream_memopen(0, 0))) { - goto error; - } - if (jpc_streamlist_insert(streams, jpc_streamlist_numstreams(streams), - stream)) { - goto error; - } - tpcnt = (dataptr[0] << 24) | (dataptr[1] << 16) | (dataptr[2] << 8) - | dataptr[3]; - datacnt -= 4; - dataptr += 4; - - /* Get the packet header data for the current tile-part. */ - while (tpcnt) { - if (!datacnt) { - if (++entno >= tab->numents) { - goto error; - } - ent = tab->ents[entno]; - dataptr = ent->data; - datacnt = ent->len; - } - n = JAS_MIN(tpcnt, datacnt); - if (jas_stream_write(stream, dataptr, n) != n) { - goto error; - } - tpcnt -= n; - dataptr += n; - datacnt -= n; - } - jas_stream_rewind(stream); - if (!datacnt) { - if (++entno >= tab->numents) { - break; - } - ent = tab->ents[entno]; - dataptr = ent->data; - datacnt = ent->len; - } - } - - return streams; - -error: - jpc_streamlist_destroy(streams); - return 0; -} - -int jpc_pptstabwrite(jas_stream_t *out, jpc_ppxstab_t *tab) -{ - int i; - jpc_ppxstabent_t *ent; - for (i = 0; i < tab->numents; ++i) { - ent = tab->ents[i]; - if (jas_stream_write(out, ent->data, ent->len) != ent->len) { - return -1; - } - } - return 0; -} - -jpc_ppxstabent_t *jpc_ppxstabent_create() -{ - jpc_ppxstabent_t *ent; - if (!(ent = jas_malloc(sizeof(jpc_ppxstabent_t)))) { - return 0; - } - ent->data = 0; - ent->len = 0; - ent->ind = 0; - return ent; -} - -void jpc_ppxstabent_destroy(jpc_ppxstabent_t *ent) -{ - if (ent->data) { - jas_free(ent->data); - } - jas_free(ent); -} diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_dec.h b/converter/other/jpeg2000/libjasper/jpc/jpc_dec.h deleted file mode 100644 index 02c5553..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_dec.h +++ /dev/null @@ -1,745 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * JPEG-2000 Decoder - * - * $Id$ - */ - -#ifndef JPC_DEC_H -#define JPC_DEC_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include "jasper/jas_stream.h" - -#include "jpc_tsfb.h" -#include "jpc_bs.h" -#include "jpc_tagtree.h" -#include "jpc_cs.h" -#include "jpc_cod.h" -#include "jpc_mqdec.h" -#include "jpc_t2cod.h" - -/******************************************************************************\ -* Below are some ugly warts necessary to support packed packet headers. -\******************************************************************************/ - -/* PPM/PPT marker segment table entry. */ - -typedef struct { - - /* The index for this entry. */ - uint_fast16_t ind; - - /* The data length. */ - uint_fast32_t len; - - /* The data. */ - unsigned char *data; - -} jpc_ppxstabent_t; - -/* PPM/PPT marker segment table. */ - -typedef struct { - - /* The number of entries. */ - int numents; - - /* The maximum number of entries (i.e., the allocated size of the array - below). */ - int maxents; - - /* The table entries. */ - jpc_ppxstabent_t **ents; - -} jpc_ppxstab_t; - -/* Stream list class. */ - -typedef struct { - - /* The number of streams in this list. */ - int numstreams; - - /* The maximum number of streams that can be accommodated without - growing the streams array. */ - int maxstreams; - - /* The streams. */ - jas_stream_t **streams; - -} jpc_streamlist_t; - -/******************************************************************************\ -* Coding parameters class. -\******************************************************************************/ - -/* Per-component coding parameters. */ - -typedef struct { - - /* How were various coding parameters set? */ - int flags; - - /* Per-component coding style parameters (e.g., explicit precinct sizes) */ - uint_fast8_t csty; - - /* The number of resolution levels. */ - uint_fast8_t numrlvls; - - /* The code block width exponent. */ - uint_fast8_t cblkwidthexpn; - - /* The code block height exponent. */ - uint_fast8_t cblkheightexpn; - - /* The QMFB ID. */ - uint_fast8_t qmfbid; - - /* The quantization style. */ - uint_fast8_t qsty; - - /* The number of quantizer step sizes. */ - uint_fast16_t numstepsizes; - - /* The step sizes. */ - uint_fast16_t stepsizes[3 * JPC_MAXRLVLS + 1]; - - /* The number of guard bits. */ - uint_fast8_t numguardbits; - - /* The ROI shift value. */ - uint_fast8_t roishift; - - /* The code block parameters. */ - uint_fast8_t cblkctx; - - /* The precinct width exponents. */ - uint_fast8_t prcwidthexpns[JPC_MAXRLVLS]; - - /* The precinct height exponents. */ - uint_fast8_t prcheightexpns[JPC_MAXRLVLS]; - -} jpc_dec_ccp_t; - -/* Coding paramters. */ - -typedef struct { - - /* How were these coding parameters set? */ - int flags; - - /* Progression change list. */ - jpc_pchglist_t *pchglist; - - /* Progression order. */ - uint_fast8_t prgord; - - /* The number of layers. */ - uint_fast16_t numlyrs; - - /* The MCT ID. */ - uint_fast8_t mctid; - - /* The coding style parameters (e.g., SOP, EPH). */ - uint_fast8_t csty; - - /* The number of components. */ - uint_fast16_t numcomps; - - /* The per-component coding parameters. */ - jpc_dec_ccp_t *ccps; - -} jpc_dec_cp_t; - -/******************************************************************************\ -* Decoder class. -\******************************************************************************/ - -/* Decoder per-segment state information. */ - -typedef struct jpc_dec_seg_s { - - /* The next segment in the list. */ - struct jpc_dec_seg_s *next; - - /* The previous segment in the list. */ - struct jpc_dec_seg_s *prev; - - /* The starting pass number for this segment. */ - int passno; - - /* The number of passes in this segment. */ - int numpasses; - - /* The maximum number of passes in this segment. */ - int maxpasses; - - /* The type of data in this segment (i.e., MQ or raw). */ - int type; - - /* A stream containing the data for this segment. */ - jas_stream_t *stream; - - /* The number of bytes destined for this segment from the packet - currently being decoded. */ - int cnt; - - /* A flag indicating if this segment has been terminated. */ - int complete; - - /* The layer number to which this segment belongs. */ - /* If the segment spans multiple layers, then the largest layer number - spanned by the segment is used. */ - int lyrno; - -} jpc_dec_seg_t; - -/* Decoder segment list. */ - -typedef struct { - - /* The first entry in the list. */ - jpc_dec_seg_t *head; - - /* The last entry in the list. */ - jpc_dec_seg_t *tail; - -} jpc_dec_seglist_t; - -/* Decoder per-code-block state information. */ - -typedef struct { - - /* The number of passes. */ - int numpasses; - - /* A list of segments that still need to be decoded. */ - jpc_dec_seglist_t segs; - - /* The first incomplete/partial segment. */ - jpc_dec_seg_t *curseg; - - /* The number of leading insignificant bit planes for this code block. */ - int numimsbs; - - /* The number of bits used to encode pass data lengths. */ - int numlenbits; - - /* The first pass number containing data for this code block. */ - int firstpassno; - - /* The MQ decoder. */ - jpc_mqdec_t *mqdec; - - /* The raw bit stream decoder. */ - jpc_bitstream_t *nulldec; - - /* The per-sample state information for this code block. */ - jas_matrix_t *flags; - - /* The sample data associated with this code block. */ - jas_matrix_t *data; - -} jpc_dec_cblk_t; - -/* Decoder per-code-block-group state information. */ - -typedef struct { - - /* The x-coordinate of the top-left corner of the precinct. */ - uint_fast32_t xstart; - - /* The y-coordinate of the top-left corner of the precinct. */ - uint_fast32_t ystart; - - /* The x-coordinate of the bottom-right corner of the precinct - (plus one). */ - uint_fast32_t xend; - - /* The y-coordinate of the bottom-right corner of the precinct - (plus one). */ - uint_fast32_t yend; - - /* The number of code blocks spanning this precinct in the horizontal - direction. */ - int numhcblks; - - /* The number of code blocks spanning this precinct in the vertical - direction. */ - int numvcblks; - - /* The total number of code blocks in this precinct. */ - int numcblks; - - /* The per code block information. */ - jpc_dec_cblk_t *cblks; - - /* The inclusion tag tree. */ - jpc_tagtree_t *incltagtree; - - /* The insignificant MSBs tag tree. */ - jpc_tagtree_t *numimsbstagtree; - -} jpc_dec_prc_t; - -/* Decoder per-band state information. */ - -typedef struct { - - /* The per-code-block-group state information. */ - jpc_dec_prc_t *prcs; - - /* The sample data associated with this band. */ - jas_matrix_t *data; - - /* The orientation of this band (i.e., LL, LH, HL, or HH). */ - int orient; - - /* The encoded quantizer step size. */ - int stepsize; - - /* The absolute quantizer step size. */ - jpc_fix_t absstepsize; - - /* The number of bit planes for this band. */ - int numbps; - - /* The analysis gain associated with this band. */ - int analgain; - - /* The ROI shift value for this band. */ - int roishift; - -} jpc_dec_band_t; - -/* Decoder per-resolution-level state information. */ - -typedef struct { - - /* The number of bands associated with this resolution level. */ - int numbands; - - /* The per-band information. */ - jpc_dec_band_t *bands; - - /* The x-coordinate of the top-left corner of the tile-component - at this resolution. */ - uint_fast32_t xstart; - - /* The y-coordinate of the top-left corner of the tile-component - at this resolution. */ - uint_fast32_t ystart; - - /* The x-coordinate of the bottom-right corner of the tile-component - at this resolution (plus one). */ - uint_fast32_t xend; - - /* The y-coordinate of the bottom-right corner of the tile-component - at this resolution (plus one). */ - uint_fast32_t yend; - - /* The exponent value for the nominal precinct width measured - relative to the associated LL band. */ - int prcwidthexpn; - - /* The exponent value for the nominal precinct height measured - relative to the associated LL band. */ - int prcheightexpn; - - /* The number of precincts in the horizontal direction. */ - int numhprcs; - - /* The number of precincts in the vertical direction. */ - int numvprcs; - - /* The total number of precincts. */ - int numprcs; - - /* The exponent value for the nominal code block group width. - This quantity is associated with the next lower resolution level - (assuming that there is one). */ - int cbgwidthexpn; - - /* The exponent value for the nominal code block group height - This quantity is associated with the next lower resolution level - (assuming that there is one). */ - int cbgheightexpn; - - /* The exponent value for the code block width. */ - uint_fast16_t cblkwidthexpn; - - /* The exponent value for the code block height. */ - uint_fast16_t cblkheightexpn; - -} jpc_dec_rlvl_t; - -/* Decoder per-tile-component state information. */ - -typedef struct { - - /* The x-coordinate of the top-left corner of the tile-component - in the coordinate system of the tile-component. */ - uint_fast32_t xstart; - - /* The y-coordinate of the top-left corner of the tile-component - in the coordinate system of the tile-component. */ - uint_fast32_t ystart; - - /* The x-coordinate of the bottom-right corner of the tile-component - in the coordinate system of the tile-component (plus one). */ - uint_fast32_t xend; - - /* The y-coordinate of the bottom-right corner of the tile-component - in the coordinate system of the tile-component (plus one). */ - uint_fast32_t yend; - - /* The component data for the current tile. */ - jas_matrix_t *data; - - /* The number of resolution levels. */ - uint_fast16_t numrlvls; - - /* The per resolution level information. */ - jpc_dec_rlvl_t *rlvls; - - /* The TSFB. */ - jpc_tsfb_t *tsfb; - -} jpc_dec_tcomp_t; - -/* - * Tile states. - */ - -#define JPC_TILE_INIT 0 -#define JPC_TILE_ACTIVE 1 -#define JPC_TILE_ACTIVELAST 2 -#define JPC_TILE_DONE 3 - -/* Decoder per-tile state information. */ - -typedef struct { - - /* The processing state for this tile. */ - int state; - - /* The x-coordinate of the top-left corner of the tile on the reference - grid. */ - uint_fast32_t xstart; - - /* The y-coordinate of the top-left corner of the tile on the reference - grid. */ - uint_fast32_t ystart; - - /* The x-coordinate of the bottom-right corner of the tile on the - reference grid (plus one). */ - uint_fast32_t xend; - - /* The y-coordinate of the bottom-right corner of the tile on the - reference grid (plus one). */ - uint_fast32_t yend; - - /* The packed packet header data for this tile. */ - jpc_ppxstab_t *pptstab; - - /* A stream containing the packed packet header data for this tile. */ - jas_stream_t *pkthdrstream; - - /* The current position within the packed packet header stream. */ - long pkthdrstreampos; - - /* The coding parameters for this tile. */ - jpc_dec_cp_t *cp; - - /* The per tile-component information. */ - jpc_dec_tcomp_t *tcomps; - - /* The next expected tile-part number. */ - int partno; - - /* The number of tile-parts. */ - int numparts; - - /* The coding mode. */ - int realmode; - - /* The packet iterator for this tile. */ - jpc_pi_t *pi; - -} jpc_dec_tile_t; - -/* Decoder per-component state information. */ - -typedef struct { - - /* The horizontal sampling period. */ - uint_fast32_t hstep; - - /* The vertical sampling period. */ - uint_fast32_t vstep; - - /* The number of samples in the horizontal direction. */ - uint_fast32_t width; - - /* The number of samples in the vertical direction. */ - uint_fast32_t height; - - /* The precision of the sample data. */ - uint_fast16_t prec; - - /* The signedness of the sample data. */ - bool sgnd; - - /* The sample alignment horizontal offset. */ - uint_fast32_t hsubstep; - - /* The sample alignment vertical offset. */ - uint_fast32_t vsubstep; - -} jpc_dec_cmpt_t; - -/* Decoder state information. */ - -typedef struct { - - /* The decoded image. */ - jas_image_t *image; - - /* The x-coordinate of the top-left corner of the image area on - the reference grid. */ - uint_fast32_t xstart; - - /* The y-coordinate of the top-left corner of the image area on - the reference grid. */ - uint_fast32_t ystart; - - /* The x-coordinate of the bottom-right corner of the image area on - the reference grid (plus one). */ - uint_fast32_t xend; - - /* The y-coordinate of the bottom-right corner of the image area on - the reference grid (plus one). */ - uint_fast32_t yend; - - /* The nominal tile width in units of the image reference grid. */ - uint_fast32_t tilewidth; - - /* The nominal tile height in units of the image reference grid. */ - uint_fast32_t tileheight; - - /* The horizontal offset from the origin of the reference grid to the - left side of the first tile. */ - uint_fast32_t tilexoff; - - /* The vertical offset from the origin of the reference grid to the - top side of the first tile. */ - uint_fast32_t tileyoff; - - /* The number of tiles spanning the image area in the vertical - direction. */ - int numhtiles; - - /* The number of tiles spanning the image area in the horizontal - direction. */ - int numvtiles; - - /* The total number of tiles. */ - int numtiles; - - /* The per-tile information. */ - jpc_dec_tile_t *tiles; - - /* The tile currently being processed. */ - jpc_dec_tile_t *curtile; - - /* The number of components. */ - int numcomps; - - /* The stream containing the input JPEG-2000 code stream data. */ - jas_stream_t *in; - - /* The default coding parameters for all tiles. */ - jpc_dec_cp_t *cp; - - /* The maximum number of layers that may be decoded. */ - int maxlyrs; - - /* The maximum number of packets that may be decoded. */ - int maxpkts; - - /* The number of packets decoded so far in the processing of the entire - code stream. */ - int numpkts; - - /* The next expected PPM marker segment sequence number. */ - int ppmseqno; - - /* The current state for code stream processing. */ - int state; - - /* The per-component information. */ - jpc_dec_cmpt_t *cmpts; - - /* The information from PPM marker segments. */ - jpc_ppxstab_t *ppmstab; - - /* A list of streams containing packet header data from PPM marker - segments. */ - jpc_streamlist_t *pkthdrstreams; - - /* The expected ending offset for a tile-part. */ - long curtileendoff; - - /* This is required by the tier-2 decoder. */ - jpc_cstate_t *cstate; - -} jpc_dec_t; - -/* Decoder options. */ - -typedef struct { - - /* The debug level for the decoder. */ - int debug; - - /* The maximum number of layers to decode. */ - int maxlyrs; - - /* The maximum number of packets to decode. */ - int maxpkts; - -} jpc_dec_importopts_t; - -/******************************************************************************\ -* Functions. -\******************************************************************************/ - -/* Create a decoder segment object. */ -jpc_dec_seg_t *jpc_seg_alloc(void); - -/* Destroy a decoder segment object. */ -void jpc_seg_destroy(jpc_dec_seg_t *seg); - -/* Remove a segment from a segment list. */ -void jpc_seglist_remove(jpc_dec_seglist_t *list, jpc_dec_seg_t *node); - -/* Insert a segment into a segment list. */ -void jpc_seglist_insert(jpc_dec_seglist_t *list, jpc_dec_seg_t *ins, - jpc_dec_seg_t *node); - -#endif diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_enc.c b/converter/other/jpeg2000/libjasper/jpc/jpc_enc.c deleted file mode 100644 index 9db41ca..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_enc.c +++ /dev/null @@ -1,2928 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "netpbm/pm.h" -#include "netpbm/nstring.h" - -#include "jasper/jas_string.h" -#include "jasper/jas_malloc.h" -#include "jasper/jas_image.h" -#include "jasper/jas_fix.h" -#include "jasper/jas_tvp.h" -#include "jasper/jas_version.h" -#include "jasper/jas_math.h" -#include "jasper/jas_debug.h" - -#include "jpc_flt.h" -#include "jpc_fix.h" -#include "jpc_tagtree.h" -#include "jpc_enc.h" -#include "jpc_cs.h" -#include "jpc_mct.h" -#include "jpc_tsfb.h" -#include "jpc_qmfb.h" -#include "jpc_t1enc.h" -#include "jpc_t2enc.h" -#include "jpc_cod.h" -#include "jpc_math.h" -#include "jpc_util.h" - -/*****************************************************************************\ -* -\*****************************************************************************/ - -#define JPC_POW2(n) \ - (1 << (n)) - -#define JPC_FLOORTOMULTPOW2(x, n) \ - (((n) > 0) ? ((x) & (~((1 << n) - 1))) : (x)) -/* Round to the nearest multiple of the specified power of two in the - direction of negative infinity. */ - -#define JPC_CEILTOMULTPOW2(x, n) \ - (((n) > 0) ? JPC_FLOORTOMULTPOW2(((x) + (1 << (n)) - 1), n) : (x)) -/* Round to the nearest multiple of the specified power of two in the - direction of positive infinity. */ - -#define JPC_POW2(n) \ - (1 << (n)) - -jpc_enc_tile_t *jpc_enc_tile_create(jpc_enc_cp_t *cp, jas_image_t *image, int tileno); -void jpc_enc_tile_destroy(jpc_enc_tile_t *tile); - -static jpc_enc_tcmpt_t *tcmpt_create(jpc_enc_tcmpt_t *tcmpt, jpc_enc_cp_t *cp, - jas_image_t *image, jpc_enc_tile_t *tile); -static void tcmpt_destroy(jpc_enc_tcmpt_t *tcmpt); -static jpc_enc_rlvl_t *rlvl_create(jpc_enc_rlvl_t *rlvl, jpc_enc_cp_t *cp, - jpc_enc_tcmpt_t *tcmpt, jpc_tsfb_band_t *bandinfos); -static void rlvl_destroy(jpc_enc_rlvl_t *rlvl); -static jpc_enc_band_t *band_create(jpc_enc_band_t *band, jpc_enc_cp_t *cp, - jpc_enc_rlvl_t *rlvl, jpc_tsfb_band_t *bandinfos); -static void band_destroy(jpc_enc_band_t *bands); -static jpc_enc_prc_t *prc_create(jpc_enc_prc_t *prc, jpc_enc_cp_t *cp, - jpc_enc_band_t *band); -static void prc_destroy(jpc_enc_prc_t *prcs); -static jpc_enc_cblk_t *cblk_create(jpc_enc_cblk_t *cblk, jpc_enc_cp_t *cp, - jpc_enc_prc_t *prc); -static void cblk_destroy(jpc_enc_cblk_t *cblks); -int ratestrtosize(const char *s, uint_fast32_t rawsize, uint_fast32_t *size); -static void pass_destroy(jpc_enc_pass_t *pass); -void jpc_enc_dump(jpc_enc_t *enc); - -/*****************************************************************************\ -* Local prototypes. -\*****************************************************************************/ - -void quantize(jas_matrix_t *data, jpc_fix_t stepsize); -static int jpc_enc_encodemainhdr(jpc_enc_t *enc); -static int jpc_enc_encodemainbody(jpc_enc_t *enc); -int jpc_enc_encodetiledata(jpc_enc_t *enc); -jpc_enc_t *jpc_enc_create(jpc_enc_cp_t *cp, jas_stream_t *out, jas_image_t *image); -void jpc_enc_destroy(jpc_enc_t *enc); -static int jpc_enc_encodemainhdr(jpc_enc_t *enc); -static int jpc_enc_encodemainbody(jpc_enc_t *enc); -int jpc_enc_encodetiledata(jpc_enc_t *enc); -int setins(int numvalues, jpc_flt_t *values, jpc_flt_t value); -static jpc_enc_cp_t *cp_create(char *optstr, jas_image_t *image); -void jpc_enc_cp_destroy(jpc_enc_cp_t *cp); - - - -static uint_fast32_t -jpc_abstorelstepsize(jpc_fix_t absdelta, int scaleexpn) { - - int p; - uint_fast32_t mant; - uint_fast32_t expn; - int n; - - if (absdelta < 0) { - abort(); - } - - p = jpc_firstone(absdelta) - JPC_FIX_FRACBITS; - n = 11 - jpc_firstone(absdelta); - mant = ((n < 0) ? (absdelta >> (-n)) : (absdelta << n)) & 0x7ff; - expn = scaleexpn - p; - if (scaleexpn < p) { - abort(); - } - return JPC_QCX_EXPN(expn) | JPC_QCX_MANT(mant); -} - - - -typedef enum { - OPT_DEBUG, - OPT_IMGAREAOFFX, - OPT_IMGAREAOFFY, - OPT_TILEGRDOFFX, - OPT_TILEGRDOFFY, - OPT_TILEWIDTH, - OPT_TILEHEIGHT, - OPT_PRCWIDTH, - OPT_PRCHEIGHT, - OPT_CBLKWIDTH, - OPT_CBLKHEIGHT, - OPT_MODE, - OPT_PRG, - OPT_NOMCT, - OPT_MAXRLVLS, - OPT_SOP, - OPT_EPH, - OPT_LAZY, - OPT_TERMALL, - OPT_SEGSYM, - OPT_VCAUSAL, - OPT_RESET, - OPT_PTERM, - OPT_NUMGBITS, - OPT_RATE, - OPT_ILYRRATES, - OPT_JP2OVERHEAD -} optid_t; - -jas_taginfo_t encopts[] = { - {OPT_DEBUG, "debug"}, - {OPT_IMGAREAOFFX, "imgareatlx"}, - {OPT_IMGAREAOFFY, "imgareatly"}, - {OPT_TILEGRDOFFX, "tilegrdtlx"}, - {OPT_TILEGRDOFFY, "tilegrdtly"}, - {OPT_TILEWIDTH, "tilewidth"}, - {OPT_TILEHEIGHT, "tileheight"}, - {OPT_PRCWIDTH, "prcwidth"}, - {OPT_PRCHEIGHT, "prcheight"}, - {OPT_CBLKWIDTH, "cblkwidth"}, - {OPT_CBLKHEIGHT, "cblkheight"}, - {OPT_MODE, "mode"}, - {OPT_PRG, "prg"}, - {OPT_NOMCT, "nomct"}, - {OPT_MAXRLVLS, "numrlvls"}, - {OPT_SOP, "sop"}, - {OPT_EPH, "eph"}, - {OPT_LAZY, "lazy"}, - {OPT_TERMALL, "termall"}, - {OPT_SEGSYM, "segsym"}, - {OPT_VCAUSAL, "vcausal"}, - {OPT_PTERM, "pterm"}, - {OPT_RESET, "resetprob"}, - {OPT_NUMGBITS, "numgbits"}, - {OPT_RATE, "rate"}, - {OPT_ILYRRATES, "ilyrrates"}, - {OPT_JP2OVERHEAD, "_jp2overhead"}, - {-1, 0} -}; - -typedef enum { - PO_L = 0, - PO_R -} poid_t; - - -jas_taginfo_t prgordtab[] = { - {JPC_COD_LRCPPRG, "lrcp"}, - {JPC_COD_RLCPPRG, "rlcp"}, - {JPC_COD_RPCLPRG, "rpcl"}, - {JPC_COD_PCRLPRG, "pcrl"}, - {JPC_COD_CPRLPRG, "cprl"}, - {-1, 0} -}; - -typedef enum { - MODE_INT, - MODE_REAL -} modeid_t; - -jas_taginfo_t modetab[] = { - {MODE_INT, "int"}, - {MODE_REAL, "real"}, - {-1, 0} -}; - - - -static void -tracev(const char * const fmt, - va_list args) { - - vfprintf(stderr, fmt, args); - - fprintf(stderr, "\n"); -} - - - -static void -trace(const char * const fmt, ...) { - - if (jas_getdbglevel() > 0) { - va_list args; - - va_start(args, fmt); - tracev(fmt, args); - va_end(args); - } -} - - - -int -jpc_encode(jas_image_t *image, jas_stream_t *out, char *optstr) { - - jpc_enc_t *enc; - jpc_enc_cp_t *cp; - - enc = 0; - cp = 0; - - jpc_initluts(); - - if (!(cp = cp_create(optstr, image))) { - fprintf(stderr, "invalid JP encoder options\n"); - goto error; - } - - if (!(enc = jpc_enc_create(cp, out, image))) { - goto error; - } - cp = 0; - - /* Encode the main header. */ - if (jpc_enc_encodemainhdr(enc)) { - goto error; - } - - /* Encode the main body. This constitutes most of the encoding work. */ - if (jpc_enc_encodemainbody(enc)) { - goto error; - } - - /* Write EOC marker segment. */ - if (!(enc->mrk = jpc_ms_create(JPC_MS_EOC))) { - goto error; - } - if (jpc_putms(enc->out, enc->cstate, enc->mrk)) { - fprintf(stderr, "cannot write EOI marker\n"); - goto error; - } - jpc_ms_destroy(enc->mrk); - enc->mrk = 0; - - if (jas_stream_flush(enc->out)) { - goto error; - } - - jpc_enc_destroy(enc); - - return 0; - -error: - if (cp) { - jpc_enc_cp_destroy(cp); - } - if (enc) { - jpc_enc_destroy(enc); - } - return -1; -} - - - -/*****************************************************************************\ -* Option parsing code. -\*****************************************************************************/ - -static jpc_enc_cp_t * -cp_create(char *optstr, jas_image_t *image) { - - jpc_enc_cp_t *cp; - jas_tvparser_t *tvp; - int ret; - int numilyrrates; - double *ilyrrates; - int i; - int tagid; - jpc_enc_tcp_t *tcp; - jpc_enc_tccp_t *tccp; - jpc_enc_ccp_t *ccp; - uint_fast16_t cmptno; - uint_fast16_t rlvlno; - uint_fast16_t prcwidthexpn; - uint_fast16_t prcheightexpn; - bool enablemct; - uint_fast32_t jp2overhead; - uint_fast16_t lyrno; - uint_fast32_t hsteplcm; - uint_fast32_t vsteplcm; - bool mctvalid; - - tvp = 0; - cp = 0; - ilyrrates = 0; - numilyrrates = 0; - - if (!(cp = jas_malloc(sizeof(jpc_enc_cp_t)))) { - goto error; - } - - prcwidthexpn = 15; - prcheightexpn = 15; - enablemct = true; - jp2overhead = 0; - - cp->ccps = 0; - cp->debug = 0; - cp->imgareatlx = UINT_FAST32_MAX; - cp->imgareatly = UINT_FAST32_MAX; - cp->refgrdwidth = 0; - cp->refgrdheight = 0; - cp->tilegrdoffx = UINT_FAST32_MAX; - cp->tilegrdoffy = UINT_FAST32_MAX; - cp->tilewidth = 0; - cp->tileheight = 0; - cp->numcmpts = jas_image_numcmpts(image); - - hsteplcm = 1; - vsteplcm = 1; - for (cmptno = 0; cmptno < jas_image_numcmpts(image); ++cmptno) { - if (jas_image_cmptbrx(image, cmptno) + - jas_image_cmpthstep(image, cmptno) <= - jas_image_brx(image) || jas_image_cmptbry(image, cmptno) + - jas_image_cmptvstep(image, cmptno) <= jas_image_bry(image)) { - fprintf(stderr, - "We don't know how to interpret this image type\n"); - goto error; - } - /* Note: We ought to be calculating the LCMs here. Fix some day. */ - hsteplcm *= jas_image_cmpthstep(image, cmptno); - vsteplcm *= jas_image_cmptvstep(image, cmptno); - } - - if (!(cp->ccps = jas_malloc(cp->numcmpts * sizeof(jpc_enc_ccp_t)))) { - goto error; - } - for (cmptno = 0, ccp = cp->ccps; cmptno < cp->numcmpts; ++cmptno, - ++ccp) { - ccp->sampgrdstepx = jas_image_cmpthstep(image, cmptno); - ccp->sampgrdstepy = jas_image_cmptvstep(image, cmptno); - /* XXX - this isn't quite correct for more general image */ - ccp->sampgrdsubstepx = 0; - ccp->sampgrdsubstepx = 0; - ccp->prec = jas_image_cmptprec(image, cmptno); - ccp->sgnd = jas_image_cmptsgnd(image, cmptno); - ccp->numstepsizes = 0; - memset(ccp->stepsizes, 0, sizeof(ccp->stepsizes)); - } - - cp->rawsize = jas_image_rawsize(image); - cp->totalsize = UINT_FAST32_MAX; - - tcp = &cp->tcp; - tcp->csty = 0; - tcp->intmode = true; - tcp->prg = JPC_COD_LRCPPRG; - tcp->numlyrs = 1; - tcp->ilyrrates = 0; - - tccp = &cp->tccp; - tccp->csty = 0; - tccp->maxrlvls = 6; - tccp->cblkwidthexpn = 6; - tccp->cblkheightexpn = 6; - tccp->cblksty = 0; - tccp->numgbits = 2; - - if (!(tvp = jas_tvparser_create(optstr ? optstr : ""))) { - goto error; - } - - while (!(ret = jas_tvparser_next(tvp))) { - switch (jas_taginfo_nonull(jas_taginfos_lookup(encopts, - jas_tvparser_gettag(tvp)))->id) { - case OPT_DEBUG: - cp->debug = atoi(jas_tvparser_getval(tvp)); - break; - case OPT_IMGAREAOFFX: - cp->imgareatlx = atoi(jas_tvparser_getval(tvp)); - break; - case OPT_IMGAREAOFFY: - cp->imgareatly = atoi(jas_tvparser_getval(tvp)); - break; - case OPT_TILEGRDOFFX: - cp->tilegrdoffx = atoi(jas_tvparser_getval(tvp)); - break; - case OPT_TILEGRDOFFY: - cp->tilegrdoffy = atoi(jas_tvparser_getval(tvp)); - break; - case OPT_TILEWIDTH: - cp->tilewidth = atoi(jas_tvparser_getval(tvp)); - break; - case OPT_TILEHEIGHT: - cp->tileheight = atoi(jas_tvparser_getval(tvp)); - break; - case OPT_PRCWIDTH: - prcwidthexpn = jpc_floorlog2(atoi(jas_tvparser_getval(tvp))); - break; - case OPT_PRCHEIGHT: - prcheightexpn = jpc_floorlog2(atoi(jas_tvparser_getval(tvp))); - break; - case OPT_CBLKWIDTH: - tccp->cblkwidthexpn = - jpc_floorlog2(atoi(jas_tvparser_getval(tvp))); - break; - case OPT_CBLKHEIGHT: - tccp->cblkheightexpn = - jpc_floorlog2(atoi(jas_tvparser_getval(tvp))); - break; - case OPT_MODE: - if ((tagid = jas_taginfo_nonull(jas_taginfos_lookup(modetab, - jas_tvparser_getval(tvp)))->id) < 0) { - fprintf(stderr, - "ignoring invalid mode %s\n", - jas_tvparser_getval(tvp)); - } else { - tcp->intmode = (tagid == MODE_INT); - } - break; - case OPT_PRG: - if ((tagid = jas_taginfo_nonull(jas_taginfos_lookup(prgordtab, - jas_tvparser_getval(tvp)))->id) < 0) { - fprintf(stderr, - "ignoring invalid progression order %s\n", - jas_tvparser_getval(tvp)); - } else { - tcp->prg = tagid; - } - break; - case OPT_NOMCT: - enablemct = false; - break; - case OPT_MAXRLVLS: - tccp->maxrlvls = atoi(jas_tvparser_getval(tvp)); - break; - case OPT_SOP: - cp->tcp.csty |= JPC_COD_SOP; - break; - case OPT_EPH: - cp->tcp.csty |= JPC_COD_EPH; - break; - case OPT_LAZY: - tccp->cblksty |= JPC_COX_LAZY; - break; - case OPT_TERMALL: - tccp->cblksty |= JPC_COX_TERMALL; - break; - case OPT_SEGSYM: - tccp->cblksty |= JPC_COX_SEGSYM; - break; - case OPT_VCAUSAL: - tccp->cblksty |= JPC_COX_VSC; - break; - case OPT_RESET: - tccp->cblksty |= JPC_COX_RESET; - break; - case OPT_PTERM: - tccp->cblksty |= JPC_COX_PTERM; - break; - case OPT_NUMGBITS: - cp->tccp.numgbits = atoi(jas_tvparser_getval(tvp)); - break; - case OPT_RATE: - if (ratestrtosize(jas_tvparser_getval(tvp), cp->rawsize, - &cp->totalsize)) { - fprintf(stderr, - "ignoring bad rate specifier %s\n", - jas_tvparser_getval(tvp)); - } - break; - case OPT_ILYRRATES: - if (jpc_atoaf(jas_tvparser_getval(tvp), &numilyrrates, - &ilyrrates)) { - fprintf(stderr, - "warning: invalid intermediate layer rates specifier " - "ignored (%s)\n", - jas_tvparser_getval(tvp)); - } - break; - - case OPT_JP2OVERHEAD: - jp2overhead = atoi(jas_tvparser_getval(tvp)); - break; - default: - fprintf(stderr, "warning: ignoring invalid option %s\n", - jas_tvparser_gettag(tvp)); - break; - } - } - - jas_tvparser_destroy(tvp); - tvp = 0; - - if (cp->totalsize != UINT_FAST32_MAX) { - cp->totalsize = (cp->totalsize > jp2overhead) ? - (cp->totalsize - jp2overhead) : 0; - } - - if (cp->imgareatlx == UINT_FAST32_MAX) { - cp->imgareatlx = 0; - } else { - if (hsteplcm != 1) { - fprintf(stderr, "warning: overriding imgareatlx value\n"); - } - cp->imgareatlx *= hsteplcm; - } - if (cp->imgareatly == UINT_FAST32_MAX) { - cp->imgareatly = 0; - } else { - if (vsteplcm != 1) { - fprintf(stderr, "warning: overriding imgareatly value\n"); - } - cp->imgareatly *= vsteplcm; - } - cp->refgrdwidth = cp->imgareatlx + jas_image_width(image); - cp->refgrdheight = cp->imgareatly + jas_image_height(image); - if (cp->tilegrdoffx == UINT_FAST32_MAX) { - cp->tilegrdoffx = cp->imgareatlx; - } - if (cp->tilegrdoffy == UINT_FAST32_MAX) { - cp->tilegrdoffy = cp->imgareatly; - } - if (!cp->tilewidth) { - cp->tilewidth = cp->refgrdwidth - cp->tilegrdoffx; - } - if (!cp->tileheight) { - cp->tileheight = cp->refgrdheight - cp->tilegrdoffy; - } - - if (cp->numcmpts == 3) { - mctvalid = true; - for (cmptno = 0; cmptno < jas_image_numcmpts(image); ++cmptno) { - if (jas_image_cmptprec(image, cmptno) != - jas_image_cmptprec(image, 0) || - jas_image_cmptsgnd(image, cmptno) != - jas_image_cmptsgnd(image, 0) || - jas_image_cmptwidth(image, cmptno) != - jas_image_cmptwidth(image, 0) || - jas_image_cmptheight(image, cmptno) != - jas_image_cmptheight(image, 0)) { - mctvalid = false; - } - } - } else { - mctvalid = false; - } - if (mctvalid && enablemct && jas_image_colorspace(image) != - JAS_IMAGE_CS_RGB) { - fprintf(stderr, "warning: color model apparently not RGB\n"); - } - if (mctvalid && enablemct && jas_image_colorspace(image) == - JAS_IMAGE_CS_RGB) { - tcp->mctid = (tcp->intmode) ? (JPC_MCT_RCT) : (JPC_MCT_ICT); - } else { - tcp->mctid = JPC_MCT_NONE; - } - tccp->qmfbid = (tcp->intmode) ? (JPC_COX_RFT) : (JPC_COX_INS); - - for (rlvlno = 0; rlvlno < tccp->maxrlvls; ++rlvlno) { - tccp->prcwidthexpns[rlvlno] = prcwidthexpn; - tccp->prcheightexpns[rlvlno] = prcheightexpn; - } - if (prcwidthexpn != 15 || prcheightexpn != 15) { - tccp->csty |= JPC_COX_PRT; - } - - /* Ensure that the tile width and height is valid. */ - if (!cp->tilewidth) { - fprintf(stderr, "invalid tile width %lu\n", (unsigned long) - cp->tilewidth); - goto error; - } - if (!cp->tileheight) { - fprintf(stderr, "invalid tile height %lu\n", (unsigned long) - cp->tileheight); - goto error; - } - - /* Ensure that the tile grid offset is valid. */ - if (cp->tilegrdoffx > cp->imgareatlx || - cp->tilegrdoffy > cp->imgareatly || - cp->tilegrdoffx + cp->tilewidth < cp->imgareatlx || - cp->tilegrdoffy + cp->tileheight < cp->imgareatly) { - fprintf(stderr, "invalid tile grid offset (%lu, %lu)\n", - (unsigned long) cp->tilegrdoffx, (unsigned long) - cp->tilegrdoffy); - goto error; - } - - cp->numhtiles = JPC_CEILDIV(cp->refgrdwidth - cp->tilegrdoffx, - cp->tilewidth); - cp->numvtiles = JPC_CEILDIV(cp->refgrdheight - cp->tilegrdoffy, - cp->tileheight); - cp->numtiles = cp->numhtiles * cp->numvtiles; - - if (ilyrrates && numilyrrates > 0) { - tcp->numlyrs = numilyrrates + 1; - if (!(tcp->ilyrrates = jas_malloc((tcp->numlyrs - 1) * - sizeof(jpc_fix_t)))) { - goto error; - } - for (i = 0; i < tcp->numlyrs - 1; ++i) { - tcp->ilyrrates[i] = jpc_dbltofix(ilyrrates[i]); - } - } - - /* Ensure that the integer mode is used in the case of lossless - coding. */ - if (cp->totalsize == UINT_FAST32_MAX && (!cp->tcp.intmode)) { - fprintf(stderr, "cannot use real mode for lossless coding\n"); - goto error; - } - - /* Ensure that the precinct width is valid. */ - if (prcwidthexpn > 15) { - fprintf(stderr, "invalid precinct width\n"); - goto error; - } - - /* Ensure that the precinct height is valid. */ - if (prcheightexpn > 15) { - fprintf(stderr, "invalid precinct height\n"); - goto error; - } - - /* Ensure that the code block width is valid. */ - if (cp->tccp.cblkwidthexpn < 2 || cp->tccp.cblkwidthexpn > 12) { - fprintf(stderr, "invalid code block width %d\n", - JPC_POW2(cp->tccp.cblkwidthexpn)); - goto error; - } - - /* Ensure that the code block height is valid. */ - if (cp->tccp.cblkheightexpn < 2 || cp->tccp.cblkheightexpn > 12) { - fprintf(stderr, "invalid code block height %d\n", - JPC_POW2(cp->tccp.cblkheightexpn)); - goto error; - } - - /* Ensure that the code block size is not too large. */ - if (cp->tccp.cblkwidthexpn + cp->tccp.cblkheightexpn > 12) { - fprintf(stderr, "code block size too large\n"); - goto error; - } - - /* Ensure that the number of layers is valid. */ - if (cp->tcp.numlyrs > 16384) { - fprintf(stderr, "too many layers\n"); - goto error; - } - - /* There must be at least one resolution level. */ - if (cp->tccp.maxrlvls < 1) { - fprintf(stderr, "must be at least one resolution level\n"); - goto error; - } - - /* Ensure that the number of guard bits is valid. */ - if (cp->tccp.numgbits > 8) { - fprintf(stderr, "invalid number of guard bits\n"); - goto error; - } - - /* Ensure that the intermediate layer rates are valid. */ - if (tcp->numlyrs > 1) { - /* The intermediate layers rates must increase monotonically. */ - for (lyrno = 0; lyrno + 2 < tcp->numlyrs; ++lyrno) { - if (tcp->ilyrrates[lyrno] >= tcp->ilyrrates[lyrno + 1]) { - fprintf(stderr, - "intermediate layer rates must increase " - "monotonically\n"); - goto error; - } - } - /* The intermediate layer rates must be less than the overall rate. */ - if (cp->totalsize != UINT_FAST32_MAX) { - for (lyrno = 0; lyrno < tcp->numlyrs - 1; ++lyrno) { - if (jpc_fixtodbl(tcp->ilyrrates[lyrno]) > - ((double) cp->totalsize) / cp->rawsize) { - fprintf(stderr, - "warning: intermediate layer rates must be " - "less than overall rate\n"); - goto error; - } - } - } - } - - if (ilyrrates) { - jas_free(ilyrrates); - } - - return cp; - -error: - - if (ilyrrates) { - jas_free(ilyrrates); - } - if (tvp) { - jas_tvparser_destroy(tvp); - } - if (cp) { - jpc_enc_cp_destroy(cp); - } - return 0; -} - - - -void -jpc_enc_cp_destroy(jpc_enc_cp_t *cp) { - - if (cp->ccps) { - if (cp->tcp.ilyrrates) { - jas_free(cp->tcp.ilyrrates); - } - jas_free(cp->ccps); - } - jas_free(cp); -} - - - -int -ratestrtosize(const char *s, uint_fast32_t rawsize, uint_fast32_t *size) { - - char *cp; - jpc_flt_t f; - - /* Note: This function must not modify output size on failure. */ - if ((cp = strchr(s, 'B'))) { - *size = atoi(s); - } else { - f = atof(s); - if (f < 0) { - *size = 0; - } else if (f > 1.0) { - *size = rawsize + 1; - } else { - *size = f * rawsize; - } - } - return 0; -} - -/*****************************************************************************\ -* Encoder constructor and destructor. -\*****************************************************************************/ - -jpc_enc_t * -jpc_enc_create(jpc_enc_cp_t *cp, jas_stream_t *out, jas_image_t *image) { - - jpc_enc_t *enc; - - enc = 0; - - if (!(enc = jas_malloc(sizeof(jpc_enc_t)))) { - goto error; - } - - enc->image = image; - enc->out = out; - enc->cp = cp; - enc->cstate = 0; - enc->tmpstream = 0; - enc->mrk = 0; - enc->curtile = 0; - - if (!(enc->cstate = jpc_cstate_create())) { - goto error; - } - enc->len = 0; - enc->mainbodysize = 0; - - return enc; - -error: - - if (enc) { - jpc_enc_destroy(enc); - } - return 0; -} - - - -void -jpc_enc_destroy(jpc_enc_t *enc) { - - /* The image object (i.e., enc->image) and output stream object - (i.e., enc->out) are created outside of the encoder. - Therefore, they must not be destroyed here. - */ - - if (enc->curtile) { - jpc_enc_tile_destroy(enc->curtile); - } - if (enc->cp) { - jpc_enc_cp_destroy(enc->cp); - } - if (enc->cstate) { - jpc_cstate_destroy(enc->cstate); - } - if (enc->tmpstream) { - jas_stream_close(enc->tmpstream); - } - - jas_free(enc); -} - - - -static int -jpc_enc_encodemainhdr(jpc_enc_t *enc) { - - jpc_siz_t *siz; - jpc_cod_t *cod; - jpc_qcd_t *qcd; - int i; - long startoff; - long mainhdrlen; - jpc_enc_cp_t *cp; - jpc_qcc_t *qcc; - jpc_enc_tccp_t *tccp; - uint_fast16_t cmptno; - jpc_tsfb_band_t bandinfos[JPC_MAXBANDS]; - jpc_enc_tcp_t *tcp; - jpc_tsfb_t *tsfb; - jpc_tsfb_band_t *bandinfo; - uint_fast16_t numbands; - uint_fast16_t bandno; - uint_fast16_t rlvlno; - uint_fast16_t analgain; - jpc_fix_t absstepsize; - char buf[1024]; - jpc_com_t *com; - - cp = enc->cp; - - startoff = jas_stream_getrwcount(enc->out); - - /* Write SOC marker segment. */ - if (!(enc->mrk = jpc_ms_create(JPC_MS_SOC))) { - return -1; - } - if (jpc_putms(enc->out, enc->cstate, enc->mrk)) { - fprintf(stderr, "cannot write SOC marker\n"); - return -1; - } - jpc_ms_destroy(enc->mrk); - enc->mrk = 0; - - /* Write SIZ marker segment. */ - if (!(enc->mrk = jpc_ms_create(JPC_MS_SIZ))) { - return -1; - } - siz = &enc->mrk->parms.siz; - siz->caps = 0; - siz->xoff = cp->imgareatlx; - siz->yoff = cp->imgareatly; - siz->width = cp->refgrdwidth; - siz->height = cp->refgrdheight; - siz->tilexoff = cp->tilegrdoffx; - siz->tileyoff = cp->tilegrdoffy; - siz->tilewidth = cp->tilewidth; - siz->tileheight = cp->tileheight; - siz->numcomps = cp->numcmpts; - siz->comps = jas_malloc(siz->numcomps * sizeof(jpc_sizcomp_t)); - assert(siz->comps); - for (i = 0; i < cp->numcmpts; ++i) { - siz->comps[i].prec = cp->ccps[i].prec; - siz->comps[i].sgnd = cp->ccps[i].sgnd; - siz->comps[i].hsamp = cp->ccps[i].sampgrdstepx; - siz->comps[i].vsamp = cp->ccps[i].sampgrdstepy; - } - if (jpc_putms(enc->out, enc->cstate, enc->mrk)) { - fprintf(stderr, "cannot write SIZ marker\n"); - return -1; - } - jpc_ms_destroy(enc->mrk); - enc->mrk = 0; - - if (!(enc->mrk = jpc_ms_create(JPC_MS_COM))) { - return -1; - } - sprintf(buf, "Creator: JasPer Version %s", jas_getversion()); - com = &enc->mrk->parms.com; - com->len = strlen(buf); - com->regid = JPC_COM_LATIN; - if (!(com->data = JAS_CAST(unsigned char *, jas_strdup(buf)))) { - abort(); - } - if (jpc_putms(enc->out, enc->cstate, enc->mrk)) { - fprintf(stderr, "cannot write COM marker\n"); - return -1; - } - jpc_ms_destroy(enc->mrk); - enc->mrk = 0; - -#if 0 - if (!(enc->mrk = jpc_ms_create(JPC_MS_CRG))) { - return -1; - } - crg = &enc->mrk->parms.crg; - crg->comps = jas_malloc(crg->numcomps * sizeof(jpc_crgcomp_t)); - if (jpc_putms(enc->out, enc->cstate, enc->mrk)) { - fprintf(stderr, "cannot write CRG marker\n"); - return -1; - } - jpc_ms_destroy(enc->mrk); - enc->mrk = 0; -#endif - - tcp = &cp->tcp; - tccp = &cp->tccp; - for (cmptno = 0; cmptno < cp->numcmpts; ++cmptno) { - tsfb = jpc_cod_gettsfb(tccp->qmfbid, tccp->maxrlvls - 1); - jpc_tsfb_getbands(tsfb, 0, 0, 1 << tccp->maxrlvls, 1 << tccp->maxrlvls, - bandinfos); - jpc_tsfb_destroy(tsfb); - numbands = 3 * tccp->maxrlvls - 2; - for (bandno = 0, bandinfo = bandinfos; bandno < numbands; - ++bandno, ++bandinfo) { - rlvlno = (bandno) ? ((bandno - 1) / 3 + 1) : 0; - analgain = JPC_NOMINALGAIN(tccp->qmfbid, tccp->maxrlvls, - rlvlno, bandinfo->orient); - if (!tcp->intmode) { - absstepsize = jpc_fix_div(jpc_inttofix(1 << - (analgain + 1)), bandinfo->synenergywt); - } else { - absstepsize = jpc_inttofix(1); - } - cp->ccps[cmptno].stepsizes[bandno] = - jpc_abstorelstepsize(absstepsize, - cp->ccps[cmptno].prec + analgain); - } - cp->ccps[cmptno].numstepsizes = numbands; - } - - if (!(enc->mrk = jpc_ms_create(JPC_MS_COD))) { - return -1; - } - cod = &enc->mrk->parms.cod; - cod->csty = cp->tccp.csty | cp->tcp.csty; - cod->compparms.csty = cp->tccp.csty | cp->tcp.csty; - cod->compparms.numdlvls = cp->tccp.maxrlvls - 1; - cod->compparms.numrlvls = cp->tccp.maxrlvls; - cod->prg = cp->tcp.prg; - cod->numlyrs = cp->tcp.numlyrs; - cod->compparms.cblkwidthval = JPC_COX_CBLKSIZEEXPN(cp->tccp.cblkwidthexpn); - cod->compparms.cblkheightval = - JPC_COX_CBLKSIZEEXPN(cp->tccp.cblkheightexpn); - cod->compparms.cblksty = cp->tccp.cblksty; - cod->compparms.qmfbid = cp->tccp.qmfbid; - cod->mctrans = (cp->tcp.mctid != JPC_MCT_NONE); - if (tccp->csty & JPC_COX_PRT) { - for (rlvlno = 0; rlvlno < tccp->maxrlvls; ++rlvlno) { - cod->compparms.rlvls[rlvlno].parwidthval = - tccp->prcwidthexpns[rlvlno]; - cod->compparms.rlvls[rlvlno].parheightval = - tccp->prcheightexpns[rlvlno]; - } - } - if (jpc_putms(enc->out, enc->cstate, enc->mrk)) { - fprintf(stderr, "cannot write COD marker\n"); - return -1; - } - jpc_ms_destroy(enc->mrk); - enc->mrk = 0; - - if (!(enc->mrk = jpc_ms_create(JPC_MS_QCD))) { - return -1; - } - qcd = &enc->mrk->parms.qcd; - qcd->compparms.qntsty = (tccp->qmfbid == JPC_COX_INS) ? - JPC_QCX_SEQNT : JPC_QCX_NOQNT; - qcd->compparms.numstepsizes = cp->ccps[0].numstepsizes; - qcd->compparms.numguard = cp->tccp.numgbits; - qcd->compparms.stepsizes = cp->ccps[0].stepsizes; - if (jpc_putms(enc->out, enc->cstate, enc->mrk)) { - return -1; - } - /* We do not want the step size array to be freed! */ - qcd->compparms.stepsizes = 0; - jpc_ms_destroy(enc->mrk); - enc->mrk = 0; - - tccp = &cp->tccp; - for (cmptno = 1; cmptno < cp->numcmpts; ++cmptno) { - if (!(enc->mrk = jpc_ms_create(JPC_MS_QCC))) { - return -1; - } - qcc = &enc->mrk->parms.qcc; - qcc->compno = cmptno; - qcc->compparms.qntsty = (tccp->qmfbid == JPC_COX_INS) ? - JPC_QCX_SEQNT : JPC_QCX_NOQNT; - qcc->compparms.numstepsizes = cp->ccps[cmptno].numstepsizes; - qcc->compparms.numguard = cp->tccp.numgbits; - qcc->compparms.stepsizes = cp->ccps[cmptno].stepsizes; - if (jpc_putms(enc->out, enc->cstate, enc->mrk)) { - return -1; - } - /* We do not want the step size array to be freed! */ - qcc->compparms.stepsizes = 0; - jpc_ms_destroy(enc->mrk); - enc->mrk = 0; - } - -#define MAINTLRLEN 2 - mainhdrlen = jas_stream_getrwcount(enc->out) - startoff; - enc->len += mainhdrlen; - if (enc->cp->totalsize != UINT_FAST32_MAX) { - uint_fast32_t overhead; - overhead = mainhdrlen + MAINTLRLEN; - enc->mainbodysize = (enc->cp->totalsize >= overhead) ? - (enc->cp->totalsize - overhead) : 0; - } else { - enc->mainbodysize = UINT_FAST32_MAX; - } - - return 0; -} - - - -int -jpc_enc_encodetiledata(jpc_enc_t *enc) { - - assert(enc->tmpstream); - if (jpc_enc_encpkts(enc, enc->tmpstream)) { - return -1; - } - return 0; -} - - - -void -quantize(jas_matrix_t *data, jpc_fix_t stepsize) { - - int i; - int j; - jpc_fix_t t; - - if (stepsize == jpc_inttofix(1)) { - return; - } - - for (i = 0; i < jas_matrix_numrows(data); ++i) { - for (j = 0; j < jas_matrix_numcols(data); ++j) { - t = jas_matrix_get(data, i, j); - -{ - if (t < 0) { - t = jpc_fix_neg(jpc_fix_div(jpc_fix_neg(t), stepsize)); - } else { - t = jpc_fix_div(t, stepsize); - } -} - - jas_matrix_set(data, i, j, t); - } - } -} - - - -static void -calcrdslopes(jpc_enc_cblk_t *cblk) { - - jpc_enc_pass_t *endpasses; - jpc_enc_pass_t *pass0; - jpc_enc_pass_t *pass1; - jpc_enc_pass_t *pass2; - jpc_flt_t slope0; - jpc_flt_t slope; - jpc_flt_t dd; - long dr; - - endpasses = &cblk->passes[cblk->numpasses]; - pass2 = cblk->passes; - slope0 = 0; - while (pass2 != endpasses) { - pass0 = 0; - for (pass1 = cblk->passes; pass1 != endpasses; ++pass1) { - dd = pass1->cumwmsedec; - dr = pass1->end; - if (pass0) { - dd -= pass0->cumwmsedec; - dr -= pass0->end; - } - if (dd <= 0) { - pass1->rdslope = JPC_BADRDSLOPE; - if (pass1 >= pass2) { - pass2 = &pass1[1]; - } - continue; - } - if (pass1 < pass2 && pass1->rdslope <= 0) { - continue; - } - if (!dr) { - assert(pass0); - pass0->rdslope = 0; - break; - } - slope = dd / dr; - if (pass0 && slope >= slope0) { - pass0->rdslope = 0; - break; - } - pass1->rdslope = slope; - if (pass1 >= pass2) { - pass2 = &pass1[1]; - } - pass0 = pass1; - slope0 = slope; - } - } - -#if 0 - for (pass0 = cblk->passes; pass0 != endpasses; ++pass0) { - if (pass0->rdslope > 0.0) { - fprintf(stderr, "pass %02d nmsedec=%lf dec=%lf end=%d %lf\n", - pass0 - cblk->passes, - fixtodbl(pass0->nmsedec), pass0->wmsedec, - pass0->end, pass0->rdslope); - } - } -#endif -} - - - -static void -traceLayerSizes(const uint_fast32_t * const lyrSizes, - unsigned int const layerCt) { - - if (jas_getdbglevel() > 0) { - unsigned int i; - for (i = 0; i < layerCt; ++i) { - fprintf(stderr, "Layer %u size = ", i); - - if (lyrSizes[i] == UINT_FAST32_MAX) - fprintf(stderr, "Unlimited"); - else - fprintf(stderr, "%u", (unsigned)lyrSizes[i]); - fprintf(stderr, "\n"); - } - } -} - - - -static void -computeLayerSizes(jpc_enc_t * const encP, - jpc_enc_tile_t * const tileP, - jpc_enc_cp_t * const cpP, - double const rho, - long const tilehdrlen, - const char ** const errorP) { - - /* Note that in allowed sizes, UINT_FAST32_MAX is a special value meaning - "unlimited". - */ - - unsigned int const lastLyrno = tileP->numlyrs - 1; - - unsigned int lyrno; - - assert(tileP->numlyrs > 0); - - for (lyrno = 0; lyrno < lastLyrno; ++lyrno) { - tileP->lyrsizes[lyrno] = tileP->rawsize * jpc_fixtodbl( - cpP->tcp.ilyrrates[lyrno]); - } - - tileP->lyrsizes[lastLyrno] = - (cpP->totalsize != UINT_FAST32_MAX) ? - (rho * encP->mainbodysize) : UINT_FAST32_MAX; - - - /* Subtract 'tilehdrlen' from every layer. */ - - for (lyrno = 0; lyrno < tileP->numlyrs; ++lyrno) { - if (tileP->lyrsizes[lyrno] != UINT_FAST32_MAX) { - if (tilehdrlen <= tileP->lyrsizes[lyrno]) { - tileP->lyrsizes[lyrno] -= tilehdrlen; - } else { - tileP->lyrsizes[lyrno] = 0; - } - } - } - - if (tileP->lyrsizes[lastLyrno] < 1) - pm_asprintf(errorP, "Cannot make image that small (%u bytes). " - "Even with pixels compressed as far as possible, metadata " - "would exceed the limit", - (unsigned)cpP->totalsize); - else - *errorP = NULL; - - traceLayerSizes(tileP->lyrsizes, tileP->numlyrs); -} - - - -static void -dump_layeringinfo(jpc_enc_t *enc) { - - jpc_enc_tcmpt_t *tcmpt; - uint_fast16_t tcmptno; - jpc_enc_rlvl_t *rlvl; - uint_fast16_t rlvlno; - jpc_enc_band_t *band; - uint_fast16_t bandno; - jpc_enc_prc_t *prc; - uint_fast32_t prcno; - jpc_enc_cblk_t *cblk; - uint_fast16_t cblkno; - jpc_enc_pass_t *pass; - uint_fast16_t passno; - int lyrno; - jpc_enc_tile_t *tile; - - tile = enc->curtile; - - for (lyrno = 0; lyrno < tile->numlyrs; ++lyrno) { - fprintf(stderr, "lyrno = %02d\n", lyrno); - for (tcmptno = 0, tcmpt = tile->tcmpts; tcmptno < tile->numtcmpts; - ++tcmptno, ++tcmpt) { - for (rlvlno = 0, rlvl = tcmpt->rlvls; rlvlno < tcmpt->numrlvls; - ++rlvlno, ++rlvl) { - if (!rlvl->bands) { - continue; - } - for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands; - ++bandno, ++band) { - if (!band->data) { - continue; - } - for (prcno = 0, prc = band->prcs; prcno < rlvl->numprcs; - ++prcno, ++prc) { - if (!prc->cblks) { - continue; - } - for (cblkno = 0, cblk = prc->cblks; cblkno < - prc->numcblks; ++cblkno, ++cblk) { - for (passno = 0, pass = cblk->passes; - passno < cblk->numpasses && - pass->lyrno == lyrno; - ++passno, ++pass) { - fprintf(stderr, - "lyrno=%02d cmptno=%02d " - "rlvlno=%02d bandno=%02d " - "prcno=%02d cblkno=%03d " - "passno=%03d\n", - lyrno, (int)tcmptno, (int)rlvlno, - (int)bandno, (int)prcno, (int) cblkno, - (int)passno); - } - } - } - } - } - } - } -} - - - - -static void -trace_layeringinfo(jpc_enc_t * const encP) { - - if (jas_getdbglevel() >= 5) - dump_layeringinfo(encP); -} - - - -static void -validateCumlensIncreases(const uint_fast32_t * const cumlens, - unsigned int const numlyrs) { - unsigned int lyrno; - - for (lyrno = 1; lyrno < numlyrs - 1; ++lyrno) { - if (cumlens[lyrno - 1] > cumlens[lyrno]) { - abort(); - } - } -} - - - -static void -findMinMaxRDSlopeValues(jpc_enc_tile_t * const tileP, - jpc_flt_t * const mnrdslopeP, - jpc_flt_t * const mxrdslopeP) { -/*---------------------------------------------------------------------------- - Find minimum and maximum R-D slope values. ------------------------------------------------------------------------------*/ - jpc_flt_t mxrdslope; - jpc_flt_t mnrdslope; - jpc_enc_tcmpt_t * endcomps; - jpc_enc_tcmpt_t * compP; - - mnrdslope = DBL_MAX; - mxrdslope = 0; - endcomps = &tileP->tcmpts[tileP->numtcmpts]; - - for (compP = tileP->tcmpts; compP != endcomps; ++compP) { - jpc_enc_rlvl_t * const endlvlsP = &compP->rlvls[compP->numrlvls]; - - jpc_enc_rlvl_t * lvlP; - - for (lvlP = compP->rlvls; lvlP != endlvlsP; ++lvlP) { - jpc_enc_band_t * endbandsP; - jpc_enc_band_t * bandP; - - if (lvlP->bands) { - endbandsP = &lvlP->bands[lvlP->numbands]; - for (bandP = lvlP->bands; bandP != endbandsP; ++bandP) { - uint_fast32_t prcno; - jpc_enc_prc_t * prcP; - - if (bandP->data) { - for (prcno = 0, prcP = bandP->prcs; - prcno < lvlP->numprcs; - ++prcno, ++prcP) { - - jpc_enc_cblk_t * endcblksP; - jpc_enc_cblk_t * cblkP; - - if (prcP->cblks) { - endcblksP = &prcP->cblks[prcP->numcblks]; - for (cblkP = prcP->cblks; - cblkP != endcblksP; - ++cblkP) { - jpc_enc_pass_t * endpassesP; - jpc_enc_pass_t * passP; - - calcrdslopes(cblkP); - endpassesP = - &cblkP->passes[cblkP->numpasses]; - for (passP = cblkP->passes; - passP != endpassesP; - ++passP) { - if (passP->rdslope > 0) { - mnrdslope = - MIN(passP->rdslope, mnrdslope); - mxrdslope = - MAX(passP->rdslope, mxrdslope); - } - } - } - } - } - } - } - } - } - } - trace("min rdslope = %f max rdslope = %f", mnrdslope, mxrdslope); - - *mnrdslopeP = mnrdslope; - *mxrdslopeP = mxrdslope; -} - - - -static void -performTier2CodingOneLayer(jpc_enc_t * const encP, - jpc_enc_tile_t * const tileP, - unsigned int const lyrno, - jas_stream_t * const outP, - const char ** const errorP) { -/*---------------------------------------------------------------------------- - Encode Layer 'lyrno' of tile *tileP to stream *outP. - - Use the pass assignment already in *tileP. ------------------------------------------------------------------------------*/ - jpc_enc_tcmpt_t * const endcompsP = &tileP->tcmpts[tileP->numtcmpts]; - - jpc_enc_tcmpt_t * compP; - - *errorP = NULL; /* initial assumption */ - - for (compP = tileP->tcmpts; compP != endcompsP && !*errorP; ++compP) { - jpc_enc_rlvl_t * const endlvlsP = &compP->rlvls[compP->numrlvls]; - - jpc_enc_rlvl_t * lvlP; - - for (lvlP = compP->rlvls; lvlP != endlvlsP && !*errorP; ++lvlP) { - if (lvlP->bands) { - uint_fast32_t prcno; - for (prcno = 0; prcno < lvlP->numprcs && !*errorP; ++prcno) { - int rc; - rc = jpc_enc_encpkt(encP, outP, compP - tileP->tcmpts, - lvlP - compP->rlvls, prcno, lyrno); - if (rc != 0) - pm_asprintf(errorP, "jpc_enc_encpkt() failed on " - "precinct %u", (unsigned)prcno); - } - } - } - } -} - - - -static void -assignHighSlopePassesToLayer(jpc_enc_t * const encP, - jpc_enc_tile_t * const tileP, - unsigned int const lyrno, - bool const haveThresh, - jpc_flt_t const thresh) { -/*---------------------------------------------------------------------------- - Assign all passes with R-D slopes greater than or equal to 'thresh' to layer - 'lyrno' and the rest to no layer. - - If 'haveThresh' is false, assign all passes to no layer. ------------------------------------------------------------------------------*/ - jpc_enc_tcmpt_t * endcompsP; - jpc_enc_tcmpt_t * compP; - - endcompsP = &tileP->tcmpts[tileP->numtcmpts]; - for (compP = tileP->tcmpts; compP != endcompsP; ++compP) { - jpc_enc_rlvl_t * const endlvlsP = &compP->rlvls[compP->numrlvls]; - - jpc_enc_rlvl_t * lvlP; - - for (lvlP = compP->rlvls; lvlP != endlvlsP; ++lvlP) { - if (lvlP->bands) { - jpc_enc_band_t * const endbandsP = - &lvlP->bands[lvlP->numbands]; - jpc_enc_band_t * bandP; - for (bandP = lvlP->bands; bandP != endbandsP; ++bandP) { - if (bandP->data) { - jpc_enc_prc_t * prcP; - uint_fast32_t prcno; - for (prcno = 0, prcP = bandP->prcs; - prcno < lvlP->numprcs; - ++prcno, ++prcP) { - if (prcP->cblks) { - jpc_enc_cblk_t * const endcblksP = - &prcP->cblks[prcP->numcblks]; - jpc_enc_cblk_t * cblkP; - for (cblkP = prcP->cblks; - cblkP != endcblksP; - ++cblkP) { - if (cblkP->curpass) { - jpc_enc_pass_t * const endpassesP = - &cblkP->passes[cblkP->numpasses]; - jpc_enc_pass_t * pass1P; - jpc_enc_pass_t * passP; - - pass1P = cblkP->curpass; - if (haveThresh) { - jpc_enc_pass_t * passP; - for (passP = cblkP->curpass; - passP != endpassesP; - ++passP) { - if (passP->rdslope >= thresh) - pass1P = passP + 1; - } - } - for (passP = cblkP->curpass; - passP != pass1P; - ++passP) { - passP->lyrno = lyrno; - } - for (; passP != endpassesP; ++passP) { - passP->lyrno = -1; - } - - } - } - } - } - } - } - } - } - } -} - - - -static void -doLayer(jpc_enc_t * const encP, - jpc_enc_tile_t * const tileP, - unsigned int const lyrno, - uint_fast32_t const allowedSize, - jpc_flt_t const mnrdslope, - jpc_flt_t const mxrdslope, - jas_stream_t * const outP, - const char ** const errorP) { -/*---------------------------------------------------------------------------- - Assign passes to layer 'lyrno' such that the cumulative size through - this layer is as close as possible to, but not exceeding, 'allowedSize'. ------------------------------------------------------------------------------*/ - bool haveGoodThresh; - jpc_flt_t goodThresh; - - if (allowedSize == UINT_FAST32_MAX) { - /* There's no rate constraint (This can be true of the last layer, - e.g. for lossless coding). */ - goodThresh = -1; - haveGoodThresh = true; - *errorP = NULL; - } else { - /* Iterate through successive approximations of the threshold, finding - the threshold that gets us closest to 'allowedSize' without going - over. In each iteration, we do the full encoding, note the size, - and then restore the previous state. - */ - long pos; - jpc_flt_t lo; - jpc_flt_t hi; - unsigned int numiters; - - lo = mnrdslope; /* initial value */ - hi = mxrdslope; /* initial value */ - numiters = 0; /* initial value */ - haveGoodThresh = false; /* initial value */ - goodThresh = 0; /* initial value */ - - do { - if (allowedSize == UINT_FAST32_MAX) { - /* There's no rate constraint (This can be true of the last - layer, e.g. for lossless coding). */ - goodThresh = -1; - haveGoodThresh = true; - } else { - jpc_flt_t const thresh = (lo + hi) / 2; - - int rc; - long oldpos; - - /* Save the tier 2 coding state. */ - jpc_save_t2state(encP); - oldpos = jas_stream_tell(outP); - assert(oldpos >= 0); - - assignHighSlopePassesToLayer(encP, tileP, lyrno, true, thresh); - - performTier2CodingOneLayer(encP, tileP, lyrno, outP, errorP); - - if (!*errorP) { - pos = jas_stream_tell(outP); - - /* Check the rate constraint. */ - assert(pos >= 0); - if (pos > allowedSize) { - /* The rate is too high. */ - lo = thresh; - } else if (pos <= allowedSize) { - /* The rate is low enough, so try higher. */ - hi = thresh; - if (!haveGoodThresh || thresh < goodThresh) { - goodThresh = thresh; - haveGoodThresh = true; - } - } - } - /* Restore the tier 2 coding state. */ - jpc_restore_t2state(encP); - rc = jas_stream_seek(outP, oldpos, SEEK_SET); - if (rc < 0) - abort(); - - trace("iter %u: allowedlen=%08ld actuallen=%08ld thresh=%f", - numiters, allowedSize, pos, thresh); - } - ++numiters; - } while (lo < hi - 1e-3 && numiters < 32 && !*errorP); - } - - if (!*errorP) { - if (!haveGoodThresh) - fprintf(stderr, "warning: empty layer generated\n"); - - trace("haveGoodThresh %u goodthresh %f", haveGoodThresh, goodThresh); - - assignHighSlopePassesToLayer(encP, tileP, lyrno, - haveGoodThresh, goodThresh); - - performTier2CodingOneLayer(encP, tileP, lyrno, outP, errorP); - } -} - - - -static void -performTier2Coding(jpc_enc_t * const encP, - unsigned int const numlyrs, - uint_fast32_t * const cumlens, - const char ** const errorP) { -/*---------------------------------------------------------------------------- - Encode in 'numlyrs' layers, such that at each layer L, the size is - cumlens[L]. ------------------------------------------------------------------------------*/ - jpc_enc_tile_t * const tileP = encP->curtile; - - jas_stream_t * outP; - unsigned int lyrno; - jpc_flt_t mnrdslope; - jpc_flt_t mxrdslope; - - validateCumlensIncreases(cumlens, numlyrs); - - outP = jas_stream_memopen(0, 0); - - if (!outP) - pm_asprintf(errorP, "jas_stream_memopen() failed"); - else { - findMinMaxRDSlopeValues(tileP, &mnrdslope, &mxrdslope); - - jpc_init_t2state(encP, 1); - - for (lyrno = 0, *errorP = NULL; - lyrno < numlyrs && !*errorP; - ++lyrno) { - doLayer(encP, tileP, lyrno, cumlens[lyrno], - mnrdslope, mxrdslope, outP, errorP); - } - - if (!*errorP) { - trace_layeringinfo(encP); - - jas_stream_close(outP); - } - } - JAS_DBGLOG(10, ("done doing rateallocation\n")); -} - - - -/*****************************************************************************\ -* Tile constructors and destructors. -\*****************************************************************************/ - -jpc_enc_tile_t * -jpc_enc_tile_create(jpc_enc_cp_t *cp, jas_image_t *image, int tileno) { - - jpc_enc_tile_t *tile; - uint_fast32_t htileno; - uint_fast32_t vtileno; - uint_fast16_t lyrno; - uint_fast16_t cmptno; - jpc_enc_tcmpt_t *tcmpt; - - if (!(tile = jas_malloc(sizeof(jpc_enc_tile_t)))) { - goto error; - } - - /* Initialize a few members used in error recovery. */ - tile->tcmpts = 0; - tile->lyrsizes = 0; - tile->numtcmpts = cp->numcmpts; - tile->pi = 0; - - tile->tileno = tileno; - htileno = tileno % cp->numhtiles; - vtileno = tileno / cp->numhtiles; - - /* Calculate the coordinates of the top-left and bottom-right - corners of the tile. */ - tile->tlx = JAS_MAX(cp->tilegrdoffx + htileno * cp->tilewidth, - cp->imgareatlx); - tile->tly = JAS_MAX(cp->tilegrdoffy + vtileno * cp->tileheight, - cp->imgareatly); - tile->brx = JAS_MIN(cp->tilegrdoffx + (htileno + 1) * cp->tilewidth, - cp->refgrdwidth); - tile->bry = JAS_MIN(cp->tilegrdoffy + (vtileno + 1) * cp->tileheight, - cp->refgrdheight); - - /* Initialize some tile coding parameters. */ - tile->intmode = cp->tcp.intmode; - tile->csty = cp->tcp.csty; - tile->prg = cp->tcp.prg; - tile->mctid = cp->tcp.mctid; - - tile->numlyrs = cp->tcp.numlyrs; - if (!(tile->lyrsizes = jas_malloc(tile->numlyrs * - sizeof(uint_fast32_t)))) { - goto error; - } - for (lyrno = 0; lyrno < tile->numlyrs; ++lyrno) { - tile->lyrsizes[lyrno] = 0; - } - - /* Allocate an array for the per-tile-component information. */ - if (!(tile->tcmpts = jas_malloc(cp->numcmpts * sizeof(jpc_enc_tcmpt_t)))) { - goto error; - } - /* Initialize a few members critical for error recovery. */ - for (cmptno = 0, tcmpt = tile->tcmpts; cmptno < cp->numcmpts; - ++cmptno, ++tcmpt) { - tcmpt->rlvls = 0; - tcmpt->tsfb = 0; - tcmpt->data = 0; - } - /* Initialize the per-tile-component information. */ - for (cmptno = 0, tcmpt = tile->tcmpts; cmptno < cp->numcmpts; - ++cmptno, ++tcmpt) { - if (!tcmpt_create(tcmpt, cp, image, tile)) { - goto error; - } - } - - /* Initialize the synthesis weights for the MCT. */ - switch (tile->mctid) { - case JPC_MCT_RCT: - tile->tcmpts[0].synweight = jpc_dbltofix(sqrt(3.0)); - tile->tcmpts[1].synweight = jpc_dbltofix(sqrt(0.6875)); - tile->tcmpts[2].synweight = jpc_dbltofix(sqrt(0.6875)); - break; - case JPC_MCT_ICT: - tile->tcmpts[0].synweight = jpc_dbltofix(sqrt(3.0000)); - tile->tcmpts[1].synweight = jpc_dbltofix(sqrt(3.2584)); - tile->tcmpts[2].synweight = jpc_dbltofix(sqrt(2.4755)); - break; - default: - case JPC_MCT_NONE: - for (cmptno = 0, tcmpt = tile->tcmpts; cmptno < cp->numcmpts; - ++cmptno, ++tcmpt) { - tcmpt->synweight = JPC_FIX_ONE; - } - break; - } - - if (!(tile->pi = jpc_enc_pi_create(cp, tile))) { - goto error; - } - - return tile; - -error: - - if (tile) { - jpc_enc_tile_destroy(tile); - } - return 0; -} - - - -void -jpc_enc_tile_destroy(jpc_enc_tile_t *tile) { - - jpc_enc_tcmpt_t *tcmpt; - uint_fast16_t cmptno; - - if (tile->tcmpts) { - for (cmptno = 0, tcmpt = tile->tcmpts; cmptno < - tile->numtcmpts; ++cmptno, ++tcmpt) { - tcmpt_destroy(tcmpt); - } - jas_free(tile->tcmpts); - } - if (tile->lyrsizes) { - jas_free(tile->lyrsizes); - } - if (tile->pi) { - jpc_pi_destroy(tile->pi); - } - jas_free(tile); -} - - - -static jpc_enc_tcmpt_t * -tcmpt_create(jpc_enc_tcmpt_t * const tcmpt, - jpc_enc_cp_t * const cp, - jas_image_t * const image, - jpc_enc_tile_t * const tile) { - - uint_fast16_t cmptno; - uint_fast16_t rlvlno; - jpc_enc_rlvl_t *rlvl; - uint_fast32_t tlx; - uint_fast32_t tly; - uint_fast32_t brx; - uint_fast32_t bry; - uint_fast32_t cmpttlx; - uint_fast32_t cmpttly; - jpc_enc_ccp_t *ccp; - jpc_tsfb_band_t bandinfos[JPC_MAXBANDS]; - - tcmpt->tile = tile; - tcmpt->tsfb = 0; - tcmpt->data = 0; - tcmpt->rlvls = 0; - - /* Deduce the component number. */ - cmptno = tcmpt - tile->tcmpts; - - ccp = &cp->ccps[cmptno]; - - /* Compute the coordinates of the top-left and bottom-right - corners of this tile-component. */ - tlx = JPC_CEILDIV(tile->tlx, ccp->sampgrdstepx); - tly = JPC_CEILDIV(tile->tly, ccp->sampgrdstepy); - brx = JPC_CEILDIV(tile->brx, ccp->sampgrdstepx); - bry = JPC_CEILDIV(tile->bry, ccp->sampgrdstepy); - - /* Create a sequence to hold the tile-component sample data. */ - tcmpt->data = jas_seq2d_create(tlx, tly, brx, bry); - if (!tcmpt->data) - goto error; - - /* Get the image data associated with this tile-component. */ - cmpttlx = JPC_CEILDIV(cp->imgareatlx, ccp->sampgrdstepx); - cmpttly = JPC_CEILDIV(cp->imgareatly, ccp->sampgrdstepy); - if (jas_image_readcmpt(image, cmptno, tlx - cmpttlx, tly - cmpttly, - brx - tlx, bry - tly, tcmpt->data)) { - goto error; - } - - tcmpt->synweight = 0; - tcmpt->qmfbid = cp->tccp.qmfbid; - tcmpt->numrlvls = cp->tccp.maxrlvls; - tcmpt->numbands = 3 * tcmpt->numrlvls - 2; - - tcmpt->tsfb = jpc_cod_gettsfb(tcmpt->qmfbid, tcmpt->numrlvls - 1); - - if (!tcmpt->tsfb) - goto error; - - for (rlvlno = 0; rlvlno < tcmpt->numrlvls; ++rlvlno) { - tcmpt->prcwidthexpns[rlvlno] = cp->tccp.prcwidthexpns[rlvlno]; - tcmpt->prcheightexpns[rlvlno] = cp->tccp.prcheightexpns[rlvlno]; - } - tcmpt->cblkwidthexpn = cp->tccp.cblkwidthexpn; - tcmpt->cblkheightexpn = cp->tccp.cblkheightexpn; - tcmpt->cblksty = cp->tccp.cblksty; - tcmpt->csty = cp->tccp.csty; - - tcmpt->numstepsizes = tcmpt->numbands; - assert(tcmpt->numstepsizes <= JPC_MAXBANDS); - memset(tcmpt->stepsizes, 0, - sizeof(tcmpt->numstepsizes * sizeof(uint_fast16_t))); - - /* Retrieve information about the various bands. */ - jpc_tsfb_getbands(tcmpt->tsfb, jas_seq2d_xstart(tcmpt->data), - jas_seq2d_ystart(tcmpt->data), - jas_seq2d_xend(tcmpt->data), - jas_seq2d_yend(tcmpt->data), bandinfos); - - tcmpt->rlvls = jas_malloc(tcmpt->numrlvls * sizeof(jpc_enc_rlvl_t)); - if (!tcmpt->rlvls) - goto error; - - for (rlvlno = 0, rlvl = tcmpt->rlvls; rlvlno < tcmpt->numrlvls; - ++rlvlno, ++rlvl) { - rlvl->bands = 0; - rlvl->tcmpt = tcmpt; - } - for (rlvlno = 0, rlvl = tcmpt->rlvls; rlvlno < tcmpt->numrlvls; - ++rlvlno, ++rlvl) { - if (!rlvl_create(rlvl, cp, tcmpt, bandinfos)) { - goto error; - } - } - - return tcmpt; - -error: - - tcmpt_destroy(tcmpt); - return 0; - -} - - - -static void -tcmpt_destroy(jpc_enc_tcmpt_t *tcmpt) { - - jpc_enc_rlvl_t *rlvl; - uint_fast16_t rlvlno; - - if (tcmpt->rlvls) { - for (rlvlno = 0, rlvl = tcmpt->rlvls; rlvlno < tcmpt->numrlvls; - ++rlvlno, ++rlvl) { - rlvl_destroy(rlvl); - } - jas_free(tcmpt->rlvls); - } - - if (tcmpt->data) { - jas_seq2d_destroy(tcmpt->data); - } - if (tcmpt->tsfb) { - jpc_tsfb_destroy(tcmpt->tsfb); - } -} - - - -static jpc_enc_rlvl_t * -rlvl_create(jpc_enc_rlvl_t *rlvl, jpc_enc_cp_t *cp, - jpc_enc_tcmpt_t *tcmpt, jpc_tsfb_band_t *bandinfos) { - - uint_fast16_t rlvlno; - uint_fast32_t tlprctlx; - uint_fast32_t tlprctly; - uint_fast32_t brprcbrx; - uint_fast32_t brprcbry; - uint_fast16_t bandno; - jpc_enc_band_t *band; - - /* Deduce the resolution level. */ - rlvlno = rlvl - tcmpt->rlvls; - - /* Initialize members required for error recovery. */ - rlvl->bands = 0; - rlvl->tcmpt = tcmpt; - - /* Compute the coordinates of the top-left and bottom-right - corners of the tile-component at this resolution. */ - rlvl->tlx = - JPC_CEILDIVPOW2(jas_seq2d_xstart(tcmpt->data), tcmpt->numrlvls - - 1 - rlvlno); - rlvl->tly = - JPC_CEILDIVPOW2(jas_seq2d_ystart(tcmpt->data), tcmpt->numrlvls - - 1 - rlvlno); - rlvl->brx = - JPC_CEILDIVPOW2(jas_seq2d_xend(tcmpt->data), tcmpt->numrlvls - - 1 - rlvlno); - rlvl->bry = - JPC_CEILDIVPOW2(jas_seq2d_yend(tcmpt->data), tcmpt->numrlvls - - 1 - rlvlno); - - if (rlvl->tlx >= rlvl->brx || rlvl->tly >= rlvl->bry) { - rlvl->numhprcs = 0; - rlvl->numvprcs = 0; - rlvl->numprcs = 0; - return rlvl; - } - - rlvl->numbands = (!rlvlno) ? 1 : 3; - rlvl->prcwidthexpn = cp->tccp.prcwidthexpns[rlvlno]; - rlvl->prcheightexpn = cp->tccp.prcheightexpns[rlvlno]; - if (!rlvlno) { - rlvl->cbgwidthexpn = rlvl->prcwidthexpn; - rlvl->cbgheightexpn = rlvl->prcheightexpn; - } else { - rlvl->cbgwidthexpn = rlvl->prcwidthexpn - 1; - rlvl->cbgheightexpn = rlvl->prcheightexpn - 1; - } - rlvl->cblkwidthexpn = - JAS_MIN(cp->tccp.cblkwidthexpn, rlvl->cbgwidthexpn); - rlvl->cblkheightexpn = - JAS_MIN(cp->tccp.cblkheightexpn, rlvl->cbgheightexpn); - - /* Compute the number of precincts. */ - tlprctlx = JPC_FLOORTOMULTPOW2(rlvl->tlx, rlvl->prcwidthexpn); - tlprctly = JPC_FLOORTOMULTPOW2(rlvl->tly, rlvl->prcheightexpn); - brprcbrx = JPC_CEILTOMULTPOW2(rlvl->brx, rlvl->prcwidthexpn); - brprcbry = JPC_CEILTOMULTPOW2(rlvl->bry, rlvl->prcheightexpn); - rlvl->numhprcs = JPC_FLOORDIVPOW2(brprcbrx - tlprctlx, rlvl->prcwidthexpn); - rlvl->numvprcs = - JPC_FLOORDIVPOW2(brprcbry - tlprctly, rlvl->prcheightexpn); - rlvl->numprcs = rlvl->numhprcs * rlvl->numvprcs; - - rlvl->bands = jas_malloc(rlvl->numbands * sizeof(jpc_enc_band_t)); - if (!rlvl->bands) - goto error; - - for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands; - ++bandno, ++band) { - band->prcs = 0; - band->data = 0; - band->rlvl = rlvl; - } - for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands; - ++bandno, ++band) { - if (!band_create(band, cp, rlvl, bandinfos)) { - goto error; - } - } - - return rlvl; -error: - - rlvl_destroy(rlvl); - return 0; -} - - - -static void -rlvl_destroy(jpc_enc_rlvl_t *rlvl) { - - jpc_enc_band_t *band; - uint_fast16_t bandno; - - if (rlvl->bands) { - for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands; - ++bandno, ++band) { - band_destroy(band); - } - jas_free(rlvl->bands); - } -} - - - -static jpc_enc_band_t * -band_create(jpc_enc_band_t *band, jpc_enc_cp_t *cp, - jpc_enc_rlvl_t *rlvl, jpc_tsfb_band_t *bandinfos) { - - uint_fast16_t bandno; - uint_fast16_t gblbandno; - uint_fast16_t rlvlno; - jpc_tsfb_band_t *bandinfo; - jpc_enc_tcmpt_t *tcmpt; - uint_fast32_t prcno; - jpc_enc_prc_t *prc; - - tcmpt = rlvl->tcmpt; - band->data = 0; - band->prcs = 0; - band->rlvl = rlvl; - - /* Deduce the resolution level and band number. */ - rlvlno = rlvl - rlvl->tcmpt->rlvls; - bandno = band - rlvl->bands; - gblbandno = (!rlvlno) ? 0 : (3 * (rlvlno - 1) + bandno + 1); - - bandinfo = &bandinfos[gblbandno]; - - if (bandinfo->xstart != bandinfo->xend && - bandinfo->ystart != bandinfo->yend) { - band->data = jas_seq2d_create(0, 0, 0, 0); - if (!band->data) - goto error; - jas_seq2d_bindsub(band->data, tcmpt->data, bandinfo->locxstart, - bandinfo->locystart, bandinfo->locxend, - bandinfo->locyend); - jas_seq2d_setshift(band->data, bandinfo->xstart, bandinfo->ystart); - } - band->orient = bandinfo->orient; - band->analgain = JPC_NOMINALGAIN(cp->tccp.qmfbid, tcmpt->numrlvls, rlvlno, - band->orient); - band->numbps = 0; - band->absstepsize = 0; - band->stepsize = 0; - band->synweight = bandinfo->synenergywt; - - if (band->data) { - band->prcs = jas_malloc(rlvl->numprcs * sizeof(jpc_enc_prc_t)); - if (!band->prcs) - goto error; - for (prcno = 0, prc = band->prcs; - prcno < rlvl->numprcs; - ++prcno, ++prc) { - prc->cblks = 0; - prc->incltree = 0; - prc->nlibtree = 0; - prc->savincltree = 0; - prc->savnlibtree = 0; - prc->band = band; - } - for (prcno = 0, prc = band->prcs; - prcno < rlvl->numprcs; - ++prcno, ++prc) { - if (!prc_create(prc, cp, band)) { - goto error; - } - } - } - - return band; - -error: - band_destroy(band); - return 0; -} - - - -static void -band_destroy(jpc_enc_band_t *band) { - - jpc_enc_prc_t *prc; - jpc_enc_rlvl_t *rlvl; - uint_fast32_t prcno; - - if (band->prcs) { - rlvl = band->rlvl; - for (prcno = 0, prc = band->prcs; prcno < rlvl->numprcs; - ++prcno, ++prc) { - prc_destroy(prc); - } - jas_free(band->prcs); - } - if (band->data) { - jas_seq2d_destroy(band->data); - } -} - - - -static jpc_enc_prc_t * -prc_create(jpc_enc_prc_t *prc, jpc_enc_cp_t *cp, jpc_enc_band_t *band) { - - uint_fast32_t prcno; - uint_fast32_t prcxind; - uint_fast32_t prcyind; - uint_fast32_t cbgtlx; - uint_fast32_t cbgtly; - uint_fast32_t tlprctlx; - uint_fast32_t tlprctly; - uint_fast32_t tlcbgtlx; - uint_fast32_t tlcbgtly; - uint_fast16_t rlvlno; - jpc_enc_rlvl_t *rlvl; - uint_fast32_t tlcblktlx; - uint_fast32_t tlcblktly; - uint_fast32_t brcblkbrx; - uint_fast32_t brcblkbry; - uint_fast32_t cblkno; - jpc_enc_cblk_t *cblk; - jpc_enc_tcmpt_t *tcmpt; - - prc->cblks = 0; - prc->incltree = 0; - prc->savincltree = 0; - prc->nlibtree = 0; - prc->savnlibtree = 0; - - rlvl = band->rlvl; - tcmpt = rlvl->tcmpt; - rlvlno = rlvl - tcmpt->rlvls; - prcno = prc - band->prcs; - prcxind = prcno % rlvl->numhprcs; - prcyind = prcno / rlvl->numhprcs; - prc->band = band; - - tlprctlx = JPC_FLOORTOMULTPOW2(rlvl->tlx, rlvl->prcwidthexpn); - tlprctly = JPC_FLOORTOMULTPOW2(rlvl->tly, rlvl->prcheightexpn); - - if (!rlvlno) { - tlcbgtlx = tlprctlx; - tlcbgtly = tlprctly; - } else { - tlcbgtlx = JPC_CEILDIVPOW2(tlprctlx, 1); - tlcbgtly = JPC_CEILDIVPOW2(tlprctly, 1); - } - - /* Compute the coordinates of the top-left and bottom-right corners of the - precinct. - */ - cbgtlx = tlcbgtlx + (prcxind << rlvl->cbgwidthexpn); - cbgtly = tlcbgtly + (prcyind << rlvl->cbgheightexpn); - prc->tlx = JAS_MAX(jas_seq2d_xstart(band->data), cbgtlx); - prc->tly = JAS_MAX(jas_seq2d_ystart(band->data), cbgtly); - prc->brx = JAS_MIN(jas_seq2d_xend(band->data), cbgtlx + - (1 << rlvl->cbgwidthexpn)); - prc->bry = JAS_MIN(jas_seq2d_yend(band->data), cbgtly + - (1 << rlvl->cbgheightexpn)); - - if (prc->tlx < prc->brx && prc->tly < prc->bry) { - /* The precinct contains at least one code block. */ - - tlcblktlx = JPC_FLOORTOMULTPOW2(prc->tlx, rlvl->cblkwidthexpn); - tlcblktly = JPC_FLOORTOMULTPOW2(prc->tly, rlvl->cblkheightexpn); - brcblkbrx = JPC_CEILTOMULTPOW2(prc->brx, rlvl->cblkwidthexpn); - brcblkbry = JPC_CEILTOMULTPOW2(prc->bry, rlvl->cblkheightexpn); - prc->numhcblks = JPC_FLOORDIVPOW2(brcblkbrx - tlcblktlx, - rlvl->cblkwidthexpn); - prc->numvcblks = JPC_FLOORDIVPOW2(brcblkbry - tlcblktly, - rlvl->cblkheightexpn); - prc->numcblks = prc->numhcblks * prc->numvcblks; - - if (!(prc->incltree = jpc_tagtree_create(prc->numhcblks, - prc->numvcblks))) { - goto error; - } - if (!(prc->nlibtree = jpc_tagtree_create(prc->numhcblks, - prc->numvcblks))) { - goto error; - } - if (!(prc->savincltree = jpc_tagtree_create(prc->numhcblks, - prc->numvcblks))) { - goto error; - } - if (!(prc->savnlibtree = jpc_tagtree_create(prc->numhcblks, - prc->numvcblks))) { - goto error; - } - - prc->cblks = jas_malloc(prc->numcblks * sizeof(jpc_enc_cblk_t)); - - if (!prc->cblks) - goto error; - for (cblkno = 0, cblk = prc->cblks; - cblkno < prc->numcblks; - ++cblkno, ++cblk) { - cblk->passes = 0; - cblk->stream = 0; - cblk->mqenc = 0; - cblk->data = 0; - cblk->flags = 0; - cblk->prc = prc; - } - for (cblkno = 0, cblk = prc->cblks; - cblkno < prc->numcblks; - ++cblkno, ++cblk) { - if (!cblk_create(cblk, cp, prc)) { - goto error; - } - } - } else { - /* The precinct does not contain any code blocks. */ - prc->tlx = prc->brx; - prc->tly = prc->bry; - prc->numcblks = 0; - prc->numhcblks = 0; - prc->numvcblks = 0; - prc->cblks = 0; - prc->incltree = 0; - prc->nlibtree = 0; - prc->savincltree = 0; - prc->savnlibtree = 0; - } - - return prc; - -error: - prc_destroy(prc); - return 0; -} - - - -static void -prc_destroy(jpc_enc_prc_t *prc) { - - jpc_enc_cblk_t *cblk; - uint_fast32_t cblkno; - - if (prc->cblks) { - for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks; - ++cblkno, ++cblk) { - cblk_destroy(cblk); - } - jas_free(prc->cblks); - } - if (prc->incltree) { - jpc_tagtree_destroy(prc->incltree); - } - if (prc->nlibtree) { - jpc_tagtree_destroy(prc->nlibtree); - } - if (prc->savincltree) { - jpc_tagtree_destroy(prc->savincltree); - } - if (prc->savnlibtree) { - jpc_tagtree_destroy(prc->savnlibtree); - } -} - - - -static jpc_enc_cblk_t * -cblk_create(jpc_enc_cblk_t *cblk, jpc_enc_cp_t *cp, jpc_enc_prc_t *prc) { - - jpc_enc_band_t *band; - uint_fast32_t cblktlx; - uint_fast32_t cblktly; - uint_fast32_t cblkbrx; - uint_fast32_t cblkbry; - jpc_enc_rlvl_t *rlvl; - uint_fast32_t cblkxind; - uint_fast32_t cblkyind; - uint_fast32_t cblkno; - uint_fast32_t tlcblktlx; - uint_fast32_t tlcblktly; - - cblkno = cblk - prc->cblks; - cblkxind = cblkno % prc->numhcblks; - cblkyind = cblkno / prc->numhcblks; - rlvl = prc->band->rlvl; - cblk->prc = prc; - - cblk->numpasses = 0; - cblk->passes = 0; - cblk->numencpasses = 0; - cblk->numimsbs = 0; - cblk->numlenbits = 0; - cblk->stream = 0; - cblk->mqenc = 0; - cblk->flags = 0; - cblk->numbps = 0; - cblk->curpass = 0; - cblk->data = 0; - cblk->savedcurpass = 0; - cblk->savednumlenbits = 0; - cblk->savednumencpasses = 0; - - band = prc->band; - tlcblktlx = JPC_FLOORTOMULTPOW2(prc->tlx, rlvl->cblkwidthexpn); - tlcblktly = JPC_FLOORTOMULTPOW2(prc->tly, rlvl->cblkheightexpn); - cblktlx = - JAS_MAX(tlcblktlx + (cblkxind << rlvl->cblkwidthexpn), prc->tlx); - cblktly = - JAS_MAX(tlcblktly + (cblkyind << rlvl->cblkheightexpn), prc->tly); - cblkbrx = - JAS_MIN(tlcblktlx + ((cblkxind + 1) << rlvl->cblkwidthexpn), prc->brx); - cblkbry = - JAS_MIN(tlcblktly + ((cblkyind + 1) << rlvl->cblkheightexpn), - prc->bry); - - assert(cblktlx < cblkbrx && cblktly < cblkbry); - cblk->data = jas_seq2d_create(0, 0, 0, 0); - if (!cblk->data) - goto error; - jas_seq2d_bindsub(cblk->data, band->data, - cblktlx, cblktly, cblkbrx, cblkbry); - - return cblk; - -error: - cblk_destroy(cblk); - return 0; -} - - - -static void -cblk_destroy(jpc_enc_cblk_t *cblk) { - - uint_fast16_t passno; - jpc_enc_pass_t *pass; - if (cblk->passes) { - for (passno = 0, pass = cblk->passes; passno < cblk->numpasses; - ++passno, ++pass) { - pass_destroy(pass); - } - jas_free(cblk->passes); - } - if (cblk->stream) { - jas_stream_close(cblk->stream); - } - if (cblk->mqenc) { - jpc_mqenc_destroy(cblk->mqenc); - } - if (cblk->data) { - jas_seq2d_destroy(cblk->data); - } - if (cblk->flags) { - jas_seq2d_destroy(cblk->flags); - } -} - - - -static void -pass_destroy(jpc_enc_pass_t *pass) { - - /* XXX - need to free resources here */ -} - - - -void -jpc_enc_dump(jpc_enc_t *enc) { - - jpc_enc_tile_t *tile; - jpc_enc_tcmpt_t *tcmpt; - jpc_enc_rlvl_t *rlvl; - jpc_enc_band_t *band; - jpc_enc_prc_t *prc; - jpc_enc_cblk_t *cblk; - uint_fast16_t cmptno; - uint_fast16_t rlvlno; - uint_fast16_t bandno; - uint_fast32_t prcno; - uint_fast32_t cblkno; - - tile = enc->curtile; - - for (cmptno = 0, tcmpt = tile->tcmpts; - cmptno < tile->numtcmpts; - ++cmptno, ++tcmpt) { - fprintf(stderr, " tcmpt %5d %5d %5d %5d\n", - (int)jas_seq2d_xstart(tcmpt->data), - (int)jas_seq2d_ystart(tcmpt->data), - (int)jas_seq2d_xend(tcmpt->data), - (int)jas_seq2d_yend(tcmpt->data)); - for (rlvlno = 0, rlvl = tcmpt->rlvls; - rlvlno < tcmpt->numrlvls; - ++rlvlno, ++rlvl) { - fprintf(stderr, " rlvl %5d %5d %5d %5d\n", - (int)rlvl->tlx, (int)rlvl->tly, - (int)rlvl->brx, (int)rlvl->bry); - for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands; - ++bandno, ++band) { - if (!band->data) { - continue; - } - fprintf(stderr, " band %5d %5d %5d %5d\n", - (int)jas_seq2d_xstart(band->data), - (int)jas_seq2d_ystart(band->data), - (int)jas_seq2d_xend(band->data), - (int)jas_seq2d_yend(band->data)); - for (prcno = 0, prc = band->prcs; - prcno < rlvl->numprcs; - ++prcno, ++prc) { - fprintf(stderr, " prc %5d %5d %5d %5d (%5d %5d)\n", - (int)prc->tlx, (int)prc->tly, - (int)prc->brx, (int)prc->bry, - (int)(prc->brx - prc->tlx), - (int)(prc->bry - prc->tly)); - if (!prc->cblks) { - continue; - } - for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks; - ++cblkno, ++cblk) { - fprintf(stderr, " cblk %5d %5d %5d %5d\n", - (int)jas_seq2d_xstart(cblk->data), - (int)jas_seq2d_ystart(cblk->data), - (int)jas_seq2d_xend(cblk->data), - (int)jas_seq2d_yend(cblk->data)); - } - } - } - } - } -} - - - -static int -jpc_enc_encodemainbody(jpc_enc_t *enc) { - - int tileno; - int i; - jpc_sot_t *sot; - jpc_enc_tcmpt_t *comp; - jpc_enc_tcmpt_t *endcomps; - jpc_enc_band_t *band; - jpc_enc_band_t *endbands; - jpc_enc_rlvl_t *lvl; - int rlvlno; - jpc_qcc_t *qcc; - jpc_cod_t *cod; - int adjust; - int j; - int absbandno; - long tilehdrlen; - long tilelen; - jpc_enc_tile_t *tile; - jpc_enc_cp_t *cp; - double rho; - uint_fast16_t cmptno; - int samestepsizes; - jpc_enc_ccp_t *ccps; - jpc_enc_tccp_t *tccp; - int bandno; - uint_fast32_t x; - uint_fast32_t y; - int mingbits; - int actualnumbps; - jpc_fix_t mxmag; - jpc_fix_t mag; - int numgbits; - const char * error; - - cp = enc->cp; - - for (tileno = 0; tileno < cp->numtiles; ++tileno) { - enc->curtile = jpc_enc_tile_create(enc->cp, enc->image, tileno); - if (!enc->curtile) - abort(); - - tile = enc->curtile; - - if (jas_getdbglevel() >= 10) { - jpc_enc_dump(enc); - } - - endcomps = &tile->tcmpts[tile->numtcmpts]; - for (cmptno = 0, comp = tile->tcmpts; - cmptno < tile->numtcmpts; - ++cmptno, ++comp) { - if (!cp->ccps[cmptno].sgnd) { - adjust = 1 << (cp->ccps[cmptno].prec - 1); - for (i = 0; i < jas_matrix_numrows(comp->data); ++i) { - for (j = 0; j < jas_matrix_numcols(comp->data); ++j) { - *jas_matrix_getref(comp->data, i, j) -= adjust; - } - } - } - } - - if (!tile->intmode) { - endcomps = &tile->tcmpts[tile->numtcmpts]; - for (comp = tile->tcmpts; comp != endcomps; ++comp) { - jas_matrix_asl(comp->data, JPC_FIX_FRACBITS); - } - } - - switch (tile->mctid) { - case JPC_MCT_RCT: - assert(jas_image_numcmpts(enc->image) == 3); - jpc_rct(tile->tcmpts[0].data, tile->tcmpts[1].data, - tile->tcmpts[2].data); - break; - case JPC_MCT_ICT: - assert(jas_image_numcmpts(enc->image) == 3); - jpc_ict(tile->tcmpts[0].data, tile->tcmpts[1].data, - tile->tcmpts[2].data); - break; - default: - break; - } - - for (i = 0; i < jas_image_numcmpts(enc->image); ++i) { - comp = &tile->tcmpts[i]; - jpc_tsfb_analyze(comp->tsfb, - ((comp->qmfbid == JPC_COX_RFT) ? - JPC_TSFB_RITIMODE : 0), comp->data); - - } - - endcomps = &tile->tcmpts[tile->numtcmpts]; - for (cmptno = 0, comp = tile->tcmpts; - comp != endcomps; - ++cmptno, ++comp) { - mingbits = 0; - absbandno = 0; - /* All bands must have a corresponding quantizer step size, - even if they contain no samples and are never coded. */ - /* Some bands may not be hit by the loop below, so we must - initialize all of the step sizes to a sane value. */ - memset(comp->stepsizes, 0, sizeof(comp->stepsizes)); - for (rlvlno = 0, lvl = comp->rlvls; - rlvlno < comp->numrlvls; - ++rlvlno, ++lvl) { - if (!lvl->bands) { - absbandno += rlvlno ? 3 : 1; - continue; - } - endbands = &lvl->bands[lvl->numbands]; - for (band = lvl->bands; band != endbands; ++band) { - if (!band->data) { - ++absbandno; - continue; - } - actualnumbps = 0; - mxmag = 0; - for (y = 0; y < jas_matrix_numrows(band->data); ++y) { - for (x = 0; x < jas_matrix_numcols(band->data); ++x) { - mag = abs(jas_matrix_get(band->data, y, x)); - if (mag > mxmag) { - mxmag = mag; - } - } - } - if (tile->intmode) { - actualnumbps = - jpc_firstone(mxmag) + 1; - } else { - actualnumbps = - jpc_firstone(mxmag) + 1 - JPC_FIX_FRACBITS; - } - numgbits = actualnumbps - (cp->ccps[cmptno].prec - 1 + - band->analgain); - if (numgbits > mingbits) { - mingbits = numgbits; - } - if (!tile->intmode) { - band->absstepsize = - jpc_fix_div( - jpc_inttofix(1 << (band->analgain + 1)), - band->synweight); - } else { - band->absstepsize = jpc_inttofix(1); - } - band->stepsize = jpc_abstorelstepsize( - band->absstepsize, cp->ccps[cmptno].prec + - band->analgain); - band->numbps = cp->tccp.numgbits + - JPC_QCX_GETEXPN(band->stepsize) - 1; - - if ((!tile->intmode) && band->data) { - quantize(band->data, band->absstepsize); - } - - comp->stepsizes[absbandno] = band->stepsize; - ++absbandno; - } - } - - assert(JPC_FIX_FRACBITS >= JPC_NUMEXTRABITS); - if (!tile->intmode) { - jas_matrix_divpow2(comp->data, - JPC_FIX_FRACBITS - JPC_NUMEXTRABITS); - } else { - jas_matrix_asl(comp->data, JPC_NUMEXTRABITS); - } - } - - if (mingbits > cp->tccp.numgbits) { - fprintf(stderr, "error: too few guard bits (need at least %d)\n", - mingbits); - return -1; - } - - enc->tmpstream = jas_stream_memopen(0, 0); - if (!enc->tmpstream) { - fprintf(stderr, "cannot open tmp file\n"); - return -1; - } - - /* Write the tile header. */ - enc->mrk = jpc_ms_create(JPC_MS_SOT); - if (!enc->mrk) - return -1; - sot = &enc->mrk->parms.sot; - sot->len = 0; - sot->tileno = tileno; - sot->partno = 0; - sot->numparts = 1; - if (jpc_putms(enc->tmpstream, enc->cstate, enc->mrk)) { - fprintf(stderr, "cannot write SOT marker\n"); - return -1; - } - jpc_ms_destroy(enc->mrk); - enc->mrk = 0; - -/************************************************************************/ -/************************************************************************/ -/************************************************************************/ - - tccp = &cp->tccp; - for (cmptno = 0; cmptno < cp->numcmpts; ++cmptno) { - comp = &tile->tcmpts[cmptno]; - if (comp->numrlvls != tccp->maxrlvls) { - if (!(enc->mrk = jpc_ms_create(JPC_MS_COD))) { - return -1; - } - /* XXX = this is not really correct. we are using comp #0's - precint sizes and other characteristics */ - comp = &tile->tcmpts[0]; - cod = &enc->mrk->parms.cod; - cod->compparms.csty = 0; - cod->compparms.numdlvls = comp->numrlvls - 1; - cod->prg = tile->prg; - cod->numlyrs = tile->numlyrs; - cod->compparms.cblkwidthval = - JPC_COX_CBLKSIZEEXPN(comp->cblkwidthexpn); - cod->compparms.cblkheightval = - JPC_COX_CBLKSIZEEXPN(comp->cblkheightexpn); - cod->compparms.cblksty = comp->cblksty; - cod->compparms.qmfbid = comp->qmfbid; - cod->mctrans = (tile->mctid != JPC_MCT_NONE); - for (i = 0; i < comp->numrlvls; ++i) { - cod->compparms.rlvls[i].parwidthval = - comp->rlvls[i].prcwidthexpn; - cod->compparms.rlvls[i].parheightval = - comp->rlvls[i].prcheightexpn; - } - if (jpc_putms(enc->tmpstream, enc->cstate, enc->mrk)) { - return -1; - } - jpc_ms_destroy(enc->mrk); - enc->mrk = 0; - } - } - - for (cmptno = 0, comp = tile->tcmpts; - cmptno < cp->numcmpts; - ++cmptno, ++comp) { - ccps = &cp->ccps[cmptno]; - if (ccps->numstepsizes == comp->numstepsizes) { - samestepsizes = 1; - for (bandno = 0; bandno < ccps->numstepsizes; ++bandno) { - if (ccps->stepsizes[bandno] != comp->stepsizes[bandno]) { - samestepsizes = 0; - break; - } - } - } else { - samestepsizes = 0; - } - if (!samestepsizes) { - if (!(enc->mrk = jpc_ms_create(JPC_MS_QCC))) { - return -1; - } - qcc = &enc->mrk->parms.qcc; - qcc->compno = cmptno; - qcc->compparms.numguard = cp->tccp.numgbits; - qcc->compparms.qntsty = (comp->qmfbid == JPC_COX_INS) ? - JPC_QCX_SEQNT : JPC_QCX_NOQNT; - qcc->compparms.numstepsizes = comp->numstepsizes; - qcc->compparms.stepsizes = comp->stepsizes; - if (jpc_putms(enc->tmpstream, enc->cstate, enc->mrk)) { - return -1; - } - qcc->compparms.stepsizes = 0; - jpc_ms_destroy(enc->mrk); - enc->mrk = 0; - } - } - - /* Write a SOD marker to indicate the end of the tile header. */ - if (!(enc->mrk = jpc_ms_create(JPC_MS_SOD))) { - return -1; - } - if (jpc_putms(enc->tmpstream, enc->cstate, enc->mrk)) { - fprintf(stderr, "cannot write SOD marker\n"); - return -1; - } - jpc_ms_destroy(enc->mrk); - enc->mrk = 0; - tilehdrlen = jas_stream_getrwcount(enc->tmpstream); - -/************************************************************************/ -/************************************************************************/ -/************************************************************************/ - - if (jpc_enc_enccblks(enc)) { - abort(); - return -1; - } - - cp = enc->cp; - rho = (double) (tile->brx - tile->tlx) * (tile->bry - tile->tly) / - ((cp->refgrdwidth - cp->imgareatlx) * (cp->refgrdheight - - cp->imgareatly)); - tile->rawsize = cp->rawsize * rho; - - computeLayerSizes(enc, tile, cp, rho, tilehdrlen, &error); - - if (!error) { - int rc; - performTier2Coding(enc, tile->numlyrs, tile->lyrsizes, &error); - - rc = jpc_enc_encodetiledata(enc); - if (rc != 0) - pm_asprintf(&error, "jpc_enc_encodetiledata() failed\n"); - } - - if (error) { - fprintf(stderr, "%s\n", error); - pm_strfree(error); - return -1; - } - - tilelen = jas_stream_tell(enc->tmpstream); - - if (jas_stream_seek(enc->tmpstream, 6, SEEK_SET) < 0) { - return -1; - } - jpc_putuint32(enc->tmpstream, tilelen); - - if (jas_stream_seek(enc->tmpstream, 0, SEEK_SET) < 0) { - return -1; - } - if (jpc_putdata(enc->out, enc->tmpstream, -1)) { - return -1; - } - enc->len += tilelen; - - jas_stream_close(enc->tmpstream); - enc->tmpstream = 0; - - jpc_enc_tile_destroy(enc->curtile); - enc->curtile = 0; - - } - - return 0; -} - - - -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_enc.h b/converter/other/jpeg2000/libjasper/jpc/jpc_enc.h deleted file mode 100644 index cfd754c..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_enc.h +++ /dev/null @@ -1,695 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * $Id$ - */ - -#ifndef JPC_ENC_H -#define JPC_ENC_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include "jasper/jas_seq.h" - -#include "jpc_t2cod.h" -#include "jpc_mqenc.h" -#include "jpc_cod.h" -#include "jpc_tagtree.h" -#include "jpc_cs.h" -#include "jpc_flt.h" -#include "jpc_tsfb.h" - -/******************************************************************************\ -* Constants. -\******************************************************************************/ - -/* The number of bits used in various lookup tables. */ -#define JPC_NUMEXTRABITS JPC_NMSEDEC_FRACBITS - -/* An invalid R-D slope value. */ -#define JPC_BADRDSLOPE (-1) - -/******************************************************************************\ -* Coding parameters types. -\******************************************************************************/ - -/* Per-component coding paramters. */ - -typedef struct { - - /* The horizontal sampling period. */ - uint_fast8_t sampgrdstepx; - - /* The vertical sampling period. */ - uint_fast8_t sampgrdstepy; - - /* The sample alignment horizontal offset. */ - uint_fast8_t sampgrdsubstepx; - - /* The sample alignment vertical offset. */ - uint_fast8_t sampgrdsubstepy; - - /* The precision of the samples. */ - uint_fast8_t prec; - - /* The signedness of the samples. */ - bool sgnd; - - /* The number of step sizes. */ - uint_fast16_t numstepsizes; - - /* The quantizer step sizes. */ - uint_fast16_t stepsizes[JPC_MAXBANDS]; - -} jpc_enc_ccp_t; - -/* Per-tile coding parameters. */ - -typedef struct { - - /* The coding mode. */ - bool intmode; - - /* The coding style (i.e., SOP, EPH). */ - uint_fast8_t csty; - - /* The progression order. */ - uint_fast8_t prg; - - /* The multicomponent transform. */ - uint_fast8_t mctid; - - /* The number of layers. */ - uint_fast16_t numlyrs; - - /* The normalized bit rates associated with the various - intermediate layers. */ - jpc_fix_t *ilyrrates; - -} jpc_enc_tcp_t; - -/* Per tile-component coding parameters. */ - -typedef struct { - - /* The coding style (i.e., explicit precinct sizes). */ - uint_fast8_t csty; - - /* The maximum number of resolution levels allowed. */ - uint_fast8_t maxrlvls; - - /* The exponent for the nominal code block width. */ - uint_fast16_t cblkwidthexpn; - - /* The exponent for the nominal code block height. */ - uint_fast16_t cblkheightexpn; - - /* The code block style parameters (e.g., lazy, terminate all, - segmentation symbols, causal, reset probability models). */ - uint_fast8_t cblksty; - - /* The QMFB. */ - uint_fast8_t qmfbid; - - /* The precinct width values. */ - uint_fast16_t prcwidthexpns[JPC_MAXRLVLS]; - - /* The precinct height values. */ - uint_fast16_t prcheightexpns[JPC_MAXRLVLS]; - - /* The number of guard bits. */ - uint_fast8_t numgbits; - -} jpc_enc_tccp_t; - -/* Coding parameters. */ - -typedef struct { - - /* The debug level. */ - int debug; - - /* The horizontal offset from the origin of the reference grid to the - left edge of the image area. */ - uint_fast32_t imgareatlx; - - /* The vertical offset from the origin of the reference grid to the - top edge of the image area. */ - uint_fast32_t imgareatly; - - /* The horizontal offset from the origin of the reference grid to the - right edge of the image area (plus one). */ - uint_fast32_t refgrdwidth; - - /* The vertical offset from the origin of the reference grid to the - bottom edge of the image area (plus one). */ - uint_fast32_t refgrdheight; - - /* The horizontal offset from the origin of the tile grid to the - origin of the reference grid. */ - uint_fast32_t tilegrdoffx; - - /* The vertical offset from the origin of the tile grid to the - origin of the reference grid. */ - uint_fast32_t tilegrdoffy; - - /* The nominal tile width in units of the image reference grid. */ - uint_fast32_t tilewidth; - - /* The nominal tile height in units of the image reference grid. */ - uint_fast32_t tileheight; - - /* The number of tiles spanning the image area in the horizontal - direction. */ - uint_fast32_t numhtiles; - - /* The number of tiles spanning the image area in the vertical - direction. */ - uint_fast32_t numvtiles; - - /* The number of tiles. */ - uint_fast32_t numtiles; - - /* The number of components. */ - uint_fast16_t numcmpts; - - /* The per-component coding parameters. */ - jpc_enc_ccp_t *ccps; - - /* The per-tile coding parameters. */ - jpc_enc_tcp_t tcp; - - /* The per-tile-component coding parameters. */ - jpc_enc_tccp_t tccp; - - /* The target code stream length in bytes. */ - uint_fast32_t totalsize; - - /* The raw (i.e., uncompressed) size of the image in bytes. */ - uint_fast32_t rawsize; - -} jpc_enc_cp_t; - -/******************************************************************************\ -* Encoder class. -\******************************************************************************/ - -/* Encoder per-coding-pass state information. */ - -typedef struct { - - /* The starting offset for this pass. */ - int start; - - /* The ending offset for this pass. */ - int end; - - /* The type of data in this pass (i.e., MQ or raw). */ - int type; - - /* Flag indicating that this pass is terminated. */ - int term; - - /* The entropy coder state after coding this pass. */ - jpc_mqencstate_t mqencstate; - - /* The layer to which this pass has been assigned. */ - int lyrno; - - /* The R-D slope for this pass. */ - jpc_flt_t rdslope; - - /* The weighted MSE reduction associated with this pass. */ - jpc_flt_t wmsedec; - - /* The cumulative weighted MSE reduction. */ - jpc_flt_t cumwmsedec; - - /* The normalized MSE reduction. */ - long nmsedec; - -} jpc_enc_pass_t; - -/* Encoder per-code-block state information. */ - -typedef struct { - - /* The number of passes. */ - int numpasses; - - /* The per-pass information. */ - jpc_enc_pass_t *passes; - - /* The number of passes encoded so far. */ - int numencpasses; - - /* The number of insignificant MSBs. */ - int numimsbs; - - /* The number of bits used to encode pass data lengths. */ - int numlenbits; - - /* The byte stream for this code block. */ - jas_stream_t *stream; - - /* The entropy encoder. */ - jpc_mqenc_t *mqenc; - - /* The data for this code block. */ - jas_matrix_t *data; - - /* The state for this code block. */ - jas_matrix_t *flags; - - /* The number of bit planes required for this code block. */ - int numbps; - - /* The next pass to be encoded. */ - jpc_enc_pass_t *curpass; - - /* The per-code-block-group state information. */ - struct jpc_enc_prc_s *prc; - - /* The saved current pass. */ - /* This is used by the rate control code. */ - jpc_enc_pass_t *savedcurpass; - - /* The saved length indicator size. */ - /* This is used by the rate control code. */ - int savednumlenbits; - - /* The saved number of encoded passes. */ - /* This is used by the rate control code. */ - int savednumencpasses; - -} jpc_enc_cblk_t; - -/* Encoder per-code-block-group state information. */ - -typedef struct jpc_enc_prc_s { - - /* The x-coordinate of the top-left corner of the precinct. */ - uint_fast32_t tlx; - - /* The y-coordinate of the top-left corner of the precinct. */ - uint_fast32_t tly; - - /* The x-coordinate of the bottom-right corner of the precinct - (plus one). */ - uint_fast32_t brx; - - /* The y-coordinate of the bottom-right corner of the precinct - (plus one). */ - uint_fast32_t bry; - - /* The number of code blocks spanning the precinct in the horizontal - direction. */ - int numhcblks; - - /* The number of code blocks spanning the precinct in the vertical - direction. */ - int numvcblks; - - /* The total number of code blocks. */ - int numcblks; - - /* The per-code-block information. */ - jpc_enc_cblk_t *cblks; - - /* The inclusion tag tree. */ - jpc_tagtree_t *incltree; - - /* The insignifcant MSBs tag tree. */ - jpc_tagtree_t *nlibtree; - - /* The per-band information. */ - struct jpc_enc_band_s *band; - - /* The saved inclusion tag tree. */ - /* This is used by rate control. */ - jpc_tagtree_t *savincltree; - - /* The saved leading-insignificant-bit-planes tag tree. */ - /* This is used by rate control. */ - jpc_tagtree_t *savnlibtree; - -} jpc_enc_prc_t; - -/* Encoder per-band state information. */ - -typedef struct jpc_enc_band_s { - - /* The per precinct information. */ - jpc_enc_prc_t *prcs; - - /* The coefficient data for this band. */ - jas_matrix_t *data; - - /* The orientation of this band (i.e., LL, LH, HL, or HH). */ - int orient; - - /* The number of bit planes associated with this band. */ - int numbps; - - /* The quantizer step size. */ - jpc_fix_t absstepsize; - - /* The encoded quantizer step size. */ - int stepsize; - - /* The L2 norm of the synthesis basis functions associated with - this band. (The MCT is not considered in this value.) */ - jpc_fix_t synweight; - - /* The analysis gain for this band. */ - int analgain; - - /* The per-resolution-level information. */ - struct jpc_enc_rlvl_s *rlvl; - -} jpc_enc_band_t; - -/* Encoder per-resolution-level state information. */ - -typedef struct jpc_enc_rlvl_s { - - /* The x-coordinate of the top-left corner of the tile-component - at this resolution. */ - uint_fast32_t tlx; - - /* The y-coordinate of the top-left corner of the tile-component - at this resolution. */ - uint_fast32_t tly; - - /* The x-coordinate of the bottom-right corner of the tile-component - at this resolution (plus one). */ - uint_fast32_t brx; - - /* The y-coordinate of the bottom-right corner of the tile-component - at this resolution (plus one). */ - uint_fast32_t bry; - - /* The exponent value for the nominal precinct width measured - relative to the associated LL band. */ - int prcwidthexpn; - - /* The exponent value for the nominal precinct height measured - relative to the associated LL band. */ - int prcheightexpn; - - /* The number of precincts spanning the resolution level in the - horizontal direction. */ - int numhprcs; - - /* The number of precincts spanning the resolution level in the - vertical direction. */ - int numvprcs; - - /* The total number of precincts. */ - int numprcs; - - /* The exponent value for the nominal code block group width. - This quantity is associated with the next lower resolution level - (assuming that there is one). */ - int cbgwidthexpn; - - /* The exponent value for the nominal code block group height. - This quantity is associated with the next lower resolution level - (assuming that there is one). */ - int cbgheightexpn; - - /* The exponent value for the code block width. */ - uint_fast16_t cblkwidthexpn; - - /* The exponent value for the code block height. */ - uint_fast16_t cblkheightexpn; - - /* The number of bands associated with this resolution level. */ - int numbands; - - /* The per-band information. */ - jpc_enc_band_t *bands; - - /* The parent tile-component. */ - struct jpc_enc_tcmpt_s *tcmpt; - -} jpc_enc_rlvl_t; - -/* Encoder per-tile-component state information. */ - -typedef struct jpc_enc_tcmpt_s { - - /* The number of resolution levels. */ - uint_fast16_t numrlvls; - - /* The per-resolution-level information. */ - jpc_enc_rlvl_t *rlvls; - - /* The tile-component data. */ - jas_matrix_t *data; - - /* The QMFB. */ - int qmfbid; - - /* The number of bands. */ - int numbands; - - /* The TSFB. */ - jpc_tsfb_t *tsfb; - - /* The synthesis energy weight (for the MCT). */ - jpc_fix_t synweight; - - /* The precinct width exponents. */ - int prcwidthexpns[JPC_MAXRLVLS]; - - /* The precinct height exponents. */ - int prcheightexpns[JPC_MAXRLVLS]; - - /* The code block width exponent. */ - int cblkwidthexpn; - - /* The code block height exponent. */ - int cblkheightexpn; - - /* Coding style (i.e., explicit precinct sizes). */ - int csty; - - /* Code block style. */ - int cblksty; - - /* The number of quantizer step sizes. */ - uint_fast16_t numstepsizes; - - /* The encoded quantizer step sizes. */ - uint_fast16_t stepsizes[JPC_MAXBANDS]; - - /* The parent tile. */ - struct jpc_enc_tile_s *tile; - -} jpc_enc_tcmpt_t; - -/* Encoder per-tile state information. */ - -typedef struct jpc_enc_tile_s { - - /* The tile number. */ - uint_fast32_t tileno; - - /* The x-coordinate of the top-left corner of the tile measured with - respect to the reference grid. */ - uint_fast32_t tlx; - - /* The y-coordinate of the top-left corner of the tile measured with - respect to the reference grid. */ - uint_fast32_t tly; - - /* The x-coordinate of the bottom-right corner of the tile measured - with respect to the reference grid (plus one). */ - uint_fast32_t brx; - - /* The y-coordinate of the bottom-right corner of the tile measured - with respect to the reference grid (plus one). */ - uint_fast32_t bry; - - /* The coding style. */ - uint_fast8_t csty; - - /* The progression order. */ - uint_fast8_t prg; - - /* The number of layers. */ - uint_fast16_t numlyrs; - - /* The MCT to employ (if any). */ - uint_fast8_t mctid; - - /* The packet iterator (used to determine the order of packet - generation). */ - jpc_pi_t *pi; - - /* The coding mode (i.e., integer or real). */ - bool intmode; - - /* The number of bytes to allocate to the various layers. */ - uint_fast32_t *lyrsizes; - - /* The number of tile-components. */ - int numtcmpts; - - /* The per tile-component information. */ - jpc_enc_tcmpt_t *tcmpts; - - /* The raw (i.e., uncompressed) size of this tile. */ - uint_fast32_t rawsize; - -} jpc_enc_tile_t; - -/* Encoder class. */ - -typedef struct jpc_enc_s { - - /* The image being encoded. */ - jas_image_t *image; - - /* The output stream. */ - jas_stream_t *out; - - /* The coding parameters. */ - jpc_enc_cp_t *cp; - - /* The tile currently being processed. */ - jpc_enc_tile_t *curtile; - - /* The code stream state. */ - jpc_cstate_t *cstate; - - /* The number of bytes output so far. */ - uint_fast32_t len; - - /* The number of bytes available for the main body of the code stream. */ - /* This is used for rate allocation purposes. */ - uint_fast32_t mainbodysize; - - /* The marker segment currently being processed. */ - /* This member is a convenience for making cleanup easier. */ - jpc_ms_t *mrk; - - /* The stream used to temporarily hold tile-part data. */ - jas_stream_t *tmpstream; - -} jpc_enc_t; - -#endif diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_fix.h b/converter/other/jpeg2000/libjasper/jpc/jpc_fix.h deleted file mode 100644 index 5ff0c9f..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_fix.h +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Fixed-Point Number Class - * - * $Id$ - */ - -#ifndef JPC_FIX_H -#define JPC_FIX_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include "jasper/jas_types.h" -#include "jasper/jas_fix.h" - -/******************************************************************************\ -* Basic parameters of the fixed-point type. -\******************************************************************************/ - -/* The integral type used to represent a fixed-point number. This - type must be capable of representing values from -(2^31) to 2^31-1 - (inclusive). */ -typedef int_fast32_t jpc_fix_t; - -/* The integral type used to respresent higher-precision intermediate results. - This type should be capable of representing values from -(2^63) to 2^63-1 - (inclusive). */ -typedef int_fast64_t jpc_fix_big_t; - -/* The number of bits used for the fractional part of a fixed-point number. */ -#define JPC_FIX_FRACBITS 13 - -/******************************************************************************\ -* Instantiations of the generic fixed-point number macros for the -* parameters given above. (Too bad C does not support templates, eh?) -* The purpose of these macros is self-evident if one examines the -* corresponding macros in the jasper/jas_fix.h header file. -\******************************************************************************/ - -#define JPC_FIX_ZERO JAS_FIX_ZERO(jpc_fix_t, JPC_FIX_FRACBITS) -#define JPC_FIX_ONE JAS_FIX_ONE(jpc_fix_t, JPC_FIX_FRACBITS) -#define JPC_FIX_HALF JAS_FIX_HALF(jpc_fix_t, JPC_FIX_FRACBITS) - -#define jpc_inttofix(x) JAS_INTTOFIX(jpc_fix_t, JPC_FIX_FRACBITS, x) -#define jpc_fixtoint(x) JAS_FIXTOINT(jpc_fix_t, JPC_FIX_FRACBITS, x) -#define jpc_fixtodbl(x) JAS_FIXTODBL(jpc_fix_t, JPC_FIX_FRACBITS, x) -#define jpc_dbltofix(x) JAS_DBLTOFIX(jpc_fix_t, JPC_FIX_FRACBITS, x) - -#define jpc_fix_add(x, y) JAS_FIX_ADD(jpc_fix_t, JPC_FIX_FRACBITS, x, y) -#define jpc_fix_sub(x, y) JAS_FIX_SUB(jpc_fix_t, JPC_FIX_FRACBITS, x, y) -#define jpc_fix_mul(x, y) \ - JAS_FIX_MUL(jpc_fix_t, JPC_FIX_FRACBITS, jpc_fix_big_t, x, y) -#define jpc_fix_mulbyint(x, y) \ - JAS_FIX_MULBYINT(jpc_fix_t, JPC_FIX_FRACBITS, x, y) -#define jpc_fix_div(x, y) \ - JAS_FIX_DIV(jpc_fix_t, JPC_FIX_FRACBITS, jpc_fix_big_t, x, y) -#define jpc_fix_neg(x) JAS_FIX_NEG(jpc_fix_t, JPC_FIX_FRACBITS, x) -#define jpc_fix_asl(x, n) JAS_FIX_ASL(jpc_fix_t, JPC_FIX_FRACBITS, x, n) -#define jpc_fix_asr(x, n) JAS_FIX_ASR(jpc_fix_t, JPC_FIX_FRACBITS, x, n) - -#define jpc_fix_pluseq(x, y) JAS_FIX_PLUSEQ(jpc_fix_t, JPC_FIX_FRACBITS, x, y) -#define jpc_fix_minuseq(x, y) JAS_FIX_MINUSEQ(jpc_fix_t, JPC_FIX_FRACBITS, x, y) -#define jpc_fix_muleq(x, y) \ - JAS_FIX_MULEQ(jpc_fix_t, JPC_FIX_FRACBITS, jpc_fix_big_t, x, y) - -#define jpc_fix_abs(x) JAS_FIX_ABS(jpc_fix_t, JPC_FIX_FRACBITS, x) -#define jpc_fix_isint(x) JAS_FIX_ISINT(jpc_fix_t, JPC_FIX_FRACBITS, x) -#define jpc_fix_sgn(x) JAS_FIX_SGN(jpc_fix_t, JPC_FIX_FRACBITS, x) -#define jpc_fix_round(x) JAS_FIX_ROUND(jpc_fix_t, JPC_FIX_FRACBITS, x) -#define jpc_fix_floor(x) JAS_FIX_FLOOR(jpc_fix_t, JPC_FIX_FRACBITS, x) -#define jpc_fix_trunc(x) JAS_FIX_TRUNC(jpc_fix_t, JPC_FIX_FRACBITS, x) - -/******************************************************************************\ -* Extra macros for convenience. -\******************************************************************************/ - -/* Compute the sum of three fixed-point numbers. */ -#define jpc_fix_add3(x, y, z) jpc_fix_add(jpc_fix_add(x, y), z) - -#endif diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_flt.h b/converter/other/jpeg2000/libjasper/jpc/jpc_flt.h deleted file mode 100644 index 088eb00..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_flt.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Floating-Point Class - * - * $Id$ - */ - -#ifndef JPC_FLT_H -#define JPC_FLT_H - -#include - -/* The code ought to be modified so this type is not used at all. */ -/* Very few places in the code rely on floating-point arithmetic, aside - from conversions in printf's. */ -typedef double jpc_flt_t; - -#endif diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_math.c b/converter/other/jpeg2000/libjasper/jpc/jpc_math.c deleted file mode 100644 index 72e3ac3..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_math.c +++ /dev/null @@ -1,180 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "jpc_math.h" - - - -/* Calculate the integer quantity floor(log2(x)), where x is a positive - integer. */ -int -jpc_floorlog2(int const arg) { - - int y; - int x; - - assert(arg > 0); - - y = 0; - x = arg; - while (x > 1) { - x >>= 1; - ++y; - } - return y; -} - - - -/* - jpc_floorlog2() and jpc_firstone() do the same thing. - The only difference is how input 0 is handled. - -n : 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 -ceil(log2(n)) : x 0 1 2 2 3 3 3 3 4 4 4 4 4 4 4 4 5 5 5 -floor(log2(n)) : x 0 1 1 2 2 2 2 3 3 3 3 3 3 3 3 4 4 4 4 -31-__builtin_clz(n): x 0 1 1 2 2 2 2 3 3 3 3 3 3 3 3 4 4 4 4 -jpc_floorlog2(n) : x 0 1 1 2 2 2 2 3 3 3 3 3 3 3 3 4 4 4 4 -jpc_firstone(n) :-1 0 1 1 2 2 2 2 3 3 3 3 3 3 3 3 4 4 4 4 - -*/ - - - -int -jpc_firstone(int const arg) { -/*---------------------------------------------------------------------------- - Calculate the bit position of the first leading one in a nonnegative - integer. ------------------------------------------------------------------------------*/ - int n; - int x; - - assert(arg >= 0); - - n = -1; - x = arg; - while (x > 0) { - x >>= 1; - ++n; - } - return n; -} - - - -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_math.h b/converter/other/jpeg2000/libjasper/jpc/jpc_math.h deleted file mode 100644 index 77df0c6..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_math.h +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -#ifndef JPC_MATH_H -#define JPC_MATH_H - -/******************************************************************************\ -* Includes -\******************************************************************************/ - -#include - -/******************************************************************************\ -* Macros -\******************************************************************************/ - -/* Compute the floor of the quotient of two integers. */ -#define JPC_FLOORDIV(x, y) (assert(x >= 0 && y > 0), (x) / (y)) - -/* Compute the ceiling of the quotient of two integers. */ -#define JPC_CEILDIV(x, y) (assert(x >= 0 && y > 0), ((x) + (y) - 1) / (y)) - -/* Compute the floor of (x / 2^y). */ -#define JPC_FLOORDIVPOW2(x, y) \ - (assert(x >= 0 && y > 0), (x) >> (y)) - -/* Compute the ceiling of (x / 2^y). */ -#define JPC_CEILDIVPOW2(x, y) \ - (assert(x >= 0 && y >= 0), ((x) + (1 << (y)) - 1) >> (y)) -/* JPC_CEILDIVPOW2U is for unsigned arguments (JPC_CEILDIVPOW2 would generate - compiler warnings because of its superfluous >= 0 check) -*/ -#define JPC_CEILDIVPOW2U(x, y) \ - (((x) + (1 << (y)) - 1) >> (y)) - -/******************************************************************************\ -* Functions. -\******************************************************************************/ - -/* Calculate the bit position of the first leading one in a nonnegative - integer. */ -int jpc_firstone(int x); - -/* Calculate the integer quantity floor(log2(x)), where x is a positive - integer. */ -int jpc_floorlog2(int x); - -#endif diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_mct.c b/converter/other/jpeg2000/libjasper/jpc/jpc_mct.c deleted file mode 100644 index 7c16c3e..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_mct.c +++ /dev/null @@ -1,337 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Multicomponent Transform Code - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include - -#include "jasper/jas_seq.h" - -#include "jpc_fix.h" -#include "jpc_mct.h" - -/******************************************************************************\ -* Code. -\******************************************************************************/ - -/* Compute the forward RCT. */ - -void jpc_rct(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2) -{ - int numrows; - int numcols; - int i; - int j; - jpc_fix_t *c0p; - jpc_fix_t *c1p; - jpc_fix_t *c2p; - - numrows = jas_matrix_numrows(c0); - numcols = jas_matrix_numcols(c0); - - /* All three matrices must have the same dimensions. */ - assert(jas_matrix_numrows(c1) == numrows && jas_matrix_numcols(c1) == numcols - && jas_matrix_numrows(c2) == numrows && jas_matrix_numcols(c2) == numcols); - - for (i = 0; i < numrows; i++) { - c0p = jas_matrix_getref(c0, i, 0); - c1p = jas_matrix_getref(c1, i, 0); - c2p = jas_matrix_getref(c2, i, 0); - for (j = numcols; j > 0; --j) { - int r; - int g; - int b; - int y; - int u; - int v; - r = *c0p; - g = *c1p; - b = *c2p; - y = (r + (g << 1) + b) >> 2; - u = b - g; - v = r - g; - *c0p++ = y; - *c1p++ = u; - *c2p++ = v; - } - } -} - -/* Compute the inverse RCT. */ - -void jpc_irct(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2) -{ - int numrows; - int numcols; - int i; - int j; - jpc_fix_t *c0p; - jpc_fix_t *c1p; - jpc_fix_t *c2p; - - numrows = jas_matrix_numrows(c0); - numcols = jas_matrix_numcols(c0); - - /* All three matrices must have the same dimensions. */ - assert(jas_matrix_numrows(c1) == numrows && jas_matrix_numcols(c1) == numcols - && jas_matrix_numrows(c2) == numrows && jas_matrix_numcols(c2) == numcols); - - for (i = 0; i < numrows; i++) { - c0p = jas_matrix_getref(c0, i, 0); - c1p = jas_matrix_getref(c1, i, 0); - c2p = jas_matrix_getref(c2, i, 0); - for (j = numcols; j > 0; --j) { - int r; - int g; - int b; - int y; - int u; - int v; - y = *c0p; - u = *c1p; - v = *c2p; - g = y - ((u + v) >> 2); - r = v + g; - b = u + g; - *c0p++ = r; - *c1p++ = g; - *c2p++ = b; - } - } -} - -void jpc_ict(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2) -{ - int numrows; - int numcols; - int i; - int j; - jpc_fix_t r; - jpc_fix_t g; - jpc_fix_t b; - jpc_fix_t y; - jpc_fix_t u; - jpc_fix_t v; - jpc_fix_t *c0p; - jpc_fix_t *c1p; - jpc_fix_t *c2p; - - numrows = jas_matrix_numrows(c0); - assert(jas_matrix_numrows(c1) == numrows && jas_matrix_numrows(c2) == numrows); - numcols = jas_matrix_numcols(c0); - assert(jas_matrix_numcols(c1) == numcols && jas_matrix_numcols(c2) == numcols); - for (i = 0; i < numrows; ++i) { - c0p = jas_matrix_getref(c0, i, 0); - c1p = jas_matrix_getref(c1, i, 0); - c2p = jas_matrix_getref(c2, i, 0); - for (j = numcols; j > 0; --j) { - r = *c0p; - g = *c1p; - b = *c2p; - y = jpc_fix_add3(jpc_fix_mul(jpc_dbltofix(0.299), r), jpc_fix_mul(jpc_dbltofix(0.587), g), - jpc_fix_mul(jpc_dbltofix(0.114), b)); - u = jpc_fix_add3(jpc_fix_mul(jpc_dbltofix(-0.16875), r), jpc_fix_mul(jpc_dbltofix(-0.33126), g), - jpc_fix_mul(jpc_dbltofix(0.5), b)); - v = jpc_fix_add3(jpc_fix_mul(jpc_dbltofix(0.5), r), jpc_fix_mul(jpc_dbltofix(-0.41869), g), - jpc_fix_mul(jpc_dbltofix(-0.08131), b)); - *c0p++ = y; - *c1p++ = u; - *c2p++ = v; - } - } -} - -void jpc_iict(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2) -{ - int numrows; - int numcols; - int i; - int j; - jpc_fix_t r; - jpc_fix_t g; - jpc_fix_t b; - jpc_fix_t y; - jpc_fix_t u; - jpc_fix_t v; - jpc_fix_t *c0p; - jpc_fix_t *c1p; - jpc_fix_t *c2p; - - numrows = jas_matrix_numrows(c0); - assert(jas_matrix_numrows(c1) == numrows && jas_matrix_numrows(c2) == numrows); - numcols = jas_matrix_numcols(c0); - assert(jas_matrix_numcols(c1) == numcols && jas_matrix_numcols(c2) == numcols); - for (i = 0; i < numrows; ++i) { - c0p = jas_matrix_getref(c0, i, 0); - c1p = jas_matrix_getref(c1, i, 0); - c2p = jas_matrix_getref(c2, i, 0); - for (j = numcols; j > 0; --j) { - y = *c0p; - u = *c1p; - v = *c2p; - r = jpc_fix_add(y, jpc_fix_mul(jpc_dbltofix(1.402), v)); - g = jpc_fix_add3(y, jpc_fix_mul(jpc_dbltofix(-0.34413), u), - jpc_fix_mul(jpc_dbltofix(-0.71414), v)); - b = jpc_fix_add(y, jpc_fix_mul(jpc_dbltofix(1.772), u)); - *c0p++ = r; - *c1p++ = g; - *c2p++ = b; - } - } -} - -jpc_fix_t jpc_mct_getsynweight(int mctid, int cmptno) -{ - jpc_fix_t synweight; - - switch (mctid) { - case JPC_MCT_RCT: - switch (cmptno) { - case 0: - synweight = jpc_dbltofix(sqrt(3.0)); - break; - case 1: - synweight = jpc_dbltofix(sqrt(0.6875)); - break; - case 2: - synweight = jpc_dbltofix(sqrt(0.6875)); - break; - } - break; - case JPC_MCT_ICT: - switch (cmptno) { - case 0: - synweight = jpc_dbltofix(sqrt(3.0000)); - break; - case 1: - synweight = jpc_dbltofix(sqrt(3.2584)); - break; - case 2: - synweight = jpc_dbltofix(sqrt(2.4755)); - break; - } - break; - default: - synweight = JPC_FIX_ONE; - break; - } - - return synweight; -} diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_mct.h b/converter/other/jpeg2000/libjasper/jpc/jpc_mct.h deleted file mode 100644 index d03d6ce..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_mct.h +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Multicomponent Transform Code - * - * $Id$ - */ - -#ifndef JPC_MCT_H -#define JPC_MCT_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include "jasper/jas_seq.h" -#include "jasper/jas_fix.h" - -/******************************************************************************\ -* Constants. -\******************************************************************************/ - -/* - * Multicomponent transform IDs. - */ - -#define JPC_MCT_NONE 0 -#define JPC_MCT_ICT 1 -#define JPC_MCT_RCT 2 - -/******************************************************************************\ -* Functions. -\******************************************************************************/ - -/* Calculate the forward RCT. */ -void jpc_rct(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2); - -/* Calculate the inverse RCT. */ -void jpc_irct(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2); - -/* Calculate the forward ICT. */ -void jpc_ict(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2); - -/* Calculate the inverse ICT. */ -void jpc_iict(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2); - -/* Get the synthesis weight associated with a particular component. */ -jpc_fix_t jpc_mct_getsynweight(int mctid, int cmptno); - -#endif diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_mqcod.c b/converter/other/jpeg2000/libjasper/jpc/jpc_mqcod.c deleted file mode 100644 index 535eaa2..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_mqcod.c +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * MQ Arithmetic Coder - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include "jasper/jas_malloc.h" - -#include "jpc_mqcod.h" - -/******************************************************************************\ -* Data. -\******************************************************************************/ - -/* MQ coder per-state information. */ - -jpc_mqstate_t jpc_mqstates[47 * 2] = { - {0x5601, 0, &jpc_mqstates[ 2], &jpc_mqstates[ 3]}, - {0x5601, 1, &jpc_mqstates[ 3], &jpc_mqstates[ 2]}, - {0x3401, 0, &jpc_mqstates[ 4], &jpc_mqstates[12]}, - {0x3401, 1, &jpc_mqstates[ 5], &jpc_mqstates[13]}, - {0x1801, 0, &jpc_mqstates[ 6], &jpc_mqstates[18]}, - {0x1801, 1, &jpc_mqstates[ 7], &jpc_mqstates[19]}, - {0x0ac1, 0, &jpc_mqstates[ 8], &jpc_mqstates[24]}, - {0x0ac1, 1, &jpc_mqstates[ 9], &jpc_mqstates[25]}, - {0x0521, 0, &jpc_mqstates[10], &jpc_mqstates[58]}, - {0x0521, 1, &jpc_mqstates[11], &jpc_mqstates[59]}, - {0x0221, 0, &jpc_mqstates[76], &jpc_mqstates[66]}, - {0x0221, 1, &jpc_mqstates[77], &jpc_mqstates[67]}, - {0x5601, 0, &jpc_mqstates[14], &jpc_mqstates[13]}, - {0x5601, 1, &jpc_mqstates[15], &jpc_mqstates[12]}, - {0x5401, 0, &jpc_mqstates[16], &jpc_mqstates[28]}, - {0x5401, 1, &jpc_mqstates[17], &jpc_mqstates[29]}, - {0x4801, 0, &jpc_mqstates[18], &jpc_mqstates[28]}, - {0x4801, 1, &jpc_mqstates[19], &jpc_mqstates[29]}, - {0x3801, 0, &jpc_mqstates[20], &jpc_mqstates[28]}, - {0x3801, 1, &jpc_mqstates[21], &jpc_mqstates[29]}, - {0x3001, 0, &jpc_mqstates[22], &jpc_mqstates[34]}, - {0x3001, 1, &jpc_mqstates[23], &jpc_mqstates[35]}, - {0x2401, 0, &jpc_mqstates[24], &jpc_mqstates[36]}, - {0x2401, 1, &jpc_mqstates[25], &jpc_mqstates[37]}, - {0x1c01, 0, &jpc_mqstates[26], &jpc_mqstates[40]}, - {0x1c01, 1, &jpc_mqstates[27], &jpc_mqstates[41]}, - {0x1601, 0, &jpc_mqstates[58], &jpc_mqstates[42]}, - {0x1601, 1, &jpc_mqstates[59], &jpc_mqstates[43]}, - {0x5601, 0, &jpc_mqstates[30], &jpc_mqstates[29]}, - {0x5601, 1, &jpc_mqstates[31], &jpc_mqstates[28]}, - {0x5401, 0, &jpc_mqstates[32], &jpc_mqstates[28]}, - {0x5401, 1, &jpc_mqstates[33], &jpc_mqstates[29]}, - {0x5101, 0, &jpc_mqstates[34], &jpc_mqstates[30]}, - {0x5101, 1, &jpc_mqstates[35], &jpc_mqstates[31]}, - {0x4801, 0, &jpc_mqstates[36], &jpc_mqstates[32]}, - {0x4801, 1, &jpc_mqstates[37], &jpc_mqstates[33]}, - {0x3801, 0, &jpc_mqstates[38], &jpc_mqstates[34]}, - {0x3801, 1, &jpc_mqstates[39], &jpc_mqstates[35]}, - {0x3401, 0, &jpc_mqstates[40], &jpc_mqstates[36]}, - {0x3401, 1, &jpc_mqstates[41], &jpc_mqstates[37]}, - {0x3001, 0, &jpc_mqstates[42], &jpc_mqstates[38]}, - {0x3001, 1, &jpc_mqstates[43], &jpc_mqstates[39]}, - {0x2801, 0, &jpc_mqstates[44], &jpc_mqstates[38]}, - {0x2801, 1, &jpc_mqstates[45], &jpc_mqstates[39]}, - {0x2401, 0, &jpc_mqstates[46], &jpc_mqstates[40]}, - {0x2401, 1, &jpc_mqstates[47], &jpc_mqstates[41]}, - {0x2201, 0, &jpc_mqstates[48], &jpc_mqstates[42]}, - {0x2201, 1, &jpc_mqstates[49], &jpc_mqstates[43]}, - {0x1c01, 0, &jpc_mqstates[50], &jpc_mqstates[44]}, - {0x1c01, 1, &jpc_mqstates[51], &jpc_mqstates[45]}, - {0x1801, 0, &jpc_mqstates[52], &jpc_mqstates[46]}, - {0x1801, 1, &jpc_mqstates[53], &jpc_mqstates[47]}, - {0x1601, 0, &jpc_mqstates[54], &jpc_mqstates[48]}, - {0x1601, 1, &jpc_mqstates[55], &jpc_mqstates[49]}, - {0x1401, 0, &jpc_mqstates[56], &jpc_mqstates[50]}, - {0x1401, 1, &jpc_mqstates[57], &jpc_mqstates[51]}, - {0x1201, 0, &jpc_mqstates[58], &jpc_mqstates[52]}, - {0x1201, 1, &jpc_mqstates[59], &jpc_mqstates[53]}, - {0x1101, 0, &jpc_mqstates[60], &jpc_mqstates[54]}, - {0x1101, 1, &jpc_mqstates[61], &jpc_mqstates[55]}, - {0x0ac1, 0, &jpc_mqstates[62], &jpc_mqstates[56]}, - {0x0ac1, 1, &jpc_mqstates[63], &jpc_mqstates[57]}, - {0x09c1, 0, &jpc_mqstates[64], &jpc_mqstates[58]}, - {0x09c1, 1, &jpc_mqstates[65], &jpc_mqstates[59]}, - {0x08a1, 0, &jpc_mqstates[66], &jpc_mqstates[60]}, - {0x08a1, 1, &jpc_mqstates[67], &jpc_mqstates[61]}, - {0x0521, 0, &jpc_mqstates[68], &jpc_mqstates[62]}, - {0x0521, 1, &jpc_mqstates[69], &jpc_mqstates[63]}, - {0x0441, 0, &jpc_mqstates[70], &jpc_mqstates[64]}, - {0x0441, 1, &jpc_mqstates[71], &jpc_mqstates[65]}, - {0x02a1, 0, &jpc_mqstates[72], &jpc_mqstates[66]}, - {0x02a1, 1, &jpc_mqstates[73], &jpc_mqstates[67]}, - {0x0221, 0, &jpc_mqstates[74], &jpc_mqstates[68]}, - {0x0221, 1, &jpc_mqstates[75], &jpc_mqstates[69]}, - {0x0141, 0, &jpc_mqstates[76], &jpc_mqstates[70]}, - {0x0141, 1, &jpc_mqstates[77], &jpc_mqstates[71]}, - {0x0111, 0, &jpc_mqstates[78], &jpc_mqstates[72]}, - {0x0111, 1, &jpc_mqstates[79], &jpc_mqstates[73]}, - {0x0085, 0, &jpc_mqstates[80], &jpc_mqstates[74]}, - {0x0085, 1, &jpc_mqstates[81], &jpc_mqstates[75]}, - {0x0049, 0, &jpc_mqstates[82], &jpc_mqstates[76]}, - {0x0049, 1, &jpc_mqstates[83], &jpc_mqstates[77]}, - {0x0025, 0, &jpc_mqstates[84], &jpc_mqstates[78]}, - {0x0025, 1, &jpc_mqstates[85], &jpc_mqstates[79]}, - {0x0015, 0, &jpc_mqstates[86], &jpc_mqstates[80]}, - {0x0015, 1, &jpc_mqstates[87], &jpc_mqstates[81]}, - {0x0009, 0, &jpc_mqstates[88], &jpc_mqstates[82]}, - {0x0009, 1, &jpc_mqstates[89], &jpc_mqstates[83]}, - {0x0005, 0, &jpc_mqstates[90], &jpc_mqstates[84]}, - {0x0005, 1, &jpc_mqstates[91], &jpc_mqstates[85]}, - {0x0001, 0, &jpc_mqstates[90], &jpc_mqstates[86]}, - {0x0001, 1, &jpc_mqstates[91], &jpc_mqstates[87]}, - {0x5601, 0, &jpc_mqstates[92], &jpc_mqstates[92]}, - {0x5601, 1, &jpc_mqstates[93], &jpc_mqstates[93]}, -}; diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_mqcod.h b/converter/other/jpeg2000/libjasper/jpc/jpc_mqcod.h deleted file mode 100644 index 5f99e02..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_mqcod.h +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * MQ Arithmetic Coder - * - * $Id$ - */ - -#ifndef JPC_MQCOD_H -#define JPC_MQCOD_H - -/*****************************************************************************\ -* Includes. -\*****************************************************************************/ - -#include "netpbm/pm_c_util.h" -#include "jasper/jas_types.h" - -/*****************************************************************************\ -* Types. -\*****************************************************************************/ - -/* - * MQ coder context information. - */ - -typedef struct { - - /* The most probable symbol (MPS). */ - bool mps; - - /* The state index. */ - int_fast16_t ind; - -} jpc_mqctx_t; - -/* - * MQ coder state table entry. - */ - -typedef struct jpc_mqstate_s { - - /* The Qe value. */ - uint_fast16_t qeval; - - /* The MPS. */ - uint_fast16_t mps; - - /* The NMPS state. */ - struct jpc_mqstate_s *nmps; - - /* The NLPS state. */ - struct jpc_mqstate_s *nlps; - -} jpc_mqstate_t; - -/******************************************************************************\ -* Data. -\******************************************************************************/ - -/* The state table for the MQ coder. */ -extern jpc_mqstate_t jpc_mqstates[]; - -#endif diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_mqdec.c b/converter/other/jpeg2000/libjasper/jpc/jpc_mqdec.c deleted file mode 100644 index f58a1c7..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_mqdec.c +++ /dev/null @@ -1,339 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * MQ Arithmetic Decoder - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include -#include - -#include "jasper/jas_types.h" -#include "jasper/jas_malloc.h" -#include "jasper/jas_math.h" -#include "jasper/jas_debug.h" - -#include "jpc_mqdec.h" - -/******************************************************************************\ -* Local macros. -\******************************************************************************/ - -#if defined(DEBUG) -#define MQDEC_CALL(n, x) \ - ((jas_getdbglevel() >= (n)) ? ((void)(x)) : ((void)0)) -#else -#define MQDEC_CALL(n, x) -#endif - -/******************************************************************************\ -* Local function prototypes. -\******************************************************************************/ - -static void jpc_mqdec_bytein(jpc_mqdec_t *mqdec); - -/******************************************************************************\ -* Code for creation and destruction of a MQ decoder. -\******************************************************************************/ - -/* Create a MQ decoder. */ -jpc_mqdec_t *jpc_mqdec_create(int maxctxs, jas_stream_t *in) -{ - jpc_mqdec_t *mqdec; - - /* There must be at least one context. */ - assert(maxctxs > 0); - - /* Allocate memory for the MQ decoder. */ - if (!(mqdec = jas_malloc(sizeof(jpc_mqdec_t)))) { - goto error; - } - mqdec->in = in; - mqdec->maxctxs = maxctxs; - /* Allocate memory for the per-context state information. */ - if (!(mqdec->ctxs = jas_malloc(mqdec->maxctxs * sizeof(jpc_mqstate_t *)))) { - goto error; - } - /* Set the current context to the first context. */ - mqdec->curctx = mqdec->ctxs; - - /* If an input stream has been associated with the MQ decoder, - initialize the decoder state from the stream. */ - if (mqdec->in) { - jpc_mqdec_init(mqdec); - } - /* Initialize the per-context state information. */ - jpc_mqdec_setctxs(mqdec, 0, 0); - - return mqdec; - -error: - /* Oops... Something has gone wrong. */ - if (mqdec) { - jpc_mqdec_destroy(mqdec); - } - return 0; -} - -/* Destroy a MQ decoder. */ -void jpc_mqdec_destroy(jpc_mqdec_t *mqdec) -{ - if (mqdec->ctxs) { - jas_free(mqdec->ctxs); - } - jas_free(mqdec); -} - -/******************************************************************************\ -* Code for initialization of a MQ decoder. -\******************************************************************************/ - -/* Initialize the state of a MQ decoder. */ - -void jpc_mqdec_init(jpc_mqdec_t *mqdec) -{ - int c; - - mqdec->eof = 0; - mqdec->creg = 0; - /* Get the next byte from the input stream. */ - if ((c = jas_stream_getc(mqdec->in)) == EOF) { - /* We have encountered an I/O error or EOF. */ - c = 0xff; - mqdec->eof = 1; - } - mqdec->inbuffer = c; - mqdec->creg += mqdec->inbuffer << 16; - jpc_mqdec_bytein(mqdec); - mqdec->creg <<= 7; - mqdec->ctreg -= 7; - mqdec->areg = 0x8000; -} - -/* Set the input stream for a MQ decoder. */ - -void jpc_mqdec_setinput(jpc_mqdec_t *mqdec, jas_stream_t *in) -{ - mqdec->in = in; -} - -/* Initialize one or more contexts. */ - -void jpc_mqdec_setctxs(jpc_mqdec_t *mqdec, int numctxs, jpc_mqctx_t *ctxs) -{ - jpc_mqstate_t **ctx; - int n; - - ctx = mqdec->ctxs; - n = JAS_MIN(mqdec->maxctxs, numctxs); - while (--n >= 0) { - *ctx = &jpc_mqstates[2 * ctxs->ind + ctxs->mps]; - ++ctx; - ++ctxs; - } - n = mqdec->maxctxs - numctxs; - while (--n >= 0) { - *ctx = &jpc_mqstates[0]; - ++ctx; - } -} - -/* Initialize a context. */ - -void jpc_mqdec_setctx(jpc_mqdec_t *mqdec, int ctxno, jpc_mqctx_t *ctx) -{ - jpc_mqstate_t **ctxi; - ctxi = &mqdec->ctxs[ctxno]; - *ctxi = &jpc_mqstates[2 * ctx->ind + ctx->mps]; -} - -/******************************************************************************\ -* Code for decoding a bit. -\******************************************************************************/ - -/* Decode a bit. */ - -int jpc_mqdec_getbit_func(register jpc_mqdec_t *mqdec) -{ - int bit; - JAS_DBGLOG(100, ("jpc_mqdec_getbit_func(%p)\n", mqdec)); - MQDEC_CALL(100, jpc_mqdec_dump(mqdec, stderr)); - bit = jpc_mqdec_getbit_macro(mqdec); - MQDEC_CALL(100, jpc_mqdec_dump(mqdec, stderr)); - JAS_DBGLOG(100, ("ctx = %d, decoded %d\n", mqdec->curctx - - mqdec->ctxs, bit)); - return bit; -} - -/* Apply MPS_EXCHANGE algorithm (with RENORMD). */ -int jpc_mqdec_mpsexchrenormd(register jpc_mqdec_t *mqdec) -{ - int ret; - register jpc_mqstate_t *state = *mqdec->curctx; - jpc_mqdec_mpsexchange(mqdec->areg, state->qeval, mqdec->curctx, ret); - jpc_mqdec_renormd(mqdec->areg, mqdec->creg, mqdec->ctreg, mqdec->in, - mqdec->eof, mqdec->inbuffer); - return ret; -} - -/* Apply LPS_EXCHANGE algorithm (with RENORMD). */ -int jpc_mqdec_lpsexchrenormd(register jpc_mqdec_t *mqdec) -{ - int ret; - register jpc_mqstate_t *state = *mqdec->curctx; - jpc_mqdec_lpsexchange(mqdec->areg, state->qeval, mqdec->curctx, ret); - jpc_mqdec_renormd(mqdec->areg, mqdec->creg, mqdec->ctreg, mqdec->in, - mqdec->eof, mqdec->inbuffer); - return ret; -} - -/******************************************************************************\ -* Support code. -\******************************************************************************/ - -/* Apply the BYTEIN algorithm. */ -static void jpc_mqdec_bytein(jpc_mqdec_t *mqdec) -{ - int c; - unsigned char prevbuf; - - if (!mqdec->eof) { - if ((c = jas_stream_getc(mqdec->in)) == EOF) { - mqdec->eof = 1; - c = 0xff; - } - prevbuf = mqdec->inbuffer; - mqdec->inbuffer = c; - if (prevbuf == 0xff) { - if (c > 0x8f) { - mqdec->creg += 0xff00; - mqdec->ctreg = 8; - } else { - mqdec->creg += c << 9; - mqdec->ctreg = 7; - } - } else { - mqdec->creg += c << 8; - mqdec->ctreg = 8; - } - } else { - mqdec->creg += 0xff00; - mqdec->ctreg = 8; - } -} diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_mqdec.h b/converter/other/jpeg2000/libjasper/jpc/jpc_mqdec.h deleted file mode 100644 index 3018550..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_mqdec.h +++ /dev/null @@ -1,320 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * MQ Arithmetic Decoder - * - * $Id$ - */ - -#ifndef JPC_MQDEC_H -#define JPC_MQDEC_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include "jasper/jas_types.h" -#include "jasper/jas_stream.h" - -#include "jpc_mqcod.h" - -/******************************************************************************\ -* Types. -\******************************************************************************/ - -/* MQ arithmetic decoder. */ - -typedef struct { - - /* The C register. */ - uint_fast32_t creg; - - /* The A register. */ - uint_fast32_t areg; - - /* The CT register. */ - uint_fast32_t ctreg; - - /* The current context. */ - jpc_mqstate_t **curctx; - - /* The per-context information. */ - jpc_mqstate_t **ctxs; - - /* The maximum number of contexts. */ - int maxctxs; - - /* The stream from which to read data. */ - jas_stream_t *in; - - /* The last character read. */ - unsigned char inbuffer; - - /* The EOF indicator. */ - int eof; - -} jpc_mqdec_t; - -/******************************************************************************\ -* Functions/macros for construction and destruction. -\******************************************************************************/ - -/* Create a MQ decoder. */ -jpc_mqdec_t *jpc_mqdec_create(int maxctxs, jas_stream_t *in); - -/* Destroy a MQ decoder. */ -void jpc_mqdec_destroy(jpc_mqdec_t *dec); - -/******************************************************************************\ -* Functions/macros for initialization. -\******************************************************************************/ - -/* Set the input stream associated with a MQ decoder. */ -void jpc_mqdec_setinput(jpc_mqdec_t *dec, jas_stream_t *in); - -/* Initialize a MQ decoder. */ -void jpc_mqdec_init(jpc_mqdec_t *dec); - -/******************************************************************************\ -* Functions/macros for manipulating contexts. -\******************************************************************************/ - -/* Set the current context for a MQ decoder. */ -#define jpc_mqdec_setcurctx(dec, ctxno) \ - ((mqdec)->curctx = &(mqdec)->ctxs[ctxno]); - -/* Set the state information for a particular context of a MQ decoder. */ -void jpc_mqdec_setctx(jpc_mqdec_t *dec, int ctxno, jpc_mqctx_t *ctx); - -/* Set the state information for all contexts of a MQ decoder. */ -void jpc_mqdec_setctxs(jpc_mqdec_t *dec, int numctxs, jpc_mqctx_t *ctxs); - -/******************************************************************************\ -* Functions/macros for decoding bits. -\******************************************************************************/ - -/* Decode a symbol. */ -#if !defined(DEBUG) -#define jpc_mqdec_getbit(dec) \ - jpc_mqdec_getbit_macro(dec) -#else -#define jpc_mqdec_getbit(dec) \ - jpc_mqdec_getbit_func(dec) -#endif - -/* Decode a symbol (assuming an unskewed probability distribution). */ -#if !defined(DEBUG) -#define jpc_mqdec_getbitnoskew(dec) \ - jpc_mqdec_getbit_macro(dec) -#else -#define jpc_mqdec_getbitnoskew(dec) \ - jpc_mqdec_getbit_func(dec) -#endif - -/******************************************************************************\ -* Functions/macros for debugging. -\******************************************************************************/ - -/* Dump the MQ decoder state for debugging. */ -void mqdec_dump(jpc_mqdec_t *dec, FILE *out); - -/******************************************************************************\ -* EVERYTHING BELOW THIS POINT IS IMPLEMENTATION SPECIFIC AND NOT PART OF THE -* APPLICATION INTERFACE. DO NOT RELY ON ANY OF THE INTERNAL FUNCTIONS/MACROS -* GIVEN BELOW. -\******************************************************************************/ - -#define jpc_mqdec_getbit_macro(dec) \ - ((((dec)->areg -= (*(dec)->curctx)->qeval), \ - (dec)->creg >> 16 >= (*(dec)->curctx)->qeval) ? \ - ((((dec)->creg -= (*(dec)->curctx)->qeval << 16), \ - (dec)->areg & 0x8000) ? (*(dec)->curctx)->mps : \ - jpc_mqdec_mpsexchrenormd(dec)) : \ - jpc_mqdec_lpsexchrenormd(dec)) - -#define jpc_mqdec_mpsexchange(areg, delta, curctx, bit) \ -{ \ - if ((areg) < (delta)) { \ - register jpc_mqstate_t *state = *(curctx); \ - /* LPS decoded. */ \ - (bit) = state->mps ^ 1; \ - *(curctx) = state->nlps; \ - } else { \ - register jpc_mqstate_t *state = *(curctx); \ - /* MPS decoded. */ \ - (bit) = state->mps; \ - *(curctx) = state->nmps; \ - } \ -} - -#define jpc_mqdec_lpsexchange(areg, delta, curctx, bit) \ -{ \ - if ((areg) >= (delta)) { \ - register jpc_mqstate_t *state = *(curctx); \ - (areg) = (delta); \ - (bit) = state->mps ^ 1; \ - *(curctx) = state->nlps; \ - } else { \ - register jpc_mqstate_t *state = *(curctx); \ - (areg) = (delta); \ - (bit) = state->mps; \ - *(curctx) = state->nmps; \ - } \ -} - -#define jpc_mqdec_renormd(areg, creg, ctreg, in, eof, inbuf) \ -{ \ - do { \ - if (!(ctreg)) { \ - jpc_mqdec_bytein2(creg, ctreg, in, eof, inbuf); \ - } \ - (areg) <<= 1; \ - (creg) <<= 1; \ - --(ctreg); \ - } while (!((areg) & 0x8000)); \ -} - -#define jpc_mqdec_bytein2(creg, ctreg, in, eof, inbuf) \ -{ \ - int c; \ - unsigned char prevbuf; \ - if (!(eof)) { \ - if ((c = jas_stream_getc(in)) == EOF) { \ - (eof) = 1; \ - c = 0xff; \ - } \ - prevbuf = (inbuf); \ - (inbuf) = c; \ - if (prevbuf == 0xff) { \ - if (c > 0x8f) { \ - (creg) += 0xff00; \ - (ctreg) = 8; \ - } else { \ - (creg) += c << 9; \ - (ctreg) = 7; \ - } \ - } else { \ - (creg) += c << 8; \ - (ctreg) = 8; \ - } \ - } else { \ - (creg) += 0xff00; \ - (ctreg) = 8; \ - } \ -} - -int jpc_mqdec_getbit_func(jpc_mqdec_t *dec); -int jpc_mqdec_mpsexchrenormd(jpc_mqdec_t *dec); -int jpc_mqdec_lpsexchrenormd(jpc_mqdec_t *dec); - -#endif diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_mqenc.c b/converter/other/jpeg2000/libjasper/jpc/jpc_mqenc.c deleted file mode 100644 index 3f6122e..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_mqenc.c +++ /dev/null @@ -1,441 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * MQ Arithmetic Encoder - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include - -#include "jasper/jas_stream.h" -#include "jasper/jas_malloc.h" -#include "jasper/jas_math.h" -#include "jasper/jas_debug.h" - -#include "jpc_mqenc.h" - -/******************************************************************************\ -* Macros -\******************************************************************************/ - -#if defined(DEBUG) -#define JPC_MQENC_CALL(n, x) \ - ((jas_getdbglevel() >= (n)) ? ((void)(x)) : ((void)0)) -#else -#define JPC_MQENC_CALL(n, x) -#endif - -#define jpc_mqenc_codemps9(areg, creg, ctreg, curctx, enc) \ -{ \ - jpc_mqstate_t *state = *(curctx); \ - (areg) -= state->qeval; \ - if (!((areg) & 0x8000)) { \ - if ((areg) < state->qeval) { \ - (areg) = state->qeval; \ - } else { \ - (creg) += state->qeval; \ - } \ - *(curctx) = state->nmps; \ - jpc_mqenc_renorme((areg), (creg), (ctreg), (enc)); \ - } else { \ - (creg) += state->qeval; \ - } \ -} - -#define jpc_mqenc_codelps2(areg, creg, ctreg, curctx, enc) \ -{ \ - jpc_mqstate_t *state = *(curctx); \ - (areg) -= state->qeval; \ - if ((areg) < state->qeval) { \ - (creg) += state->qeval; \ - } else { \ - (areg) = state->qeval; \ - } \ - *(curctx) = state->nlps; \ - jpc_mqenc_renorme((areg), (creg), (ctreg), (enc)); \ -} - -#define jpc_mqenc_renorme(areg, creg, ctreg, enc) \ -{ \ - do { \ - (areg) <<= 1; \ - (creg) <<= 1; \ - if (!--(ctreg)) { \ - jpc_mqenc_byteout((areg), (creg), (ctreg), (enc)); \ - } \ - } while (!((areg) & 0x8000)); \ -} - -#define jpc_mqenc_byteout(areg, creg, ctreg, enc) \ -{ \ - if ((enc)->outbuf != 0xff) { \ - if ((creg) & 0x8000000) { \ - if (++((enc)->outbuf) == 0xff) { \ - (creg) &= 0x7ffffff; \ - jpc_mqenc_byteout2(enc); \ - enc->outbuf = ((creg) >> 20) & 0xff; \ - (creg) &= 0xfffff; \ - (ctreg) = 7; \ - } else { \ - jpc_mqenc_byteout2(enc); \ - enc->outbuf = ((creg) >> 19) & 0xff; \ - (creg) &= 0x7ffff; \ - (ctreg) = 8; \ - } \ - } else { \ - jpc_mqenc_byteout2(enc); \ - (enc)->outbuf = ((creg) >> 19) & 0xff; \ - (creg) &= 0x7ffff; \ - (ctreg) = 8; \ - } \ - } else { \ - jpc_mqenc_byteout2(enc); \ - (enc)->outbuf = ((creg) >> 20) & 0xff; \ - (creg) &= 0xfffff; \ - (ctreg) = 7; \ - } \ -} - -#define jpc_mqenc_byteout2(enc) \ -{ \ - if (enc->outbuf >= 0) { \ - if (jas_stream_putc(enc->out, (unsigned char)enc->outbuf) == EOF) { \ - enc->err |= 1; \ - } \ - } \ - enc->lastbyte = enc->outbuf; \ -} - -/******************************************************************************\ -* Local function protoypes. -\******************************************************************************/ - -static void jpc_mqenc_setbits(jpc_mqenc_t *mqenc); - -/******************************************************************************\ -* Code for creation and destruction of encoder. -\******************************************************************************/ - -/* Create a MQ encoder. */ - -jpc_mqenc_t *jpc_mqenc_create(int maxctxs, jas_stream_t *out) -{ - jpc_mqenc_t *mqenc; - - /* Allocate memory for the MQ encoder. */ - if (!(mqenc = jas_malloc(sizeof(jpc_mqenc_t)))) { - goto error; - } - mqenc->out = out; - mqenc->maxctxs = maxctxs; - - /* Allocate memory for the per-context state information. */ - if (!(mqenc->ctxs = jas_malloc(mqenc->maxctxs * sizeof(jpc_mqstate_t *)))) { - goto error; - } - - /* Set the current context to the first one. */ - mqenc->curctx = mqenc->ctxs; - - jpc_mqenc_init(mqenc); - - /* Initialize the per-context state information to something sane. */ - jpc_mqenc_setctxs(mqenc, 0, 0); - - return mqenc; - -error: - if (mqenc) { - jpc_mqenc_destroy(mqenc); - } - return 0; -} - -/* Destroy a MQ encoder. */ - -void jpc_mqenc_destroy(jpc_mqenc_t *mqenc) -{ - if (mqenc->ctxs) { - jas_free(mqenc->ctxs); - } - jas_free(mqenc); -} - -/******************************************************************************\ -* State initialization code. -\******************************************************************************/ - -/* Initialize the coding state of a MQ encoder. */ - -void jpc_mqenc_init(jpc_mqenc_t *mqenc) -{ - mqenc->areg = 0x8000; - mqenc->outbuf = -1; - mqenc->creg = 0; - mqenc->ctreg = 12; - mqenc->lastbyte = -1; - mqenc->err = 0; -} - -/* Initialize one or more contexts. */ - -void jpc_mqenc_setctxs(jpc_mqenc_t *mqenc, int numctxs, jpc_mqctx_t *ctxs) -{ - jpc_mqstate_t **ctx; - int n; - - ctx = mqenc->ctxs; - n = JAS_MIN(mqenc->maxctxs, numctxs); - while (--n >= 0) { - *ctx = &jpc_mqstates[2 * ctxs->ind + ctxs->mps]; - ++ctx; - ++ctxs; - } - n = mqenc->maxctxs - numctxs; - while (--n >= 0) { - *ctx = &jpc_mqstates[0]; - ++ctx; - } - -} - -/* Get the coding state for a MQ encoder. */ - -void jpc_mqenc_getstate(jpc_mqenc_t *mqenc, jpc_mqencstate_t *state) -{ - state->areg = mqenc->areg; - state->creg = mqenc->creg; - state->ctreg = mqenc->ctreg; - state->lastbyte = mqenc->lastbyte; -} - -/******************************************************************************\ -* Code for coding symbols. -\******************************************************************************/ - -/* Encode a bit. */ - -int jpc_mqenc_putbit_func(jpc_mqenc_t *mqenc, int bit) -{ - const jpc_mqstate_t *state; - JAS_DBGLOG(100, ("jpc_mqenc_putbit(%p, %d)\n", mqenc, bit)); - JPC_MQENC_CALL(100, jpc_mqenc_dump(mqenc, stderr)); - - state = *(mqenc->curctx); - - if (state->mps == bit) { - /* Apply the CODEMPS algorithm as defined in the standard. */ - mqenc->areg -= state->qeval; - if (!(mqenc->areg & 0x8000)) { - jpc_mqenc_codemps2(mqenc); - } else { - mqenc->creg += state->qeval; - } - } else { - /* Apply the CODELPS algorithm as defined in the standard. */ - jpc_mqenc_codelps2(mqenc->areg, mqenc->creg, mqenc->ctreg, mqenc->curctx, mqenc); - } - - return jpc_mqenc_error(mqenc) ? (-1) : 0; -} - -int jpc_mqenc_codemps2(jpc_mqenc_t *mqenc) -{ - /* Note: This function only performs part of the work associated with - the CODEMPS algorithm from the standard. Some of the work is also - performed by the caller. */ - - jpc_mqstate_t *state = *(mqenc->curctx); - if (mqenc->areg < state->qeval) { - mqenc->areg = state->qeval; - } else { - mqenc->creg += state->qeval; - } - *mqenc->curctx = state->nmps; - jpc_mqenc_renorme(mqenc->areg, mqenc->creg, mqenc->ctreg, mqenc); - return jpc_mqenc_error(mqenc) ? (-1) : 0; -} - -int jpc_mqenc_codelps(jpc_mqenc_t *mqenc) -{ - jpc_mqenc_codelps2(mqenc->areg, mqenc->creg, mqenc->ctreg, mqenc->curctx, mqenc); - return jpc_mqenc_error(mqenc) ? (-1) : 0; -} - -/******************************************************************************\ -* Miscellaneous code. -\******************************************************************************/ - -/* Terminate the code word. */ - -int jpc_mqenc_flush(jpc_mqenc_t *mqenc, int termmode) -{ - int_fast16_t k; - - switch (termmode) { - case JPC_MQENC_PTERM: - k = 11 - mqenc->ctreg + 1; - while (k > 0) { - mqenc->creg <<= mqenc->ctreg; - mqenc->ctreg = 0; - jpc_mqenc_byteout(mqenc->areg, mqenc->creg, mqenc->ctreg, - mqenc); - k -= mqenc->ctreg; - } - if (mqenc->outbuf != 0xff) { - jpc_mqenc_byteout(mqenc->areg, mqenc->creg, mqenc->ctreg, mqenc); - } - break; - case JPC_MQENC_DEFTERM: - jpc_mqenc_setbits(mqenc); - mqenc->creg <<= mqenc->ctreg; - jpc_mqenc_byteout(mqenc->areg, mqenc->creg, mqenc->ctreg, mqenc); - mqenc->creg <<= mqenc->ctreg; - jpc_mqenc_byteout(mqenc->areg, mqenc->creg, mqenc->ctreg, mqenc); - if (mqenc->outbuf != 0xff) { - jpc_mqenc_byteout(mqenc->areg, mqenc->creg, mqenc->ctreg, mqenc); - } - break; - default: - abort(); - break; - } - return 0; -} - -static void jpc_mqenc_setbits(jpc_mqenc_t *mqenc) -{ - uint_fast32_t tmp = mqenc->creg + mqenc->areg; - mqenc->creg |= 0xffff; - if (mqenc->creg >= tmp) { - mqenc->creg -= 0x8000; - } -} - -/* Dump a MQ encoder to a stream for debugging. */ - -int jpc_mqenc_dump(jpc_mqenc_t *mqenc, FILE *out) -{ - fprintf(out, "AREG = %08x, CREG = %08x, CTREG = %d\n", - (unsigned)mqenc->areg, (unsigned)mqenc->creg, (int)mqenc->ctreg); - fprintf(out, "IND = %02d, MPS = %d, QEVAL = %04x\n", - (int)(*mqenc->curctx - jpc_mqstates), (int)(*mqenc->curctx)->mps, - (unsigned)(*mqenc->curctx)->qeval); - return 0; -} diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_mqenc.h b/converter/other/jpeg2000/libjasper/jpc/jpc_mqenc.h deleted file mode 100644 index 1421ae4..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_mqenc.h +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * MQ Arithmetic Encoder - * - * $Id$ - */ - -#ifndef JPC_MQENC_H -#define JPC_MQENC_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include "jasper/jas_types.h" -#include "jasper/jas_stream.h" - -#include "jpc_mqcod.h" - -/******************************************************************************\ -* Constants. -\******************************************************************************/ - -/* - * Termination modes. - */ - -#define JPC_MQENC_DEFTERM 0 /* default termination */ -#define JPC_MQENC_PTERM 1 /* predictable termination */ - -/******************************************************************************\ -* Types. -\******************************************************************************/ - -/* MQ arithmetic encoder class. */ - -typedef struct { - - /* The C register. */ - uint_fast32_t creg; - - /* The A register. */ - uint_fast32_t areg; - - /* The CT register. */ - uint_fast32_t ctreg; - - /* The maximum number of contexts. */ - int maxctxs; - - /* The per-context information. */ - jpc_mqstate_t **ctxs; - - /* The current context. */ - jpc_mqstate_t **curctx; - - /* The stream for encoder output. */ - jas_stream_t *out; - - /* The byte buffer (i.e., the B variable in the standard). */ - int_fast16_t outbuf; - - /* The last byte output. */ - int_fast16_t lastbyte; - - /* The error indicator. */ - int err; - -} jpc_mqenc_t; - -/* MQ arithmetic encoder state information. */ - -typedef struct { - - /* The A register. */ - unsigned areg; - - /* The C register. */ - unsigned creg; - - /* The CT register. */ - unsigned ctreg; - - /* The last byte output by the encoder. */ - int lastbyte; - -} jpc_mqencstate_t; - -/******************************************************************************\ -* Functions/macros for construction and destruction. -\******************************************************************************/ - -/* Create a MQ encoder. */ -jpc_mqenc_t *jpc_mqenc_create(int maxctxs, jas_stream_t *out); - -/* Destroy a MQ encoder. */ -void jpc_mqenc_destroy(jpc_mqenc_t *enc); - -/******************************************************************************\ -* Functions/macros for initialization. -\******************************************************************************/ - -/* Initialize a MQ encoder. */ -void jpc_mqenc_init(jpc_mqenc_t *enc); - -/******************************************************************************\ -* Functions/macros for context manipulation. -\******************************************************************************/ - -/* Set the current context. */ -#define jpc_mqenc_setcurctx(enc, ctxno) \ - ((enc)->curctx = &(enc)->ctxs[ctxno]); - -/* Set the state information for a particular context. */ -void jpc_mqenc_setctx(jpc_mqenc_t *enc, int ctxno, jpc_mqctx_t *ctx); - -/* Set the state information for multiple contexts. */ -void jpc_mqenc_setctxs(jpc_mqenc_t *enc, int numctxs, jpc_mqctx_t *ctxs); - -/******************************************************************************\ -* Miscellaneous functions/macros. -\******************************************************************************/ - -/* Get the error state of a MQ encoder. */ -#define jpc_mqenc_error(enc) \ - ((enc)->err) - -/* Get the current encoder state. */ -void jpc_mqenc_getstate(jpc_mqenc_t *enc, jpc_mqencstate_t *state); - -/* Terminate the code. */ -int jpc_mqenc_flush(jpc_mqenc_t *enc, int termmode); - -/******************************************************************************\ -* Functions/macros for encoding bits. -\******************************************************************************/ - -/* Encode a bit. */ -#if !defined(DEBUG) -#define jpc_mqenc_putbit(enc, bit) jpc_mqenc_putbit_macro(enc, bit) -#else -#define jpc_mqenc_putbit(enc, bit) jpc_mqenc_putbit_func(enc, bit) -#endif - -/******************************************************************************\ -* Functions/macros for debugging. -\******************************************************************************/ - -int jpc_mqenc_dump(jpc_mqenc_t *mqenc, FILE *out); - -/******************************************************************************\ -* Implementation-specific details. -\******************************************************************************/ - -/* Note: This macro is included only to satisfy the needs of - the mqenc_putbit macro. */ -#define jpc_mqenc_putbit_macro(enc, bit) \ - (((*((enc)->curctx))->mps == (bit)) ? \ - (((enc)->areg -= (*(enc)->curctx)->qeval), \ - ((!((enc)->areg & 0x8000)) ? (jpc_mqenc_codemps2(enc)) : \ - ((enc)->creg += (*(enc)->curctx)->qeval))) : \ - jpc_mqenc_codelps(enc)) - -/* Note: These function prototypes are included only to satisfy the - needs of the mqenc_putbit_macro macro. Do not call any of these - functions directly. */ -int jpc_mqenc_codemps2(jpc_mqenc_t *enc); -int jpc_mqenc_codelps(jpc_mqenc_t *enc); - -/* Note: This function prototype is included only to satisfy the needs of - the mqenc_putbit macro. */ -int jpc_mqenc_putbit_func(jpc_mqenc_t *enc, int bit); - -#endif diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_qmfb.c b/converter/other/jpeg2000/libjasper/jpc/jpc_qmfb.c deleted file mode 100644 index 80bc5aa..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_qmfb.c +++ /dev/null @@ -1,1091 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Quadrature Mirror-Image Filter Bank (QMFB) Library - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include - -#include "jasper/jas_fix.h" -#include "jasper/jas_malloc.h" -#include "jasper/jas_math.h" - -#include "jpc_qmfb.h" -#include "jpc_tsfb.h" -#include "jpc_math.h" - -/******************************************************************************\ -* -\******************************************************************************/ - -static jpc_qmfb1d_t *jpc_qmfb1d_create(void); - -static int jpc_ft_getnumchans(jpc_qmfb1d_t *qmfb); -static int jpc_ft_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters); -static int jpc_ft_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters); -static void jpc_ft_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x); -static void jpc_ft_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x); - -static int jpc_ns_getnumchans(jpc_qmfb1d_t *qmfb); -static int jpc_ns_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters); -static int jpc_ns_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters); -static void jpc_ns_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x); -static void jpc_ns_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x); - -/******************************************************************************\ -* -\******************************************************************************/ - -jpc_qmfb1dops_t jpc_ft_ops = { - jpc_ft_getnumchans, - jpc_ft_getanalfilters, - jpc_ft_getsynfilters, - jpc_ft_analyze, - jpc_ft_synthesize -}; - -jpc_qmfb1dops_t jpc_ns_ops = { - jpc_ns_getnumchans, - jpc_ns_getanalfilters, - jpc_ns_getsynfilters, - jpc_ns_analyze, - jpc_ns_synthesize -}; - -/******************************************************************************\ -* -\******************************************************************************/ - -static void jpc_qmfb1d_setup(jpc_fix_t *startptr, int startind, int endind, - int intrastep, jpc_fix_t **lstartptr, int *lstartind, int *lendind, - jpc_fix_t **hstartptr, int *hstartind, int *hendind) -{ - *lstartind = JPC_CEILDIVPOW2(startind, 1); - *lendind = JPC_CEILDIVPOW2(endind, 1); - *hstartind = JPC_FLOORDIVPOW2(startind, 1); - *hendind = JPC_FLOORDIVPOW2(endind, 1); - *lstartptr = startptr; - *hstartptr = &startptr[(*lendind - *lstartind) * intrastep]; -} - -static void jpc_qmfb1d_split(jpc_fix_t *startptr, int startind, int endind, - register int step, jpc_fix_t *lstartptr, int lstartind, int lendind, - jpc_fix_t *hstartptr, int hstartind, int hendind) -{ -#define QMFB_SPLITBUFSIZE 4096 - jpc_fix_t splitbuf[QMFB_SPLITBUFSIZE]; - jpc_fix_t *buf = splitbuf; - int llen; - int hlen; - int twostep; - jpc_fix_t *tmpptr; - register jpc_fix_t *ptr; - register jpc_fix_t *hptr; - register jpc_fix_t *lptr; - register int n; - int state; - - twostep = step << 1; - llen = lendind - lstartind; - hlen = hendind - hstartind; - - if (hstartind < lstartind) { - /* The first sample in the input signal is to appear - in the highpass subband signal. */ - /* Copy the appropriate samples into the lowpass subband - signal, saving any samples destined for the highpass subband - signal as they are overwritten. */ - tmpptr = buf; - ptr = &startptr[step]; - lptr = lstartptr; - n = llen; - state = 1; - while (n-- > 0) { - if (state) { - *tmpptr = *lptr; - ++tmpptr; - } - *lptr = *ptr; - ptr += twostep; - lptr += step; - state ^= 1; - } - /* Copy the appropriate samples into the highpass subband - signal. */ - /* Handle the nonoverwritten samples. */ - hptr = &hstartptr[(hlen - 1) * step]; - ptr = &startptr[(((llen + hlen - 1) >> 1) << 1) * step]; - n = hlen - (tmpptr - buf); - while (n-- > 0) { - *hptr = *ptr; - hptr -= step; - ptr -= twostep; - } - /* Handle the overwritten samples. */ - n = tmpptr - buf; - while (n-- > 0) { - --tmpptr; - *hptr = *tmpptr; - hptr -= step; - } - } else { - /* The first sample in the input signal is to appear - in the lowpass subband signal. */ - /* Copy the appropriate samples into the lowpass subband - signal, saving any samples for the highpass subband - signal as they are overwritten. */ - state = 0; - ptr = startptr; - lptr = lstartptr; - tmpptr = buf; - n = llen; - while (n-- > 0) { - if (state) { - *tmpptr = *lptr; - ++tmpptr; - } - *lptr = *ptr; - ptr += twostep; - lptr += step; - state ^= 1; - } - /* Copy the appropriate samples into the highpass subband - signal. */ - /* Handle the nonoverwritten samples. */ - ptr = &startptr[((((llen + hlen) >> 1) << 1) - 1) * step]; - hptr = &hstartptr[(hlen - 1) * step]; - n = hlen - (tmpptr - buf); - while (n-- > 0) { - *hptr = *ptr; - ptr -= twostep; - hptr -= step; - } - /* Handle the overwritten samples. */ - n = tmpptr - buf; - while (n-- > 0) { - --tmpptr; - *hptr = *tmpptr; - hptr -= step; - } - } -} - -static void jpc_qmfb1d_join(jpc_fix_t *startptr, int startind, int endind, - register int step, jpc_fix_t *lstartptr, int lstartind, int lendind, - jpc_fix_t *hstartptr, int hstartind, int hendind) -{ -#define QMFB_JOINBUFSIZE 4096 - jpc_fix_t joinbuf[QMFB_JOINBUFSIZE]; - jpc_fix_t *buf = joinbuf; - int llen; - int hlen; - int twostep; - jpc_fix_t *tmpptr; - register jpc_fix_t *ptr; - register jpc_fix_t *hptr; - register jpc_fix_t *lptr; - register int n; - int state; - - twostep = step << 1; - llen = lendind - lstartind; - hlen = hendind - hstartind; - - if (hstartind < lstartind) { - /* The first sample in the highpass subband signal is to - appear first in the output signal. */ - /* Copy the appropriate samples into the first phase of the - output signal. */ - tmpptr = buf; - hptr = hstartptr; - ptr = startptr; - n = (llen + 1) >> 1; - while (n-- > 0) { - *tmpptr = *ptr; - *ptr = *hptr; - ++tmpptr; - ptr += twostep; - hptr += step; - } - n = hlen - ((llen + 1) >> 1); - while (n-- > 0) { - *ptr = *hptr; - ptr += twostep; - hptr += step; - } - /* Copy the appropriate samples into the second phase of - the output signal. */ - ptr -= (lendind > hendind) ? (step) : (step + twostep); - state = !((llen - 1) & 1); - lptr = &lstartptr[(llen - 1) * step]; - n = llen; - while (n-- > 0) { - if (state) { - --tmpptr; - *ptr = *tmpptr; - } else { - *ptr = *lptr; - } - lptr -= step; - ptr -= twostep; - state ^= 1; - } - } else { - /* The first sample in the lowpass subband signal is to - appear first in the output signal. */ - /* Copy the appropriate samples into the first phase of the - output signal (corresponding to even indexed samples). */ - lptr = &lstartptr[(llen - 1) * step]; - ptr = &startptr[((llen - 1) << 1) * step]; - n = llen >> 1; - tmpptr = buf; - while (n-- > 0) { - *tmpptr = *ptr; - *ptr = *lptr; - ++tmpptr; - ptr -= twostep; - lptr -= step; - } - n = llen - (llen >> 1); - while (n-- > 0) { - *ptr = *lptr; - ptr -= twostep; - lptr -= step; - } - /* Copy the appropriate samples into the second phase of - the output signal (corresponding to odd indexed - samples). */ - ptr = &startptr[step]; - hptr = hstartptr; - state = !(llen & 1); - n = hlen; - while (n-- > 0) { - if (state) { - --tmpptr; - *ptr = *tmpptr; - } else { - *ptr = *hptr; - } - hptr += step; - ptr += twostep; - state ^= 1; - } - } -} - -/******************************************************************************\ -* Code for 5/3 transform. -\******************************************************************************/ - -static int jpc_ft_getnumchans(jpc_qmfb1d_t *qmfb) -{ - return 2; -} - -static int jpc_ft_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters) -{ - abort(); - return -1; -} - -static int jpc_ft_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters) -{ - jas_seq_t *lf; - jas_seq_t *hf; - - lf = 0; - hf = 0; - - if (len > 1 || (!len)) { - if (!(lf = jas_seq_create(-1, 2))) { - goto error; - } - jas_seq_set(lf, -1, jpc_dbltofix(0.5)); - jas_seq_set(lf, 0, jpc_dbltofix(1.0)); - jas_seq_set(lf, 1, jpc_dbltofix(0.5)); - if (!(hf = jas_seq_create(-1, 4))) { - goto error; - } - jas_seq_set(hf, -1, jpc_dbltofix(-0.125)); - jas_seq_set(hf, 0, jpc_dbltofix(-0.25)); - jas_seq_set(hf, 1, jpc_dbltofix(0.75)); - jas_seq_set(hf, 2, jpc_dbltofix(-0.25)); - jas_seq_set(hf, 3, jpc_dbltofix(-0.125)); - } else if (len == 1) { - if (!(lf = jas_seq_create(0, 1))) { - goto error; - } - jas_seq_set(lf, 0, jpc_dbltofix(1.0)); - if (!(hf = jas_seq_create(0, 1))) { - goto error; - } - jas_seq_set(hf, 0, jpc_dbltofix(2.0)); - } else { - abort(); - } - - filters[0] = lf; - filters[1] = hf; - - return 0; - -error: - if (lf) { - jas_seq_destroy(lf); - } - if (hf) { - jas_seq_destroy(hf); - } - return -1; -} - -#define NFT_LIFT0(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pluseq) \ -{ \ - register jpc_fix_t *lptr = (lstartptr); \ - register jpc_fix_t *hptr = (hstartptr); \ - register int n = (hendind) - (hstartind); \ - if ((hstartind) < (lstartind)) { \ - pluseq(*hptr, *lptr); \ - hptr += (step); \ - --n; \ - } \ - if ((hendind) >= (lendind)) { \ - --n; \ - } \ - while (n-- > 0) { \ - pluseq(*hptr, jpc_fix_asr(jpc_fix_add(*lptr, lptr[(step)]), 1)); \ - hptr += (step); \ - lptr += (step); \ - } \ - if ((hendind) >= (lendind)) { \ - pluseq(*hptr, *lptr); \ - } \ -} - -#define NFT_LIFT1(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pluseq) \ -{ \ - register jpc_fix_t *lptr = (lstartptr); \ - register jpc_fix_t *hptr = (hstartptr); \ - register int n = (lendind) - (lstartind); \ - if ((hstartind) >= (lstartind)) { \ - pluseq(*lptr, *hptr); \ - lptr += (step); \ - --n; \ - } \ - if ((lendind) > (hendind)) { \ - --n; \ - } \ - while (n-- > 0) { \ - pluseq(*lptr, jpc_fix_asr(jpc_fix_add(*hptr, hptr[(step)]), 2)); \ - lptr += (step); \ - hptr += (step); \ - } \ - if ((lendind) > (hendind)) { \ - pluseq(*lptr, *hptr); \ - } \ -} - -#define RFT_LIFT0(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pmeqop) \ -{ \ - register jpc_fix_t *lptr = (lstartptr); \ - register jpc_fix_t *hptr = (hstartptr); \ - register int n = (hendind) - (hstartind); \ - if ((hstartind) < (lstartind)) { \ - *hptr pmeqop *lptr; \ - hptr += (step); \ - --n; \ - } \ - if ((hendind) >= (lendind)) { \ - --n; \ - } \ - while (n-- > 0) { \ - *hptr pmeqop (*lptr + lptr[(step)]) >> 1; \ - hptr += (step); \ - lptr += (step); \ - } \ - if ((hendind) >= (lendind)) { \ - *hptr pmeqop *lptr; \ - } \ -} - -#define RFT_LIFT1(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pmeqop) \ -{ \ - register jpc_fix_t *lptr = (lstartptr); \ - register jpc_fix_t *hptr = (hstartptr); \ - register int n = (lendind) - (lstartind); \ - if ((hstartind) >= (lstartind)) { \ - *lptr pmeqop ((*hptr << 1) + 2) >> 2; \ - lptr += (step); \ - --n; \ - } \ - if ((lendind) > (hendind)) { \ - --n; \ - } \ - while (n-- > 0) { \ - *lptr pmeqop ((*hptr + hptr[(step)]) + 2) >> 2; \ - lptr += (step); \ - hptr += (step); \ - } \ - if ((lendind) > (hendind)) { \ - *lptr pmeqop ((*hptr << 1) + 2) >> 2; \ - } \ -} - -static void jpc_ft_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x) -{ - jpc_fix_t *startptr; - int startind; - int endind; - jpc_fix_t * lstartptr; - int lstartind; - int lendind; - jpc_fix_t * hstartptr; - int hstartind; - int hendind; - int interstep; - int intrastep; - int numseq; - - if (flags & JPC_QMFB1D_VERT) { - interstep = 1; - intrastep = jas_seq2d_rowstep(x); - numseq = jas_seq2d_width(x); - startind = jas_seq2d_ystart(x); - endind = jas_seq2d_yend(x); - } else { - interstep = jas_seq2d_rowstep(x); - intrastep = 1; - numseq = jas_seq2d_height(x); - startind = jas_seq2d_xstart(x); - endind = jas_seq2d_xend(x); - } - - assert(startind < endind); - - startptr = jas_seq2d_getref(x, jas_seq2d_xstart(x), jas_seq2d_ystart(x)); - if (flags & JPC_QMFB1D_RITIMODE) { - while (numseq-- > 0) { - jpc_qmfb1d_setup(startptr, startind, endind, intrastep, - &lstartptr, &lstartind, &lendind, &hstartptr, - &hstartind, &hendind); - if (endind - startind > 1) { - jpc_qmfb1d_split(startptr, startind, endind, - intrastep, lstartptr, lstartind, lendind, - hstartptr, hstartind, hendind); - RFT_LIFT0(lstartptr, lstartind, lendind, - hstartptr, hstartind, hendind, intrastep, -=); - RFT_LIFT1(lstartptr, lstartind, lendind, - hstartptr, hstartind, hendind, intrastep, +=); - } else { - if (lstartind == lendind) { - *startptr <<= 1; - } - } - startptr += interstep; - } - } else { - while (numseq-- > 0) { - jpc_qmfb1d_setup(startptr, startind, endind, intrastep, - &lstartptr, &lstartind, &lendind, &hstartptr, - &hstartind, &hendind); - if (endind - startind > 1) { - jpc_qmfb1d_split(startptr, startind, endind, - intrastep, lstartptr, lstartind, lendind, - hstartptr, hstartind, hendind); - NFT_LIFT0(lstartptr, lstartind, lendind, - hstartptr, hstartind, hendind, intrastep, - jpc_fix_minuseq); - NFT_LIFT1(lstartptr, lstartind, lendind, - hstartptr, hstartind, hendind, intrastep, - jpc_fix_pluseq); - } else { - if (lstartind == lendind) { - *startptr = jpc_fix_asl(*startptr, 1); - } - } - startptr += interstep; - } - } -} - -static void jpc_ft_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x) -{ - jpc_fix_t *startptr; - int startind; - int endind; - jpc_fix_t *lstartptr; - int lstartind; - int lendind; - jpc_fix_t *hstartptr; - int hstartind; - int hendind; - int interstep; - int intrastep; - int numseq; - - if (flags & JPC_QMFB1D_VERT) { - interstep = 1; - intrastep = jas_seq2d_rowstep(x); - numseq = jas_seq2d_width(x); - startind = jas_seq2d_ystart(x); - endind = jas_seq2d_yend(x); - } else { - interstep = jas_seq2d_rowstep(x); - intrastep = 1; - numseq = jas_seq2d_height(x); - startind = jas_seq2d_xstart(x); - endind = jas_seq2d_xend(x); - } - - assert(startind < endind); - - startptr = jas_seq2d_getref(x, jas_seq2d_xstart(x), jas_seq2d_ystart(x)); - if (flags & JPC_QMFB1D_RITIMODE) { - while (numseq-- > 0) { - jpc_qmfb1d_setup(startptr, startind, endind, intrastep, - &lstartptr, &lstartind, &lendind, &hstartptr, - &hstartind, &hendind); - if (endind - startind > 1) { - RFT_LIFT1(lstartptr, lstartind, lendind, - hstartptr, hstartind, hendind, intrastep, -=); - RFT_LIFT0(lstartptr, lstartind, lendind, - hstartptr, hstartind, hendind, intrastep, +=); - jpc_qmfb1d_join(startptr, startind, endind, - intrastep, lstartptr, lstartind, lendind, - hstartptr, hstartind, hendind); - } else { - if (lstartind == lendind) { - *startptr >>= 1; - } - } - startptr += interstep; - } - } else { - while (numseq-- > 0) { - jpc_qmfb1d_setup(startptr, startind, endind, intrastep, - &lstartptr, &lstartind, &lendind, &hstartptr, - &hstartind, &hendind); - if (endind - startind > 1) { - NFT_LIFT1(lstartptr, lstartind, lendind, - hstartptr, hstartind, hendind, intrastep, - jpc_fix_minuseq); - NFT_LIFT0(lstartptr, lstartind, lendind, - hstartptr, hstartind, hendind, intrastep, - jpc_fix_pluseq); - jpc_qmfb1d_join(startptr, startind, endind, - intrastep, lstartptr, lstartind, lendind, - hstartptr, hstartind, hendind); - } else { - if (lstartind == lendind) { - *startptr = jpc_fix_asr(*startptr, 1); - } - } - startptr += interstep; - } - } -} - -/******************************************************************************\ -* Code for 9/7 transform. -\******************************************************************************/ - -static int jpc_ns_getnumchans(jpc_qmfb1d_t *qmfb) -{ - return 2; -} - -static int jpc_ns_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters) -{ - abort(); - return -1; -} - -static int jpc_ns_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters) -{ - jas_seq_t *lf; - jas_seq_t *hf; - - lf = 0; - hf = 0; - - if (len > 1 || (!len)) { - if (!(lf = jas_seq_create(-3, 4))) { - goto error; - } - jas_seq_set(lf, -3, jpc_dbltofix(-0.09127176311424948)); - jas_seq_set(lf, -2, jpc_dbltofix(-0.05754352622849957)); - jas_seq_set(lf, -1, jpc_dbltofix(0.5912717631142470)); - jas_seq_set(lf, 0, jpc_dbltofix(1.115087052456994)); - jas_seq_set(lf, 1, jpc_dbltofix(0.5912717631142470)); - jas_seq_set(lf, 2, jpc_dbltofix(-0.05754352622849957)); - jas_seq_set(lf, 3, jpc_dbltofix(-0.09127176311424948)); - if (!(hf = jas_seq_create(-3, 6))) { - goto error; - } - jas_seq_set(hf, -3, jpc_dbltofix(-0.02674875741080976 * 2.0)); - jas_seq_set(hf, -2, jpc_dbltofix(-0.01686411844287495 * 2.0)); - jas_seq_set(hf, -1, jpc_dbltofix(0.07822326652898785 * 2.0)); - jas_seq_set(hf, 0, jpc_dbltofix(0.2668641184428723 * 2.0)); - jas_seq_set(hf, 1, jpc_dbltofix(-0.6029490182363579 * 2.0)); - jas_seq_set(hf, 2, jpc_dbltofix(0.2668641184428723 * 2.0)); - jas_seq_set(hf, 3, jpc_dbltofix(0.07822326652898785 * 2.0)); - jas_seq_set(hf, 4, jpc_dbltofix(-0.01686411844287495 * 2.0)); - jas_seq_set(hf, 5, jpc_dbltofix(-0.02674875741080976 * 2.0)); - } else if (len == 1) { - if (!(lf = jas_seq_create(0, 1))) { - goto error; - } - jas_seq_set(lf, 0, jpc_dbltofix(1.0)); - if (!(hf = jas_seq_create(0, 1))) { - goto error; - } - jas_seq_set(hf, 0, jpc_dbltofix(2.0)); - } else { - abort(); - } - - filters[0] = lf; - filters[1] = hf; - - return 0; - -error: - if (lf) { - jas_seq_destroy(lf); - } - if (hf) { - jas_seq_destroy(hf); - } - return -1; -} - -#define NNS_LIFT0(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, alpha) \ -{ \ - register jpc_fix_t *lptr = (lstartptr); \ - register jpc_fix_t *hptr = (hstartptr); \ - register int n = (hendind) - (hstartind); \ - jpc_fix_t twoalpha = jpc_fix_mulbyint(alpha, 2); \ - if ((hstartind) < (lstartind)) { \ - jpc_fix_pluseq(*hptr, jpc_fix_mul(*lptr, (twoalpha))); \ - hptr += (step); \ - --n; \ - } \ - if ((hendind) >= (lendind)) { \ - --n; \ - } \ - while (n-- > 0) { \ - jpc_fix_pluseq(*hptr, jpc_fix_mul(jpc_fix_add(*lptr, lptr[(step)]), (alpha))); \ - hptr += (step); \ - lptr += (step); \ - } \ - if ((hendind) >= (lendind)) { \ - jpc_fix_pluseq(*hptr, jpc_fix_mul(*lptr, (twoalpha))); \ - } \ -} - -#define NNS_LIFT1(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, alpha) \ -{ \ - register jpc_fix_t *lptr = (lstartptr); \ - register jpc_fix_t *hptr = (hstartptr); \ - register int n = (lendind) - (lstartind); \ - int twoalpha = jpc_fix_mulbyint(alpha, 2); \ - if ((hstartind) >= (lstartind)) { \ - jpc_fix_pluseq(*lptr, jpc_fix_mul(*hptr, (twoalpha))); \ - lptr += (step); \ - --n; \ - } \ - if ((lendind) > (hendind)) { \ - --n; \ - } \ - while (n-- > 0) { \ - jpc_fix_pluseq(*lptr, jpc_fix_mul(jpc_fix_add(*hptr, hptr[(step)]), (alpha))); \ - lptr += (step); \ - hptr += (step); \ - } \ - if ((lendind) > (hendind)) { \ - jpc_fix_pluseq(*lptr, jpc_fix_mul(*hptr, (twoalpha))); \ - } \ -} - -#define NNS_SCALE(startptr, startind, endind, step, alpha) \ -{ \ - register jpc_fix_t *ptr = (startptr); \ - register int n = (endind) - (startind); \ - while (n-- > 0) { \ - jpc_fix_muleq(*ptr, alpha); \ - ptr += (step); \ - } \ -} - -static void jpc_ns_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x) -{ - jpc_fix_t *startptr; - int startind; - int endind; - jpc_fix_t *lstartptr; - int lstartind; - int lendind; - jpc_fix_t *hstartptr; - int hstartind; - int hendind; - int interstep; - int intrastep; - int numseq; - - if (flags & JPC_QMFB1D_VERT) { - interstep = 1; - intrastep = jas_seq2d_rowstep(x); - numseq = jas_seq2d_width(x); - startind = jas_seq2d_ystart(x); - endind = jas_seq2d_yend(x); - } else { - interstep = jas_seq2d_rowstep(x); - intrastep = 1; - numseq = jas_seq2d_height(x); - startind = jas_seq2d_xstart(x); - endind = jas_seq2d_xend(x); - } - - assert(startind < endind); - - startptr = jas_seq2d_getref(x, jas_seq2d_xstart(x), jas_seq2d_ystart(x)); - if (!(flags & JPC_QMFB1D_RITIMODE)) { - while (numseq-- > 0) { - jpc_qmfb1d_setup(startptr, startind, endind, intrastep, - &lstartptr, &lstartind, &lendind, &hstartptr, - &hstartind, &hendind); - if (endind - startind > 1) { - jpc_qmfb1d_split(startptr, startind, endind, - intrastep, lstartptr, lstartind, lendind, - hstartptr, hstartind, hendind); - NNS_LIFT0(lstartptr, lstartind, lendind, - hstartptr, hstartind, hendind, intrastep, - jpc_dbltofix(-1.586134342)); - NNS_LIFT1(lstartptr, lstartind, lendind, - hstartptr, hstartind, hendind, intrastep, - jpc_dbltofix(-0.052980118)); - NNS_LIFT0(lstartptr, lstartind, lendind, - hstartptr, hstartind, hendind, intrastep, - jpc_dbltofix(0.882911075)); - NNS_LIFT1(lstartptr, lstartind, lendind, - hstartptr, hstartind, hendind, intrastep, - jpc_dbltofix(0.443506852)); - NNS_SCALE(lstartptr, lstartind, lendind, - intrastep, jpc_dbltofix(1.0/1.23017410558578)); - NNS_SCALE(hstartptr, hstartind, hendind, - intrastep, jpc_dbltofix(1.0/1.62578613134411)); - } else { -#if 0 - if (lstartind == lendind) { - *startptr = jpc_fix_asl(*startptr, 1); - } -#endif - } - startptr += interstep; - } - } else { - /* The reversible integer-to-integer mode is not valid for this - transform. */ - abort(); - } -} - -static void jpc_ns_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x) -{ - jpc_fix_t *startptr; - int startind; - int endind; - jpc_fix_t *lstartptr; - int lstartind; - int lendind; - jpc_fix_t *hstartptr; - int hstartind; - int hendind; - int interstep; - int intrastep; - int numseq; - - if (flags & JPC_QMFB1D_VERT) { - interstep = 1; - intrastep = jas_seq2d_rowstep(x); - numseq = jas_seq2d_width(x); - startind = jas_seq2d_ystart(x); - endind = jas_seq2d_yend(x); - } else { - interstep = jas_seq2d_rowstep(x); - intrastep = 1; - numseq = jas_seq2d_height(x); - startind = jas_seq2d_xstart(x); - endind = jas_seq2d_xend(x); - } - - assert(startind < endind); - - startptr = jas_seq2d_getref(x, jas_seq2d_xstart(x), jas_seq2d_ystart(x)); - if (!(flags & JPC_QMFB1D_RITIMODE)) { - while (numseq-- > 0) { - jpc_qmfb1d_setup(startptr, startind, endind, intrastep, - &lstartptr, &lstartind, &lendind, &hstartptr, - &hstartind, &hendind); - if (endind - startind > 1) { - NNS_SCALE(lstartptr, lstartind, lendind, - intrastep, jpc_dbltofix(1.23017410558578)); - NNS_SCALE(hstartptr, hstartind, hendind, - intrastep, jpc_dbltofix(1.62578613134411)); - NNS_LIFT1(lstartptr, lstartind, lendind, - hstartptr, hstartind, hendind, intrastep, - jpc_dbltofix(-0.443506852)); - NNS_LIFT0(lstartptr, lstartind, lendind, - hstartptr, hstartind, hendind, intrastep, - jpc_dbltofix(-0.882911075)); - NNS_LIFT1(lstartptr, lstartind, lendind, - hstartptr, hstartind, hendind, intrastep, - jpc_dbltofix(0.052980118)); - NNS_LIFT0(lstartptr, lstartind, lendind, - hstartptr, hstartind, hendind, intrastep, - jpc_dbltofix(1.586134342)); - jpc_qmfb1d_join(startptr, startind, endind, - intrastep, lstartptr, lstartind, lendind, - hstartptr, hstartind, hendind); - } else { -#if 0 - if (lstartind == lendind) { - *startptr = jpc_fix_asr(*startptr, 1); - } -#endif - } - startptr += interstep; - } - } else { - /* The reversible integer-to-integer mode is not valid - for this transform. */ - abort(); - } -} - -/******************************************************************************\ -* -\******************************************************************************/ - -jpc_qmfb1d_t *jpc_qmfb1d_make(int qmfbid) -{ - jpc_qmfb1d_t *qmfb; - if (!(qmfb = jpc_qmfb1d_create())) { - return 0; - } - switch (qmfbid) { - case JPC_QMFB1D_FT: - qmfb->ops = &jpc_ft_ops; - break; - case JPC_QMFB1D_NS: - qmfb->ops = &jpc_ns_ops; - break; - default: - jpc_qmfb1d_destroy(qmfb); - return 0; - break; - } - return qmfb; -} - -static jpc_qmfb1d_t *jpc_qmfb1d_create() -{ - jpc_qmfb1d_t *qmfb; - if (!(qmfb = jas_malloc(sizeof(jpc_qmfb1d_t)))) { - return 0; - } - qmfb->ops = 0; - return qmfb; -} - -jpc_qmfb1d_t *jpc_qmfb1d_copy(jpc_qmfb1d_t *qmfb) -{ - jpc_qmfb1d_t *newqmfb; - - if (!(newqmfb = jpc_qmfb1d_create())) { - return 0; - } - newqmfb->ops = qmfb->ops; - return newqmfb; -} - -void jpc_qmfb1d_destroy(jpc_qmfb1d_t *qmfb) -{ - jas_free(qmfb); -} - -/******************************************************************************\ -* -\******************************************************************************/ - -void jpc_qmfb1d_getbands(jpc_qmfb1d_t *qmfb, int flags, uint_fast32_t xstart, - uint_fast32_t ystart, uint_fast32_t xend, uint_fast32_t yend, int maxbands, - int *numbandsptr, jpc_qmfb1dband_t *bands) -{ - int start; - int end; - if (flags & JPC_QMFB1D_VERT) { - start = ystart; - end = yend; - } else { - start = xstart; - end = xend; - } - assert(jpc_qmfb1d_getnumchans(qmfb) == 2); - assert(start <= end); - bands[0].start = JPC_CEILDIVPOW2(start, 1); - bands[0].end = JPC_CEILDIVPOW2(end, 1); - bands[0].locstart = start; - bands[0].locend = start + bands[0].end - bands[0].start; - bands[1].start = JPC_FLOORDIVPOW2(start, 1); - bands[1].end = JPC_FLOORDIVPOW2(end, 1); - bands[1].locstart = bands[0].locend; - bands[1].locend = bands[1].locstart + bands[1].end - bands[1].start; - assert(bands[1].locend == end); - *numbandsptr = 2; -} - -/******************************************************************************\ -* -\******************************************************************************/ - -int jpc_qmfb1d_getnumchans(jpc_qmfb1d_t *qmfb) -{ - return (*qmfb->ops->getnumchans)(qmfb); -} - -int jpc_qmfb1d_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters) -{ - return (*qmfb->ops->getanalfilters)(qmfb, len, filters); -} - -int jpc_qmfb1d_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters) -{ - return (*qmfb->ops->getsynfilters)(qmfb, len, filters); -} - -void jpc_qmfb1d_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x) -{ - (*qmfb->ops->analyze)(qmfb, flags, x); -} - -void jpc_qmfb1d_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x) -{ - (*qmfb->ops->synthesize)(qmfb, flags, x); -} diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_qmfb.h b/converter/other/jpeg2000/libjasper/jpc/jpc_qmfb.h deleted file mode 100644 index e10b6c1..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_qmfb.h +++ /dev/null @@ -1,235 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Quadrature Mirror-Image Filter Bank (QMFB) Routines - * - * $Id$ - */ - -#ifndef JPC_QMFB_H -#define JPC_QMFB_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include "jasper/jas_seq.h" - -/******************************************************************************\ -* Constants. -\******************************************************************************/ - -/* The maximum number of channels for a QMF bank. */ -#define JPC_QMFB1D_MAXCHANS 2 - -/* Select reversible integer-to-integer mode. */ -#define JPC_QMFB1D_RITIMODE 1 - -/* Vertical filtering. */ -#define JPC_QMFB1D_VERT 0x10000 - -/* QMFB IDs. */ -#define JPC_QMFB1D_FT 1 /* 5/3 */ -#define JPC_QMFB1D_NS 2 /* 9/7 */ - -/******************************************************************************\ -* Types. -\******************************************************************************/ - -/* Forward declaration. */ -struct jpc_qmfb1dops_s; - -/* Band information. */ - -typedef struct { - - /* The starting index for the band in the downsampled domain. */ - int start; - - /* The ending index for the band in the downsampled domain. */ - int end; - - /* The location of the start of the band. */ - int locstart; - - /* The location of the end of the band. */ - int locend; - -} jpc_qmfb1dband_t; - -/* QMF bank */ - -typedef struct { - - /* The operations for this QMFB. */ - struct jpc_qmfb1dops_s *ops; - -} jpc_qmfb1d_t; - -/* QMFB operations. */ - -typedef struct jpc_qmfb1dops_s { - - /* The number of channels in the QMFB. */ - int (*getnumchans)(jpc_qmfb1d_t *qmfb); - - /* Get the analysis filters for this QMFB. */ - int (*getanalfilters)(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters); - - /* Get the synthesis filters for this QMFB. */ - int (*getsynfilters)(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters); - - /* Do analysis. */ - void (*analyze)(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x); - - /* Do synthesis. */ - void (*synthesize)(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x); - -} jpc_qmfb1dops_t; - -/******************************************************************************\ -* Functions. -\******************************************************************************/ - -/* Create a QMFB from a QMFB ID. */ -jpc_qmfb1d_t *jpc_qmfb1d_make(int qmfbid); - -/* Create a copy of a QMFB. */ -jpc_qmfb1d_t *jpc_qmfb1d_copy(jpc_qmfb1d_t *qmfb); - -/* Destroy a QMFB. */ -void jpc_qmfb1d_destroy(jpc_qmfb1d_t *qmfb); - -/* Get the number of channels for a QMFB. */ -int jpc_qmfb1d_getnumchans(jpc_qmfb1d_t *qmfb); - -/* Get the analysis filters for a QMFB. */ -int jpc_qmfb1d_getanalfilters(jpc_qmfb1d_t *qmfb, int len, - jas_seq2d_t **filters); - -/* Get the synthesis filters for a QMFB. */ -int jpc_qmfb1d_getsynfilters(jpc_qmfb1d_t *qmfb, int len, - jas_seq2d_t **filters); - -/* Get the bands for a QMFB. */ -void jpc_qmfb1d_getbands(jpc_qmfb1d_t *qmfb, int flags, uint_fast32_t xstart, - uint_fast32_t ystart, uint_fast32_t xend, uint_fast32_t yend, int maxbands, - int *numbandsptr, jpc_qmfb1dband_t *bands); - -/* Perform analysis. */ -void jpc_qmfb1d_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x); - -/* Perform synthesis. */ -void jpc_qmfb1d_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x); - -#endif diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_t1cod.c b/converter/other/jpeg2000/libjasper/jpc/jpc_t1cod.c deleted file mode 100644 index 650cb85..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_t1cod.c +++ /dev/null @@ -1,537 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include -#include -#include - -#include "jasper/jas_types.h" -#include "jasper/jas_math.h" - -#include "jpc_bs.h" -#include "jpc_dec.h" -#include "jpc_cs.h" -#include "jpc_mqcod.h" -#include "jpc_t1cod.h" -#include "jpc_tsfb.h" - -double jpc_pow2i(int n); - -/******************************************************************************\ -* Global data. -\******************************************************************************/ - -int jpc_zcctxnolut[4 * 256]; -int jpc_spblut[256]; -int jpc_scctxnolut[256]; -int jpc_magctxnolut[4096]; - -jpc_fix_t jpc_signmsedec[1 << JPC_NMSEDEC_BITS]; -jpc_fix_t jpc_refnmsedec[1 << JPC_NMSEDEC_BITS]; -jpc_fix_t jpc_signmsedec0[1 << JPC_NMSEDEC_BITS]; -jpc_fix_t jpc_refnmsedec0[1 << JPC_NMSEDEC_BITS]; - -jpc_mqctx_t jpc_mqctxs[JPC_NUMCTXS]; - -/******************************************************************************\ -* Code. -\******************************************************************************/ - -int JPC_PASSTYPE(int passno) -{ - int passtype; - switch (passno % 3) { - case 0: - passtype = JPC_CLNPASS; - break; - case 1: - passtype = JPC_SIGPASS; - break; - case 2: - passtype = JPC_REFPASS; - break; - default: - passtype = -1; - assert(0); - break; - } - return passtype; -} - -int JPC_NOMINALGAIN(int qmfbid, int numlvls, int lvlno, int orient) -{ -if (qmfbid == JPC_COX_INS) { - return 0; -} - assert(qmfbid == JPC_COX_RFT); - if (lvlno == 0) { - assert(orient == JPC_TSFB_LL); - return 0; - } else { - switch (orient) { - case JPC_TSFB_LH: - case JPC_TSFB_HL: - return 1; - break; - case JPC_TSFB_HH: - return 2; - break; - } - } - abort(); -} - -/******************************************************************************\ -* Coding pass related functions. -\******************************************************************************/ - -int JPC_SEGTYPE(int passno, int firstpassno, int bypass) -{ - int passtype; - if (bypass) { - passtype = JPC_PASSTYPE(passno); - if (passtype == JPC_CLNPASS) { - return JPC_SEG_MQ; - } - return ((passno < firstpassno + 10) ? JPC_SEG_MQ : JPC_SEG_RAW); - } else { - return JPC_SEG_MQ; - } -} - -int JPC_SEGPASSCNT(int passno, int firstpassno, int numpasses, int bypass, int termall) -{ - int ret; - int passtype; - - if (termall) { - ret = 1; - } else if (bypass) { - if (passno < firstpassno + 10) { - ret = 10 - (passno - firstpassno); - } else { - passtype = JPC_PASSTYPE(passno); - switch (passtype) { - case JPC_SIGPASS: - ret = 2; - break; - case JPC_REFPASS: - ret = 1; - break; - case JPC_CLNPASS: - ret = 1; - break; - default: - ret = -1; - assert(0); - break; - } - } - } else { - ret = JPC_PREC * 3 - 2; - } - ret = JAS_MIN(ret, numpasses - passno); - return ret; -} - -int JPC_ISTERMINATED(int passno, int firstpassno, int numpasses, int termall, - int lazy) -{ - int ret; - int n; - if (passno - firstpassno == numpasses - 1) { - ret = 1; - } else { - n = JPC_SEGPASSCNT(passno, firstpassno, numpasses, lazy, termall); - ret = (n <= 1) ? 1 : 0; - } - - return ret; -} - -/******************************************************************************\ -* Lookup table code. -\******************************************************************************/ - -static void jpc_initmqctxs(void) -{ - jpc_initctxs(jpc_mqctxs); -} - -void jpc_initluts() -{ - int i; - int orient; - int refine; - float u; - float v; - float t; - -/* XXX - hack */ -jpc_initmqctxs(); - - for (orient = 0; orient < 4; ++orient) { - for (i = 0; i < 256; ++i) { - jpc_zcctxnolut[(orient << 8) | i] = jpc_getzcctxno(i, orient); - } - } - - for (i = 0; i < 256; ++i) { - jpc_spblut[i] = jpc_getspb(i << 4); - } - - for (i = 0; i < 256; ++i) { - jpc_scctxnolut[i] = jpc_getscctxno(i << 4); - } - - for (refine = 0; refine < 2; ++refine) { - for (i = 0; i < 2048; ++i) { - jpc_magctxnolut[(refine << 11) + i] = jpc_getmagctxno((refine ? JPC_REFINE : 0) | i); - } - } - - for (i = 0; i < (1 << JPC_NMSEDEC_BITS); ++i) { - t = i * jpc_pow2i(-JPC_NMSEDEC_FRACBITS); - u = t; - v = t - 1.5; - jpc_signmsedec[i] = jpc_dbltofix(floor((u * u - v * v) * jpc_pow2i(JPC_NMSEDEC_FRACBITS) + 0.5) / jpc_pow2i(JPC_NMSEDEC_FRACBITS)); -/* XXX - this calc is not correct */ - jpc_signmsedec0[i] = jpc_dbltofix(floor((u * u) * jpc_pow2i(JPC_NMSEDEC_FRACBITS) + 0.5) / jpc_pow2i(JPC_NMSEDEC_FRACBITS)); - u = t - 1.0; - if (i & (1 << (JPC_NMSEDEC_BITS - 1))) { - v = t - 1.5; - } else { - v = t - 0.5; - } - jpc_refnmsedec[i] = jpc_dbltofix(floor((u * u - v * v) * jpc_pow2i(JPC_NMSEDEC_FRACBITS) + 0.5) / jpc_pow2i(JPC_NMSEDEC_FRACBITS)); -/* XXX - this calc is not correct */ - jpc_refnmsedec0[i] = jpc_dbltofix(floor((u * u) * jpc_pow2i(JPC_NMSEDEC_FRACBITS) + 0.5) / jpc_pow2i(JPC_NMSEDEC_FRACBITS)); - } -} - -jpc_fix_t jpc_getsignmsedec_func(jpc_fix_t x, int bitpos) -{ - jpc_fix_t y; - assert(!(x & (~JAS_ONES(bitpos + 1)))); - y = jpc_getsignmsedec_macro(x, bitpos); - return y; -} - -int jpc_getzcctxno(int f, int orient) -{ - int h; - int v; - int d; - int n; - int t; - int hv; - - /* Avoid compiler warning. */ - n = 0; - - h = ((f & JPC_WSIG) != 0) + ((f & JPC_ESIG) != 0); - v = ((f & JPC_NSIG) != 0) + ((f & JPC_SSIG) != 0); - d = ((f & JPC_NWSIG) != 0) + ((f & JPC_NESIG) != 0) + ((f & JPC_SESIG) != 0) + ((f & JPC_SWSIG) != 0); - switch (orient) { - case JPC_TSFB_HL: - t = h; - h = v; - v = t; - case JPC_TSFB_LL: - case JPC_TSFB_LH: - if (!h) { - if (!v) { - if (!d) { - n = 0; - } else if (d == 1) { - n = 1; - } else { - n = 2; - } - } else if (v == 1) { - n = 3; - } else { - n = 4; - } - } else if (h == 1) { - if (!v) { - if (!d) { - n = 5; - } else { - n = 6; - } - } else { - n = 7; - } - } else { - n = 8; - } - break; - case JPC_TSFB_HH: - hv = h + v; - if (!d) { - if (!hv) { - n = 0; - } else if (hv == 1) { - n = 1; - } else { - n = 2; - } - } else if (d == 1) { - if (!hv) { - n = 3; - } else if (hv == 1) { - n = 4; - } else { - n = 5; - } - } else if (d == 2) { - if (!hv) { - n = 6; - } else { - n = 7; - } - } else { - n = 8; - } - break; - } - assert(n < JPC_NUMZCCTXS); - return JPC_ZCCTXNO + n; -} - -int jpc_getspb(int f) -{ - int hc; - int vc; - int n; - - hc = JAS_MIN(((f & (JPC_ESIG | JPC_ESGN)) == JPC_ESIG) + ((f & (JPC_WSIG | JPC_WSGN)) == JPC_WSIG), 1) - - JAS_MIN(((f & (JPC_ESIG | JPC_ESGN)) == (JPC_ESIG | JPC_ESGN)) + ((f & (JPC_WSIG | JPC_WSGN)) == (JPC_WSIG | JPC_WSGN)), 1); - vc = JAS_MIN(((f & (JPC_NSIG | JPC_NSGN)) == JPC_NSIG) + ((f & (JPC_SSIG | JPC_SSGN)) == JPC_SSIG), 1) - - JAS_MIN(((f & (JPC_NSIG | JPC_NSGN)) == (JPC_NSIG | JPC_NSGN)) + ((f & (JPC_SSIG | JPC_SSGN)) == (JPC_SSIG | JPC_SSGN)), 1); - if (!hc && !vc) { - n = 0; - } else { - n = (!(hc > 0 || (!hc && vc > 0))); - } - return n; -} - -int jpc_getscctxno(int f) -{ - int hc; - int vc; - int n; - - /* Avoid compiler warning. */ - n = 0; - - hc = JAS_MIN(((f & (JPC_ESIG | JPC_ESGN)) == JPC_ESIG) + ((f & (JPC_WSIG | JPC_WSGN)) == JPC_WSIG), - 1) - JAS_MIN(((f & (JPC_ESIG | JPC_ESGN)) == (JPC_ESIG | JPC_ESGN)) + - ((f & (JPC_WSIG | JPC_WSGN)) == (JPC_WSIG | JPC_WSGN)), 1); - vc = JAS_MIN(((f & (JPC_NSIG | JPC_NSGN)) == JPC_NSIG) + ((f & (JPC_SSIG | JPC_SSGN)) == JPC_SSIG), - 1) - JAS_MIN(((f & (JPC_NSIG | JPC_NSGN)) == (JPC_NSIG | JPC_NSGN)) + - ((f & (JPC_SSIG | JPC_SSGN)) == (JPC_SSIG | JPC_SSGN)), 1); - assert(hc >= -1 && hc <= 1 && vc >= -1 && vc <= 1); - if (hc < 0) { - hc = -hc; - vc = -vc; - } - if (!hc) { - if (vc == -1) { - n = 1; - } else if (!vc) { - n = 0; - } else { - n = 1; - } - } else if (hc == 1) { - if (vc == -1) { - n = 2; - } else if (!vc) { - n = 3; - } else { - n = 4; - } - } - assert(n < JPC_NUMSCCTXS); - return JPC_SCCTXNO + n; -} - -int jpc_getmagctxno(int f) -{ - int n; - - if (!(f & JPC_REFINE)) { - n = (f & (JPC_OTHSIGMSK)) ? 1 : 0; - } else { - n = 2; - } - - assert(n < JPC_NUMMAGCTXS); - return JPC_MAGCTXNO + n; -} - -void jpc_initctxs(jpc_mqctx_t *ctxs) -{ - jpc_mqctx_t *ctx; - int i; - - ctx = ctxs; - for (i = 0; i < JPC_NUMCTXS; ++i) { - ctx->mps = 0; - switch (i) { - case JPC_UCTXNO: - ctx->ind = 46; - break; - case JPC_ZCCTXNO: - ctx->ind = 4; - break; - case JPC_AGGCTXNO: - ctx->ind = 3; - break; - default: - ctx->ind = 0; - break; - } - ++ctx; - } -} - -/* Calculate the real quantity exp2(n), where x is an integer. */ -double jpc_pow2i(int n) -{ - double x; - double a; - - x = 1.0; - if (n < 0) { - a = 0.5; - n = -n; - } else { - a = 2.0; - } - while (--n >= 0) { - x *= a; - } - return x; -} diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_t1cod.h b/converter/other/jpeg2000/libjasper/jpc/jpc_t1cod.h deleted file mode 100644 index 3e061d2..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_t1cod.h +++ /dev/null @@ -1,344 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * $Id$ - */ - -#ifndef JPC_T1COD_H -#define JPC_T1COD_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include "jasper/jas_fix.h" -#include "jasper/jas_math.h" - -#include "jpc_mqcod.h" -#include "jpc_tsfb.h" - -/******************************************************************************\ -* Constants. -\******************************************************************************/ - -/* The number of bits used to index into various lookup tables. */ -#define JPC_NMSEDEC_BITS 7 -#define JPC_NMSEDEC_FRACBITS (JPC_NMSEDEC_BITS - 1) - -/* - * Segment types. - */ - -/* Invalid. */ -#define JPC_SEG_INVALID 0 -/* MQ. */ -#define JPC_SEG_MQ 1 -/* Raw. */ -#define JPC_SEG_RAW 2 - -/* The nominal word size. */ -#define JPC_PREC 32 - -/* Tier-1 coding pass types. */ -#define JPC_SIGPASS 0 /* significance */ -#define JPC_REFPASS 1 /* refinement */ -#define JPC_CLNPASS 2 /* cleanup */ - -/* - * Per-sample state information for tier-1 coding. - */ - -/* The northeast neighbour has been found to be significant. */ -#define JPC_NESIG 0x0001 -/* The southeast neighbour has been found to be significant. */ -#define JPC_SESIG 0x0002 -/* The southwest neighbour has been found to be significant. */ -#define JPC_SWSIG 0x0004 -/* The northwest neighbour has been found to be significant. */ -#define JPC_NWSIG 0x0008 -/* The north neighbour has been found to be significant. */ -#define JPC_NSIG 0x0010 -/* The east neighbour has been found to be significant. */ -#define JPC_ESIG 0x0020 -/* The south neighbour has been found to be significant. */ -#define JPC_SSIG 0x0040 -/* The west neighbour has been found to be significant. */ -#define JPC_WSIG 0x0080 -/* The significance mask for 8-connected neighbours. */ -#define JPC_OTHSIGMSK \ - (JPC_NSIG | JPC_NESIG | JPC_ESIG | JPC_SESIG | JPC_SSIG | JPC_SWSIG | JPC_WSIG | JPC_NWSIG) -/* The significance mask for 4-connected neighbours. */ -#define JPC_PRIMSIGMSK (JPC_NSIG | JPC_ESIG | JPC_SSIG | JPC_WSIG) - -/* The north neighbour is negative in value. */ -#define JPC_NSGN 0x0100 -/* The east neighbour is negative in value. */ -#define JPC_ESGN 0x0200 -/* The south neighbour is negative in value. */ -#define JPC_SSGN 0x0400 -/* The west neighbour is negative in value. */ -#define JPC_WSGN 0x0800 -/* The sign mask for 4-connected neighbours. */ -#define JPC_SGNMSK (JPC_NSGN | JPC_ESGN | JPC_SSGN | JPC_WSGN) - -/* This sample has been found to be significant. */ -#define JPC_SIG 0x1000 -/* The sample has been refined. */ -#define JPC_REFINE 0x2000 -/* This sample has been processed during the significance pass. */ -#define JPC_VISIT 0x4000 - -/* The number of aggregation contexts. */ -#define JPC_NUMAGGCTXS 1 -/* The number of zero coding contexts. */ -#define JPC_NUMZCCTXS 9 -/* The number of magnitude contexts. */ -#define JPC_NUMMAGCTXS 3 -/* The number of sign coding contexts. */ -#define JPC_NUMSCCTXS 5 -/* The number of uniform contexts. */ -#define JPC_NUMUCTXS 1 - -/* The context ID for the first aggregation context. */ -#define JPC_AGGCTXNO 0 -/* The context ID for the first zero coding context. */ -#define JPC_ZCCTXNO (JPC_AGGCTXNO + JPC_NUMAGGCTXS) -/* The context ID for the first magnitude context. */ -#define JPC_MAGCTXNO (JPC_ZCCTXNO + JPC_NUMZCCTXS) -/* The context ID for the first sign coding context. */ -#define JPC_SCCTXNO (JPC_MAGCTXNO + JPC_NUMMAGCTXS) -/* The context ID for the first uniform context. */ -#define JPC_UCTXNO (JPC_SCCTXNO + JPC_NUMSCCTXS) -/* The total number of contexts. */ -#define JPC_NUMCTXS (JPC_UCTXNO + JPC_NUMUCTXS) - -/******************************************************************************\ -* External data. -\******************************************************************************/ - -/* These lookup tables are used by various macros/functions. */ -/* Do not access these lookup tables directly. */ -extern int jpc_zcctxnolut[]; -extern int jpc_spblut[]; -extern int jpc_scctxnolut[]; -extern int jpc_magctxnolut[]; -extern jpc_fix_t jpc_refnmsedec[]; -extern jpc_fix_t jpc_signmsedec[]; -extern jpc_fix_t jpc_refnmsedec0[]; -extern jpc_fix_t jpc_signmsedec0[]; - -/* The initial settings for the MQ contexts. */ -extern jpc_mqctx_t jpc_mqctxs[]; - -/******************************************************************************\ -* Functions and macros. -\******************************************************************************/ - -/* Initialize the MQ contexts. */ -void jpc_initctxs(jpc_mqctx_t *ctxs); - -/* Get the zero coding context. */ -int jpc_getzcctxno(int f, int orient); -#define JPC_GETZCCTXNO(f, orient) \ - (jpc_zcctxnolut[((orient) << 8) | ((f) & JPC_OTHSIGMSK)]) - -/* Get the sign prediction bit. */ -int jpc_getspb(int f); -#define JPC_GETSPB(f) \ - (jpc_spblut[((f) & (JPC_PRIMSIGMSK | JPC_SGNMSK)) >> 4]) - -/* Get the sign coding context. */ -int jpc_getscctxno(int f); -#define JPC_GETSCCTXNO(f) \ - (jpc_scctxnolut[((f) & (JPC_PRIMSIGMSK | JPC_SGNMSK)) >> 4]) - -/* Get the magnitude context. */ -int jpc_getmagctxno(int f); -#define JPC_GETMAGCTXNO(f) \ - (jpc_magctxnolut[((f) & JPC_OTHSIGMSK) | ((((f) & JPC_REFINE) != 0) << 11)]) - -/* Get the normalized MSE reduction for significance passes. */ -#define JPC_GETSIGNMSEDEC(x, bitpos) jpc_getsignmsedec_macro(x, bitpos) -jpc_fix_t jpc_getsignmsedec_func(jpc_fix_t x, int bitpos); -#define jpc_getsignmsedec_macro(x, bitpos) \ - ((bitpos > JPC_NMSEDEC_FRACBITS) ? jpc_signmsedec[JPC_ASR(x, bitpos - JPC_NMSEDEC_FRACBITS) & JAS_ONES(JPC_NMSEDEC_BITS)] : \ - (jpc_signmsedec0[JPC_ASR(x, bitpos - JPC_NMSEDEC_FRACBITS) & JAS_ONES(JPC_NMSEDEC_BITS)])) - -/* Get the normalized MSE reduction for refinement passes. */ -#define JPC_GETREFNMSEDEC(x, bitpos) jpc_getrefnmsedec_macro(x, bitpos) -jpc_fix_t jpc_refsignmsedec_func(jpc_fix_t x, int bitpos); -#define jpc_getrefnmsedec_macro(x, bitpos) \ - ((bitpos > JPC_NMSEDEC_FRACBITS) ? jpc_refnmsedec[JPC_ASR(x, bitpos - JPC_NMSEDEC_FRACBITS) & JAS_ONES(JPC_NMSEDEC_BITS)] : \ - (jpc_refnmsedec0[JPC_ASR(x, bitpos - JPC_NMSEDEC_FRACBITS) & JAS_ONES(JPC_NMSEDEC_BITS)])) - -/* Arithmetic shift right (with ability to shift left also). */ -#define JPC_ASR(x, n) \ - (((n) >= 0) ? ((x) >> (n)) : ((x) << (-(n)))) - -/* Update the per-sample state information. */ -#define JPC_UPDATEFLAGS4(fp, rowstep, s, vcausalflag) \ -{ \ - register jpc_fix_t *np = (fp) - (rowstep); \ - register jpc_fix_t *sp = (fp) + (rowstep); \ - if ((vcausalflag)) { \ - sp[-1] |= JPC_NESIG; \ - sp[1] |= JPC_NWSIG; \ - if (s) { \ - *sp |= JPC_NSIG | JPC_NSGN; \ - (fp)[-1] |= JPC_ESIG | JPC_ESGN; \ - (fp)[1] |= JPC_WSIG | JPC_WSGN; \ - } else { \ - *sp |= JPC_NSIG; \ - (fp)[-1] |= JPC_ESIG; \ - (fp)[1] |= JPC_WSIG; \ - } \ - } else { \ - np[-1] |= JPC_SESIG; \ - np[1] |= JPC_SWSIG; \ - sp[-1] |= JPC_NESIG; \ - sp[1] |= JPC_NWSIG; \ - if (s) { \ - *np |= JPC_SSIG | JPC_SSGN; \ - *sp |= JPC_NSIG | JPC_NSGN; \ - (fp)[-1] |= JPC_ESIG | JPC_ESGN; \ - (fp)[1] |= JPC_WSIG | JPC_WSGN; \ - } else { \ - *np |= JPC_SSIG; \ - *sp |= JPC_NSIG; \ - (fp)[-1] |= JPC_ESIG; \ - (fp)[1] |= JPC_WSIG; \ - } \ - } \ -} - -/* Initialize the lookup tables used by the codec. */ -void jpc_initluts(void); - -/* Get the nominal gain associated with a particular band. */ -int JPC_NOMINALGAIN(int qmfbid, int numlvls, int lvlno, int orient); - -/* Get the coding pass type. */ -int JPC_PASSTYPE(int passno); - -/* Get the segment type. */ -int JPC_SEGTYPE(int passno, int firstpassno, int bypass); - -/* Get the number of coding passess in the segment. */ -int JPC_SEGPASSCNT(int passno, int firstpassno, int numpasses, int bypass, - int termall); - -/* Is the coding pass terminated? */ -int JPC_ISTERMINATED(int passno, int firstpassno, int numpasses, int termall, - int lazy); - -#endif diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_t1dec.c b/converter/other/jpeg2000/libjasper/jpc/jpc_t1dec.c deleted file mode 100644 index 01a54ea..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_t1dec.c +++ /dev/null @@ -1,954 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Tier 1 Decoder - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include -#include - -#include "jasper/jas_fix.h" -#include "jasper/jas_stream.h" -#include "jasper/jas_math.h" - -#include "jpc_bs.h" -#include "jpc_mqdec.h" -#include "jpc_t1dec.h" -#include "jpc_t1cod.h" -#include "jpc_dec.h" - -/******************************************************************************\ -* -\******************************************************************************/ - -static int jpc_dec_decodecblk(jpc_dec_t *dec, jpc_dec_tile_t *tile, jpc_dec_tcomp_t *tcomp, jpc_dec_band_t *band, - jpc_dec_cblk_t *cblk, int dopartial, int maxlyrs); -static int dec_sigpass(jpc_dec_t *dec, jpc_mqdec_t *mqdec, int bitpos, int orient, - int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data); -static int dec_rawsigpass(jpc_dec_t *dec, jpc_bitstream_t *in, int bitpos, - int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data); -static int dec_refpass(jpc_dec_t *dec, jpc_mqdec_t *mqdec, int bitpos, int vcausalflag, - jas_matrix_t *flags, jas_matrix_t *data); -static int dec_rawrefpass(jpc_dec_t *dec, jpc_bitstream_t *in, int bitpos, - int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data); -static int dec_clnpass(jpc_dec_t *dec, jpc_mqdec_t *mqdec, int bitpos, int orient, - int vcausalflag, int segsymflag, jas_matrix_t *flags, jas_matrix_t *data); - -#if defined(DEBUG) -static long t1dec_cnt = 0; -#endif - -#if !defined(DEBUG) -#define JPC_T1D_GETBIT(mqdec, v, passtypename, symtypename) \ - ((v) = jpc_mqdec_getbit(mqdec)) -#else -#define JPC_T1D_GETBIT(mqdec, v, passtypename, symtypename) \ -{ \ - (v) = jpc_mqdec_getbit(mqdec); \ - if (jas_getdbglevel() >= 100) { \ - fprintf(stderr, "index = %ld; passtype = %s; symtype = %s; sym = %d\n", t1dec_cnt, passtypename, symtypename, v); \ - ++t1dec_cnt; \ - } \ -} -#endif -#define JPC_T1D_GETBITNOSKEW(mqdec, v, passtypename, symtypename) \ - JPC_T1D_GETBIT(mqdec, v, passtypename, symtypename) - -#if !defined(DEBUG) -#define JPC_T1D_RAWGETBIT(bitstream, v, passtypename, symtypename) \ - ((v) = jpc_bitstream_getbit(bitstream)) -#else -#define JPC_T1D_RAWGETBIT(bitstream, v, passtypename, symtypename) \ -{ \ - (v) = jpc_bitstream_getbit(bitstream); \ - if (jas_getdbglevel() >= 100) { \ - fprintf(stderr, "index = %ld; passtype = %s; symtype = %s; sym = %d\n", t1dec_cnt, passtypename, symtypename, v); \ - ++t1dec_cnt; \ - } \ -} -#endif - -/******************************************************************************\ -* Code. -\******************************************************************************/ - -int jpc_dec_decodecblks(jpc_dec_t *dec, jpc_dec_tile_t *tile) -{ - jpc_dec_tcomp_t *tcomp; - int compcnt; - jpc_dec_rlvl_t *rlvl; - int rlvlcnt; - jpc_dec_band_t *band; - int bandcnt; - jpc_dec_prc_t *prc; - int prccnt; - jpc_dec_cblk_t *cblk; - int cblkcnt; - - for (compcnt = dec->numcomps, tcomp = tile->tcomps; compcnt > 0; - --compcnt, ++tcomp) { - for (rlvlcnt = tcomp->numrlvls, rlvl = tcomp->rlvls; - rlvlcnt > 0; --rlvlcnt, ++rlvl) { - if (!rlvl->bands) { - continue; - } - for (bandcnt = rlvl->numbands, band = rlvl->bands; - bandcnt > 0; --bandcnt, ++band) { - if (!band->data) { - continue; - } - for (prccnt = rlvl->numprcs, prc = band->prcs; - prccnt > 0; --prccnt, ++prc) { - if (!prc->cblks) { - continue; - } - for (cblkcnt = prc->numcblks, - cblk = prc->cblks; cblkcnt > 0; - --cblkcnt, ++cblk) { - if (jpc_dec_decodecblk(dec, tile, tcomp, - band, cblk, 1, JPC_MAXLYRS)) { - return -1; - } - } - } - - } - } - } - - return 0; -} - -static int jpc_dec_decodecblk(jpc_dec_t *dec, jpc_dec_tile_t *tile, jpc_dec_tcomp_t *tcomp, jpc_dec_band_t *band, - jpc_dec_cblk_t *cblk, int dopartial, int maxlyrs) -{ - jpc_dec_seg_t *seg; - int i; - int bpno; - int passtype; - int ret; - int compno; - int filldata; - int fillmask; - jpc_dec_ccp_t *ccp; - - compno = tcomp - tile->tcomps; - - if (!cblk->flags) { - /* Note: matrix is assumed to be zeroed */ - if (!(cblk->flags = jas_matrix_create(jas_matrix_numrows(cblk->data) + - 2, jas_matrix_numcols(cblk->data) + 2))) { - return -1; - } - } - - seg = cblk->segs.head; - while (seg && (seg != cblk->curseg || dopartial) && (maxlyrs < 0 || - seg->lyrno < maxlyrs)) { - assert(seg->numpasses >= seg->maxpasses || dopartial); - assert(seg->stream); - jas_stream_rewind(seg->stream); - jas_stream_setrwcount(seg->stream, 0); - if (seg->type == JPC_SEG_MQ) { - if (!cblk->mqdec) { - if (!(cblk->mqdec = jpc_mqdec_create(JPC_NUMCTXS, 0))) { - return -1; - } - jpc_mqdec_setctxs(cblk->mqdec, JPC_NUMCTXS, jpc_mqctxs); - } - jpc_mqdec_setinput(cblk->mqdec, seg->stream); - jpc_mqdec_init(cblk->mqdec); - } else { - assert(seg->type == JPC_SEG_RAW); - if (!cblk->nulldec) { - if (!(cblk->nulldec = jpc_bitstream_sopen(seg->stream, "r"))) { - assert(0); - } - } - } - - - for (i = 0; i < seg->numpasses; ++i) { - if (cblk->numimsbs > band->numbps) { - ccp = &tile->cp->ccps[compno]; - if (ccp->roishift <= 0) { - fprintf(stderr, "warning: corrupt code stream\n"); - } else { - if (cblk->numimsbs < ccp->roishift - band->numbps) { - fprintf(stderr, "warning: corrupt code stream\n"); - } - } - } - bpno = band->roishift + band->numbps - 1 - (cblk->numimsbs + - (seg->passno + i - cblk->firstpassno + 2) / 3); -if (bpno < 0) { - goto premature_exit; -} -#if 1 - passtype = (seg->passno + i + 2) % 3; -#else - passtype = JPC_PASSTYPE(seg->passno + i + 2); -#endif - assert(bpno >= 0 && bpno < 31); - switch (passtype) { - case JPC_SIGPASS: - ret = (seg->type == JPC_SEG_MQ) ? dec_sigpass(dec, - cblk->mqdec, bpno, band->orient, - (tile->cp->ccps[compno].cblkctx & JPC_COX_VSC) != 0, - cblk->flags, cblk->data) : - dec_rawsigpass(dec, cblk->nulldec, bpno, - (tile->cp->ccps[compno].cblkctx & JPC_COX_VSC) != 0, - cblk->flags, cblk->data); - break; - case JPC_REFPASS: - ret = (seg->type == JPC_SEG_MQ) ? - dec_refpass(dec, cblk->mqdec, bpno, - (tile->cp->ccps[compno].cblkctx & JPC_COX_VSC) != 0, - cblk->flags, cblk->data) : - dec_rawrefpass(dec, cblk->nulldec, bpno, - (tile->cp->ccps[compno].cblkctx & JPC_COX_VSC) != 0, - cblk->flags, cblk->data); - break; - case JPC_CLNPASS: - assert(seg->type == JPC_SEG_MQ); - ret = dec_clnpass(dec, cblk->mqdec, bpno, - band->orient, (tile->cp->ccps[compno].cblkctx & - JPC_COX_VSC) != 0, (tile->cp->ccps[compno].cblkctx & - JPC_COX_SEGSYM) != 0, cblk->flags, - cblk->data); - break; - default: - ret = -1; - break; - } - /* Do we need to reset after each coding pass? */ - if (tile->cp->ccps[compno].cblkctx & JPC_COX_RESET) { - jpc_mqdec_setctxs(cblk->mqdec, JPC_NUMCTXS, jpc_mqctxs); - } - - if (ret) { - fprintf(stderr, "coding pass failed passtype=%d segtype=%d\n", passtype, seg->type); - return -1; - } - - } - - if (seg->type == JPC_SEG_MQ) { -/* Note: dont destroy mq decoder because context info will be lost */ - } else { - assert(seg->type == JPC_SEG_RAW); - if (tile->cp->ccps[compno].cblkctx & JPC_COX_PTERM) { - fillmask = 0x7f; - filldata = 0x2a; - } else { - fillmask = 0; - filldata = 0; - } - if ((ret = jpc_bitstream_inalign(cblk->nulldec, fillmask, - filldata)) < 0) { - return -1; - } else if (ret > 0) { - fprintf(stderr, "warning: bad termination pattern detected\n"); - } - jpc_bitstream_close(cblk->nulldec); - cblk->nulldec = 0; - } - - cblk->curseg = seg->next; - jpc_seglist_remove(&cblk->segs, seg); - jpc_seg_destroy(seg); - seg = cblk->curseg; - } - - assert(dopartial ? (!cblk->curseg) : 1); - -premature_exit: - return 0; -} - -/******************************************************************************\ -* Code for significance pass. -\******************************************************************************/ - -#define jpc_sigpass_step(fp, frowstep, dp, bitpos, oneplushalf, orient, mqdec, vcausalflag) \ -{ \ - int f; \ - int v; \ - f = *(fp); \ - if ((f & JPC_OTHSIGMSK) && !(f & (JPC_SIG | JPC_VISIT))) { \ - jpc_mqdec_setcurctx((mqdec), JPC_GETZCCTXNO(f, (orient))); \ - JPC_T1D_GETBIT((mqdec), v, "SIG", "ZC"); \ - if (v) { \ - jpc_mqdec_setcurctx((mqdec), JPC_GETSCCTXNO(f)); \ - JPC_T1D_GETBIT((mqdec), v, "SIG", "SC"); \ - v ^= JPC_GETSPB(f); \ - JPC_UPDATEFLAGS4((fp), (frowstep), v, (vcausalflag)); \ - *(fp) |= JPC_SIG; \ - *(dp) = (v) ? (-(oneplushalf)) : (oneplushalf); \ - } \ - *(fp) |= JPC_VISIT; \ - } \ -} - -static int dec_sigpass(jpc_dec_t *dec, register jpc_mqdec_t *mqdec, int bitpos, int orient, - int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data) -{ - int i; - int j; - int one; - int half; - int oneplushalf; - int vscanlen; - int width; - int height; - jpc_fix_t *fp; - int frowstep; - int fstripestep; - jpc_fix_t *fstripestart; - jpc_fix_t *fvscanstart; - jpc_fix_t *dp; - int drowstep; - int dstripestep; - jpc_fix_t *dstripestart; - jpc_fix_t *dvscanstart; - int k; - - width = jas_matrix_numcols(data); - height = jas_matrix_numrows(data); - frowstep = jas_matrix_rowstep(flags); - drowstep = jas_matrix_rowstep(data); - fstripestep = frowstep << 2; - dstripestep = drowstep << 2; - - one = 1 << bitpos; - half = one >> 1; - oneplushalf = one | half; - - fstripestart = jas_matrix_getref(flags, 1, 1); - dstripestart = jas_matrix_getref(data, 0, 0); - for (i = height; i > 0; i -= 4, fstripestart += fstripestep, - dstripestart += dstripestep) { - fvscanstart = fstripestart; - dvscanstart = dstripestart; - vscanlen = JAS_MIN(i, 4); - for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { - fp = fvscanstart; - dp = dvscanstart; - k = vscanlen; - - /* Process first sample in vertical scan. */ - jpc_sigpass_step(fp, frowstep, dp, bitpos, oneplushalf, - orient, mqdec, vcausalflag); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - /* Process second sample in vertical scan. */ - jpc_sigpass_step(fp, frowstep, dp, bitpos, oneplushalf, - orient, mqdec, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - /* Process third sample in vertical scan. */ - jpc_sigpass_step(fp, frowstep, dp, bitpos, oneplushalf, - orient, mqdec, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - /* Process fourth sample in vertical scan. */ - jpc_sigpass_step(fp, frowstep, dp, bitpos, oneplushalf, - orient, mqdec, 0); - } - } - return 0; -} - -#define jpc_rawsigpass_step(fp, frowstep, dp, oneplushalf, in, vcausalflag) \ -{ \ - jpc_fix_t f = *(fp); \ - jpc_fix_t v; \ - if ((f & JPC_OTHSIGMSK) && !(f & (JPC_SIG | JPC_VISIT))) { \ - JPC_T1D_RAWGETBIT(in, v, "SIG", "ZC"); \ - if (v < 0) { \ - return -1; \ - } \ - if (v) { \ - JPC_T1D_RAWGETBIT(in, v, "SIG", "SC"); \ - if (v < 0) { \ - return -1; \ - } \ - JPC_UPDATEFLAGS4((fp), (frowstep), v, (vcausalflag)); \ - *(fp) |= JPC_SIG; \ - *(dp) = v ? (-oneplushalf) : (oneplushalf); \ - } \ - *(fp) |= JPC_VISIT; \ - } \ -} - -static int dec_rawsigpass(jpc_dec_t *dec, jpc_bitstream_t *in, int bitpos, int vcausalflag, - jas_matrix_t *flags, jas_matrix_t *data) -{ - int i; - int j; - int k; - int one; - int half; - int oneplushalf; - int vscanlen; - int width; - int height; - jpc_fix_t *fp; - int frowstep; - int fstripestep; - jpc_fix_t *fstripestart; - jpc_fix_t *fvscanstart; - jpc_fix_t *dp; - int drowstep; - int dstripestep; - jpc_fix_t *dstripestart; - jpc_fix_t *dvscanstart; - - width = jas_matrix_numcols(data); - height = jas_matrix_numrows(data); - frowstep = jas_matrix_rowstep(flags); - drowstep = jas_matrix_rowstep(data); - fstripestep = frowstep << 2; - dstripestep = drowstep << 2; - - one = 1 << bitpos; - half = one >> 1; - oneplushalf = one | half; - - fstripestart = jas_matrix_getref(flags, 1, 1); - dstripestart = jas_matrix_getref(data, 0, 0); - for (i = height; i > 0; i -= 4, fstripestart += fstripestep, - dstripestart += dstripestep) { - fvscanstart = fstripestart; - dvscanstart = dstripestart; - vscanlen = JAS_MIN(i, 4); - for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { - fp = fvscanstart; - dp = dvscanstart; - k = vscanlen; - - /* Process first sample in vertical scan. */ - jpc_rawsigpass_step(fp, frowstep, dp, oneplushalf, - in, vcausalflag); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - /* Process second sample in vertical scan. */ - jpc_rawsigpass_step(fp, frowstep, dp, oneplushalf, - in, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - /* Process third sample in vertical scan. */ - jpc_rawsigpass_step(fp, frowstep, dp, oneplushalf, - in, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - /* Process fourth sample in vertical scan. */ - jpc_rawsigpass_step(fp, frowstep, dp, oneplushalf, - in, 0); - - } - } - return 0; -} - -/******************************************************************************\ -* Code for refinement pass. -\******************************************************************************/ - -#define jpc_refpass_step(fp, dp, poshalf, neghalf, mqdec, vcausalflag) \ -{ \ - int v; \ - int t; \ - if (((*(fp)) & (JPC_SIG | JPC_VISIT)) == JPC_SIG) { \ - jpc_mqdec_setcurctx((mqdec), JPC_GETMAGCTXNO(*(fp))); \ - JPC_T1D_GETBITNOSKEW((mqdec), v, "REF", "MR"); \ - t = (v ? (poshalf) : (neghalf)); \ - *(dp) += (*(dp) < 0) ? (-t) : t; \ - *(fp) |= JPC_REFINE; \ - } \ -} - -static int dec_refpass(jpc_dec_t *dec, register jpc_mqdec_t *mqdec, int bitpos, - int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data) -{ - int i; - int j; - int vscanlen; - int width; - int height; - int one; - int poshalf; - int neghalf; - jpc_fix_t *fp; - int frowstep; - int fstripestep; - jpc_fix_t *fstripestart; - jpc_fix_t *fvscanstart; - jpc_fix_t *dp; - int drowstep; - int dstripestep; - jpc_fix_t *dstripestart; - jpc_fix_t *dvscanstart; - int k; - - width = jas_matrix_numcols(data); - height = jas_matrix_numrows(data); - frowstep = jas_matrix_rowstep(flags); - drowstep = jas_matrix_rowstep(data); - fstripestep = frowstep << 2; - dstripestep = drowstep << 2; - - one = 1 << bitpos; - poshalf = one >> 1; - neghalf = (bitpos > 0) ? (-poshalf) : (-1); - - fstripestart = jas_matrix_getref(flags, 1, 1); - dstripestart = jas_matrix_getref(data, 0, 0); - for (i = height; i > 0; i -= 4, fstripestart += fstripestep, - dstripestart += dstripestep) { - fvscanstart = fstripestart; - dvscanstart = dstripestart; - vscanlen = JAS_MIN(i, 4); - for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { - fp = fvscanstart; - dp = dvscanstart; - k = vscanlen; - - /* Process first sample in vertical scan. */ - jpc_refpass_step(fp, dp, poshalf, neghalf, mqdec, - vcausalflag); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - /* Process second sample in vertical scan. */ - jpc_refpass_step(fp, dp, poshalf, neghalf, mqdec, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - /* Process third sample in vertical scan. */ - jpc_refpass_step(fp, dp, poshalf, neghalf, mqdec, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - /* Process fourth sample in vertical scan. */ - jpc_refpass_step(fp, dp, poshalf, neghalf, mqdec, 0); - } - } - - return 0; -} - -#define jpc_rawrefpass_step(fp, dp, poshalf, neghalf, in, vcausalflag) \ -{ \ - jpc_fix_t v; \ - jpc_fix_t t; \ - if (((*(fp)) & (JPC_SIG | JPC_VISIT)) == JPC_SIG) { \ - JPC_T1D_RAWGETBIT(in, v, "REF", "MAGREF"); \ - if (v < 0) { \ - return -1; \ - } \ - t = (v ? poshalf : neghalf); \ - *(dp) += (*(dp) < 0) ? (-t) : t; \ - *(fp) |= JPC_REFINE; \ - } \ -} - -static int dec_rawrefpass(jpc_dec_t *dec, jpc_bitstream_t *in, int bitpos, int vcausalflag, - jas_matrix_t *flags, jas_matrix_t *data) -{ - int i; - int j; - int k; - int vscanlen; - int width; - int height; - int one; - int poshalf; - int neghalf; - jpc_fix_t *fp; - int frowstep; - int fstripestep; - jpc_fix_t *fstripestart; - jpc_fix_t *fvscanstart; - jpc_fix_t *dp; - int drowstep; - int dstripestep; - jpc_fix_t *dstripestart; - jpc_fix_t *dvscanstart; - - width = jas_matrix_numcols(data); - height = jas_matrix_numrows(data); - frowstep = jas_matrix_rowstep(flags); - drowstep = jas_matrix_rowstep(data); - fstripestep = frowstep << 2; - dstripestep = drowstep << 2; - - one = 1 << bitpos; - poshalf = one >> 1; - neghalf = (bitpos > 0) ? (-poshalf) : (-1); - - fstripestart = jas_matrix_getref(flags, 1, 1); - dstripestart = jas_matrix_getref(data, 0, 0); - for (i = height; i > 0; i -= 4, fstripestart += fstripestep, - dstripestart += dstripestep) { - fvscanstart = fstripestart; - dvscanstart = dstripestart; - vscanlen = JAS_MIN(i, 4); - for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { - fp = fvscanstart; - dp = dvscanstart; - k = vscanlen; - - /* Process first sample in vertical scan. */ - jpc_rawrefpass_step(fp, dp, poshalf, neghalf, in, - vcausalflag); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - /* Process second sample in vertical scan. */ - jpc_rawrefpass_step(fp, dp, poshalf, neghalf, in, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - /* Process third sample in vertical scan. */ - jpc_rawrefpass_step(fp, dp, poshalf, neghalf, in, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - /* Process fourth sample in vertical scan. */ - jpc_rawrefpass_step(fp, dp, poshalf, neghalf, in, 0); - } - } - return 0; -} - -/******************************************************************************\ -* Code for cleanup pass. -\******************************************************************************/ - -#define jpc_clnpass_step(f, fp, frowstep, dp, oneplushalf, orient, mqdec, flabel, plabel, vcausalflag) \ -{ \ - int v; \ -flabel \ - if (!((f) & (JPC_SIG | JPC_VISIT))) { \ - jpc_mqdec_setcurctx((mqdec), JPC_GETZCCTXNO((f), (orient))); \ - JPC_T1D_GETBIT((mqdec), v, "CLN", "ZC"); \ - if (v) { \ -plabel \ - /* Coefficient is significant. */ \ - jpc_mqdec_setcurctx((mqdec), JPC_GETSCCTXNO(f)); \ - JPC_T1D_GETBIT((mqdec), v, "CLN", "SC"); \ - v ^= JPC_GETSPB(f); \ - *(dp) = (v) ? (-(oneplushalf)) : (oneplushalf); \ - JPC_UPDATEFLAGS4((fp), (frowstep), v, (vcausalflag)); \ - *(fp) |= JPC_SIG; \ - } \ - } \ - /* XXX - Is this correct? Can aggregation cause some VISIT bits not to be reset? Check. */ \ - *(fp) &= ~JPC_VISIT; \ -} - -static int dec_clnpass(jpc_dec_t *dec, register jpc_mqdec_t *mqdec, int bitpos, int orient, - int vcausalflag, int segsymflag, jas_matrix_t *flags, jas_matrix_t *data) -{ - int i; - int j; - int k; - int vscanlen; - int v; - int half; - int runlen; - int f; - int width; - int height; - int one; - int oneplushalf; - - jpc_fix_t *fp; - int frowstep; - int fstripestep; - jpc_fix_t *fstripestart; - jpc_fix_t *fvscanstart; - - jpc_fix_t *dp; - int drowstep; - int dstripestep; - jpc_fix_t *dstripestart; - jpc_fix_t *dvscanstart; - - one = 1 << bitpos; - half = one >> 1; - oneplushalf = one | half; - - width = jas_matrix_numcols(data); - height = jas_matrix_numrows(data); - - frowstep = jas_matrix_rowstep(flags); - drowstep = jas_matrix_rowstep(data); - fstripestep = frowstep << 2; - dstripestep = drowstep << 2; - - fstripestart = jas_matrix_getref(flags, 1, 1); - dstripestart = jas_matrix_getref(data, 0, 0); - for (i = 0; i < height; i += 4, fstripestart += fstripestep, - dstripestart += dstripestep) { - fvscanstart = fstripestart; - dvscanstart = dstripestart; - vscanlen = JAS_MIN(4, height - i); - for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { - fp = fvscanstart; - if (vscanlen >= 4 && (!((*fp) & (JPC_SIG | JPC_VISIT | - JPC_OTHSIGMSK))) && (fp += frowstep, !((*fp) & (JPC_SIG | - JPC_VISIT | JPC_OTHSIGMSK))) && (fp += frowstep, !((*fp) & - (JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK))) && (fp += frowstep, - !((*fp) & (JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK)))) { - - jpc_mqdec_setcurctx(mqdec, JPC_AGGCTXNO); - JPC_T1D_GETBIT(mqdec, v, "CLN", "AGG"); - if (!v) { - continue; - } - jpc_mqdec_setcurctx(mqdec, JPC_UCTXNO); - JPC_T1D_GETBITNOSKEW(mqdec, v, "CLN", "RL"); - runlen = v; - JPC_T1D_GETBITNOSKEW(mqdec, v, "CLN", "RL"); - runlen = (runlen << 1) | v; - f = *(fp = fvscanstart + frowstep * runlen); - dp = dvscanstart + drowstep * runlen; - k = vscanlen - runlen; - switch (runlen) { - case 0: - goto clnpass_partial0; - break; - case 1: - goto clnpass_partial1; - break; - case 2: - goto clnpass_partial2; - break; - case 3: - goto clnpass_partial3; - break; - } - } else { - f = *(fp = fvscanstart); - dp = dvscanstart; - k = vscanlen; - goto clnpass_full0; - } - - /* Process first sample in vertical scan. */ - jpc_clnpass_step(f, fp, frowstep, dp, oneplushalf, orient, - mqdec, clnpass_full0:, clnpass_partial0:, - vcausalflag); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - /* Process second sample in vertical scan. */ - f = *fp; - jpc_clnpass_step(f, fp, frowstep, dp, oneplushalf, orient, - mqdec, ;, clnpass_partial1:, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - /* Process third sample in vertical scan. */ - f = *fp; - jpc_clnpass_step(f, fp, frowstep, dp, oneplushalf, orient, - mqdec, ;, clnpass_partial2:, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - /* Process fourth sample in vertical scan. */ - f = *fp; - jpc_clnpass_step(f, fp, frowstep, dp, oneplushalf, orient, - mqdec, ;, clnpass_partial3:, 0); - } - } - - if (segsymflag) { - int segsymval; - segsymval = 0; - jpc_mqdec_setcurctx(mqdec, JPC_UCTXNO); - JPC_T1D_GETBITNOSKEW(mqdec, v, "CLN", "SEGSYM"); - segsymval = (segsymval << 1) | (v & 1); - JPC_T1D_GETBITNOSKEW(mqdec, v, "CLN", "SEGSYM"); - segsymval = (segsymval << 1) | (v & 1); - JPC_T1D_GETBITNOSKEW(mqdec, v, "CLN", "SEGSYM"); - segsymval = (segsymval << 1) | (v & 1); - JPC_T1D_GETBITNOSKEW(mqdec, v, "CLN", "SEGSYM"); - segsymval = (segsymval << 1) | (v & 1); - if (segsymval != 0xa) { - fprintf(stderr, "warning: bad segmentation symbol\n"); - } - } - - return 0; -} diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_t1dec.h b/converter/other/jpeg2000/libjasper/jpc/jpc_t1dec.h deleted file mode 100644 index e28a1f5..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_t1dec.h +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Tier 1 Decoder - * - * $Id$ - */ - -#ifndef JPC_T1DEC_H -#define JPC_T1DEC_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include "jpc_dec.h" -#include "jpc_mqdec.h" -#include "jpc_t1cod.h" - -/******************************************************************************\ -* Functions. -\******************************************************************************/ - -/* Decode all of the code blocks for a particular tile. */ -int jpc_dec_decodecblks(jpc_dec_t *dec, jpc_dec_tile_t *tile); - -#endif diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_t1enc.c b/converter/other/jpeg2000/libjasper/jpc/jpc_t1enc.c deleted file mode 100644 index e1af0f6..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_t1enc.c +++ /dev/null @@ -1,1027 +0,0 @@ - /* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Tier 1 Encoder - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include -#include - -#include "jasper/jas_fix.h" -#include "jasper/jas_malloc.h" -#include "jasper/jas_math.h" - -#include "jpc_t1enc.h" -#include "jpc_t1cod.h" -#include "jpc_enc.h" -#include "jpc_cod.h" -#include "jpc_math.h" - -static int jpc_encsigpass(jpc_mqenc_t *mqenc, int bitpos, int orient, int, - jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec); - -static int jpc_encrefpass(jpc_mqenc_t *mqenc, int bitpos, int, jas_matrix_t *flags, - jas_matrix_t *data, int term, long *nmsedec); - -static int jpc_encclnpass(jpc_mqenc_t *mqenc, int bitpos, int orient, int, - int, jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec); - -static int jpc_encrawsigpass(jpc_bitstream_t *out, int bitpos, int, - jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec); - -static int jpc_encrawrefpass(jpc_bitstream_t *out, int bitpos, int, - jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec); - -/******************************************************************************\ -* Code for encoding code blocks. -\******************************************************************************/ - -/* Encode all of the code blocks associated with the current tile. */ -int jpc_enc_enccblks(jpc_enc_t *enc) -{ - jpc_enc_tcmpt_t *tcmpt; - jpc_enc_tcmpt_t *endcomps; - jpc_enc_rlvl_t *lvl; - jpc_enc_rlvl_t *endlvls; - jpc_enc_band_t *band; - jpc_enc_band_t *endbands; - jpc_enc_cblk_t *cblk; - jpc_enc_cblk_t *endcblks; - int i; - int j; - int mx; - int bmx; - int v; - jpc_enc_tile_t *tile; - uint_fast32_t prcno; - jpc_enc_prc_t *prc; - - tile = enc->curtile; - - endcomps = &tile->tcmpts[tile->numtcmpts]; - for (tcmpt = tile->tcmpts; tcmpt != endcomps; ++tcmpt) { - endlvls = &tcmpt->rlvls[tcmpt->numrlvls]; - for (lvl = tcmpt->rlvls; lvl != endlvls; ++lvl) { - if (!lvl->bands) { - continue; - } - endbands = &lvl->bands[lvl->numbands]; - for (band = lvl->bands; band != endbands; ++band) { - if (!band->data) { - continue; - } - for (prcno = 0, prc = band->prcs; prcno < lvl->numprcs; ++prcno, ++prc) { - if (!prc->cblks) { - continue; - } - bmx = 0; - endcblks = &prc->cblks[prc->numcblks]; - for (cblk = prc->cblks; cblk != endcblks; ++cblk) { - mx = 0; - for (i = 0; i < jas_matrix_numrows(cblk->data); ++i) { - for (j = 0; j < jas_matrix_numcols(cblk->data); ++j) { - v = abs(jas_matrix_get(cblk->data, i, j)); - if (v > mx) { - mx = v; - } - } - } - if (mx > bmx) { - bmx = mx; - } - cblk->numbps = JAS_MAX(jpc_firstone(mx) + 1 - JPC_NUMEXTRABITS, 0); - } - - for (cblk = prc->cblks; cblk != endcblks; ++cblk) { - cblk->numimsbs = band->numbps - cblk->numbps; - assert(cblk->numimsbs >= 0); - } - - for (cblk = prc->cblks; cblk != endcblks; ++cblk) { - if (jpc_enc_enccblk(enc, cblk->stream, tcmpt, band, cblk)) { - return -1; - } - } - } - } - } - } - return 0; -} - -static int getthebyte(jas_stream_t *in, long off) -{ - int c; - long oldpos; - oldpos = jas_stream_tell(in); - assert(oldpos >= 0); - jas_stream_seek(in, off, SEEK_SET); - c = jas_stream_peekc(in); - jas_stream_seek(in, oldpos, SEEK_SET); - return c; -} - - - -int -jpc_enc_enccblk(jpc_enc_t *enc, jas_stream_t *out, jpc_enc_tcmpt_t *tcmpt, - jpc_enc_band_t *band, jpc_enc_cblk_t *cblk) { -/*---------------------------------------------------------------------------- - Encode a single code block. ------------------------------------------------------------------------------*/ - jpc_enc_pass_t *pass; - jpc_enc_pass_t *endpasses; - int bitpos; - int n; - int adjust; - int passtype; - int t; - jpc_bitstream_t *bout; - jpc_enc_pass_t *termpass; - int vcausal; - int segsym; - int termmode; - int c; - - bout = 0; - - cblk->stream = jas_stream_memopen(0, 0); - assert(cblk->stream); - cblk->mqenc = jpc_mqenc_create(JPC_NUMCTXS, cblk->stream); - assert(cblk->mqenc); - jpc_mqenc_setctxs(cblk->mqenc, JPC_NUMCTXS, jpc_mqctxs); - - cblk->numpasses = (cblk->numbps > 0) ? (3 * cblk->numbps - 2) : 0; - if (cblk->numpasses > 0) { - cblk->passes = jas_malloc(cblk->numpasses * sizeof(jpc_enc_pass_t)); - assert(cblk->passes); - } else { - cblk->passes = 0; - } - endpasses = &cblk->passes[cblk->numpasses]; - for (pass = cblk->passes; pass != endpasses; ++pass) { - pass->start = 0; - pass->end = 0; - pass->term = - JPC_ISTERMINATED(pass - cblk->passes, 0, - cblk->numpasses, - (tcmpt->cblksty & JPC_COX_TERMALL) != 0, - (tcmpt->cblksty & JPC_COX_LAZY) != 0); - pass->type = JPC_SEGTYPE(pass - cblk->passes, 0, - (tcmpt->cblksty & JPC_COX_LAZY) != 0); - pass->lyrno = -1; - if (pass == endpasses - 1) { - assert(pass->term == 1); - pass->term = 1; - } - } - - cblk->flags = jas_matrix_create(jas_matrix_numrows(cblk->data) + 2, - jas_matrix_numcols(cblk->data) + 2); - assert(cblk->flags); - - - bitpos = cblk->numbps - 1; - pass = cblk->passes; - n = cblk->numpasses; - while (--n >= 0) { - - if (pass->type == JPC_SEG_MQ) { - /* NOP */ - } else { - assert(pass->type == JPC_SEG_RAW); - if (!bout) { - bout = jpc_bitstream_sopen(cblk->stream, "w"); - assert(bout); - } - } - -#if 1 - passtype = (pass - cblk->passes + 2) % 3; -#else - passtype = JPC_PASSTYPE(pass - cblk->passes + 2); -#endif - pass->start = jas_stream_tell(cblk->stream); -#if 0 -assert(jas_stream_tell(cblk->stream) == jas_stream_getrwcount(cblk->stream)); -#endif - assert(bitpos >= 0); - vcausal = (tcmpt->cblksty & JPC_COX_VSC) != 0; - segsym = (tcmpt->cblksty & JPC_COX_SEGSYM) != 0; - if (pass->term) { - termmode = ((tcmpt->cblksty & JPC_COX_PTERM) ? - JPC_MQENC_PTERM : JPC_MQENC_DEFTERM) + 1; - } else { - termmode = 0; - } - switch (passtype) { - case JPC_SIGPASS: - if (pass->type == JPC_SEG_MQ) - jpc_encsigpass(cblk->mqenc, - bitpos, band->orient, vcausal, cblk->flags, - cblk->data, termmode, &pass->nmsedec); - else - jpc_encrawsigpass(bout, bitpos, vcausal, cblk->flags, - cblk->data, termmode, &pass->nmsedec); - break; - case JPC_REFPASS: - if (pass->type == JPC_SEG_MQ) - jpc_encrefpass( - cblk->mqenc, - bitpos, vcausal, cblk->flags, cblk->data, termmode, - &pass->nmsedec); - else - jpc_encrawrefpass(bout, bitpos, - vcausal, cblk->flags, cblk->data, termmode, - &pass->nmsedec); - break; - case JPC_CLNPASS: - assert(pass->type == JPC_SEG_MQ); - jpc_encclnpass( - cblk->mqenc, bitpos, band->orient, - vcausal, segsym, cblk->flags, cblk->data, termmode, - &pass->nmsedec); - break; - default: - assert(false); - break; - } - - if (pass->type == JPC_SEG_MQ) { - if (pass->term) { - jpc_mqenc_init(cblk->mqenc); - } - jpc_mqenc_getstate(cblk->mqenc, &pass->mqencstate); - pass->end = jas_stream_tell(cblk->stream); - if (tcmpt->cblksty & JPC_COX_RESET) { - jpc_mqenc_setctxs(cblk->mqenc, JPC_NUMCTXS, jpc_mqctxs); - } - } else { - if (pass->term) { - if (jpc_bitstream_pending(bout)) { - jpc_bitstream_outalign(bout, 0x2a); - } - jpc_bitstream_close(bout); - bout = 0; - pass->end = jas_stream_tell(cblk->stream); - } else { - pass->end = jas_stream_tell(cblk->stream) + - jpc_bitstream_pending(bout); - /* NOTE - This will not work. need to adjust by # of pending - output bytes - */ - } - } -#if 0 - /* XXX - This assertion fails sometimes when various coding modes are used. - This seems to be harmless, but why does it happen at all? */ - assert(jas_stream_tell(cblk->stream) == - jas_stream_getrwcount(cblk->stream)); -#endif - - pass->wmsedec = jpc_fixtodbl(band->rlvl->tcmpt->synweight) * - jpc_fixtodbl(band->rlvl->tcmpt->synweight) * - jpc_fixtodbl(band->synweight) * - jpc_fixtodbl(band->synweight) * - jpc_fixtodbl(band->absstepsize) * jpc_fixtodbl(band->absstepsize) * - ((double) (1 << bitpos)) * ((double)(1 << bitpos)) * - jpc_fixtodbl(pass->nmsedec); - pass->cumwmsedec = pass->wmsedec; - if (pass != cblk->passes) { - pass->cumwmsedec += pass[-1].cumwmsedec; - } - if (passtype == JPC_CLNPASS) { - --bitpos; - } - ++pass; - } - -#if 0 - dump_passes(cblk->passes, cblk->numpasses, cblk); -#endif - - n = 0; - endpasses = &cblk->passes[cblk->numpasses]; - for (pass = cblk->passes; pass != endpasses; ++pass) { - if (pass->start < n) { - pass->start = n; - } - if (pass->end < n) { - pass->end = n; - } - if (!pass->term) { - termpass = pass; - while (termpass - pass < cblk->numpasses && - !termpass->term) { - ++termpass; - } - if (pass->type == JPC_SEG_MQ) { - t = (pass->mqencstate.lastbyte == 0xff) ? 1 : 0; - if (pass->mqencstate.ctreg >= 5) { - adjust = 4 + t; - } else { - adjust = 5 + t; - } - pass->end += adjust; - } - if (pass->end > termpass->end) { - pass->end = termpass->end; - } - if ((c = getthebyte(cblk->stream, pass->end - 1)) == EOF) { - abort(); - } - if (c == 0xff) { - ++pass->end; - } - n = JAS_MAX(n, pass->end); - } else { - n = JAS_MAX(n, pass->end); - } - } - -#if 0 - dump_passes(cblk->passes, cblk->numpasses, cblk); -#endif - - if (bout) { - jpc_bitstream_close(bout); - } - - return 0; -} - - - -/*****************************************************************************\ -* Code for significance pass. -\*****************************************************************************/ - -#define sigpass_step(fp, frowstep, dp, bitpos, one, nmsedec, orient, mqenc, vcausalflag) \ -{ \ - int f; \ - int v; \ - f = *(fp); \ - if ((f & JPC_OTHSIGMSK) && !(f & (JPC_SIG | JPC_VISIT))) { \ - v = (abs(*(dp)) & (one)) ? 1 : 0; \ - jpc_mqenc_setcurctx(mqenc, JPC_GETZCCTXNO(f, (orient))); \ - jpc_mqenc_putbit(mqenc, v); \ - if (v) { \ - *(nmsedec) += JPC_GETSIGNMSEDEC(abs(*(dp)), (bitpos) + JPC_NUMEXTRABITS); \ - v = ((*(dp) < 0) ? 1 : 0); \ - jpc_mqenc_setcurctx(mqenc, JPC_GETSCCTXNO(f)); \ - jpc_mqenc_putbit(mqenc, v ^ JPC_GETSPB(f)); \ - JPC_UPDATEFLAGS4(fp, frowstep, v, vcausalflag); \ - *(fp) |= JPC_SIG; \ - } \ - *(fp) |= JPC_VISIT; \ - } \ -} - -static int jpc_encsigpass(jpc_mqenc_t *mqenc, int bitpos, int orient, int vcausalflag, - jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec) -{ - int i; - int j; - int one; - int vscanlen; - int width; - int height; - int frowstep; - int drowstep; - int fstripestep; - int dstripestep; - jpc_fix_t *fstripestart; - jpc_fix_t *dstripestart; - jpc_fix_t *fp; - jpc_fix_t *dp; - jpc_fix_t *fvscanstart; - jpc_fix_t *dvscanstart; - int k; - - *nmsedec = 0; - width = jas_matrix_numcols(data); - height = jas_matrix_numrows(data); - frowstep = jas_matrix_rowstep(flags); - drowstep = jas_matrix_rowstep(data); - fstripestep = frowstep << 2; - dstripestep = drowstep << 2; - - one = 1 << (bitpos + JPC_NUMEXTRABITS); - - fstripestart = jas_matrix_getref(flags, 1, 1); - dstripestart = jas_matrix_getref(data, 0, 0); - for (i = height; i > 0; i -= 4, fstripestart += fstripestep, - dstripestart += dstripestep) { - fvscanstart = fstripestart; - dvscanstart = dstripestart; - vscanlen = JAS_MIN(i, 4); - for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { - fp = fvscanstart; - dp = dvscanstart; - k = vscanlen; - - sigpass_step(fp, frowstep, dp, bitpos, one, - nmsedec, orient, mqenc, vcausalflag); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - sigpass_step(fp, frowstep, dp, bitpos, one, - nmsedec, orient, mqenc, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - sigpass_step(fp, frowstep, dp, bitpos, one, - nmsedec, orient, mqenc, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - sigpass_step(fp, frowstep, dp, bitpos, one, - nmsedec, orient, mqenc, 0); - - } - } - - if (term) { - jpc_mqenc_flush(mqenc, term - 1); - } - - return jpc_mqenc_error(mqenc) ? (-1) : 0; -} - -#define rawsigpass_step(fp, frowstep, dp, bitpos, one, nmsedec, out, vcausalflag) \ -{ \ - jpc_fix_t f = *(fp); \ - jpc_fix_t v; \ - if ((f & JPC_OTHSIGMSK) && !(f & (JPC_SIG | JPC_VISIT))) { \ - v = (abs(*(dp)) & (one)) ? 1 : 0; \ - if ((jpc_bitstream_putbit((out), v)) == EOF) { \ - return -1; \ - } \ - if (v) { \ - *(nmsedec) += JPC_GETSIGNMSEDEC(abs(*(dp)), (bitpos) + JPC_NUMEXTRABITS); \ - v = ((*(dp) < 0) ? 1 : 0); \ - if (jpc_bitstream_putbit(out, v) == EOF) { \ - return -1; \ - } \ - JPC_UPDATEFLAGS4(fp, frowstep, v, vcausalflag); \ - *(fp) |= JPC_SIG; \ - } \ - *(fp) |= JPC_VISIT; \ - } \ -} - -static int jpc_encrawsigpass(jpc_bitstream_t *out, int bitpos, int vcausalflag, jas_matrix_t *flags, - jas_matrix_t *data, int term, long *nmsedec) -{ - int i; - int j; - int k; - int one; - int vscanlen; - int width; - int height; - int frowstep; - int drowstep; - int fstripestep; - int dstripestep; - jpc_fix_t *fstripestart; - jpc_fix_t *dstripestart; - jpc_fix_t *fp; - jpc_fix_t *dp; - jpc_fix_t *fvscanstart; - jpc_fix_t *dvscanstart; - - *nmsedec = 0; - width = jas_matrix_numcols(data); - height = jas_matrix_numrows(data); - frowstep = jas_matrix_rowstep(flags); - drowstep = jas_matrix_rowstep(data); - fstripestep = frowstep << 2; - dstripestep = drowstep << 2; - - one = 1 << (bitpos + JPC_NUMEXTRABITS); - - fstripestart = jas_matrix_getref(flags, 1, 1); - dstripestart = jas_matrix_getref(data, 0, 0); - for (i = height; i > 0; i -= 4, fstripestart += fstripestep, - dstripestart += dstripestep) { - fvscanstart = fstripestart; - dvscanstart = dstripestart; - vscanlen = JAS_MIN(i, 4); - for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { - fp = fvscanstart; - dp = dvscanstart; - k = vscanlen; - - rawsigpass_step(fp, frowstep, dp, bitpos, one, - nmsedec, out, vcausalflag); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - rawsigpass_step(fp, frowstep, dp, bitpos, one, - nmsedec, out, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - rawsigpass_step(fp, frowstep, dp, bitpos, one, - nmsedec, out, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - rawsigpass_step(fp, frowstep, dp, bitpos, one, - nmsedec, out, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - - } - } - - if (term) { - jpc_bitstream_outalign(out, 0x2a); - } - - return 0; -} - -/******************************************************************************\ -* Code for refinement pass. -\******************************************************************************/ - -#define refpass_step(fp, dp, bitpos, one, nmsedec, mqenc, vcausalflag) \ -{ \ - int v; \ - if (((*(fp)) & (JPC_SIG | JPC_VISIT)) == JPC_SIG) { \ - (d) = *(dp); \ - *(nmsedec) += JPC_GETREFNMSEDEC(abs(d), (bitpos) + JPC_NUMEXTRABITS); \ - jpc_mqenc_setcurctx((mqenc), JPC_GETMAGCTXNO(*(fp))); \ - v = (abs(d) & (one)) ? 1 : 0; \ - jpc_mqenc_putbit((mqenc), v); \ - *(fp) |= JPC_REFINE; \ - } \ -} - -static int jpc_encrefpass(jpc_mqenc_t *mqenc, int bitpos, int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data, - int term, long *nmsedec) -{ - int i; - int j; - int one; - int vscanlen; - int d; - int width; - int height; - int frowstep; - int drowstep; - int fstripestep; - int dstripestep; - jpc_fix_t *fstripestart; - jpc_fix_t *dstripestart; - jpc_fix_t *fvscanstart; - jpc_fix_t *dvscanstart; - jpc_fix_t *dp; - jpc_fix_t *fp; -int k; - - *nmsedec = 0; - width = jas_matrix_numcols(data); - height = jas_matrix_numrows(data); - frowstep = jas_matrix_rowstep(flags); - drowstep = jas_matrix_rowstep(data); - fstripestep = frowstep << 2; - dstripestep = drowstep << 2; - - one = 1 << (bitpos + JPC_NUMEXTRABITS); - - fstripestart = jas_matrix_getref(flags, 1, 1); - dstripestart = jas_matrix_getref(data, 0, 0); - for (i = height; i > 0; i -= 4, fstripestart += fstripestep, - dstripestart += dstripestep) { - fvscanstart = fstripestart; - dvscanstart = dstripestart; - vscanlen = JAS_MIN(i, 4); - for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { - fp = fvscanstart; - dp = dvscanstart; - k = vscanlen; - - refpass_step(fp, dp, bitpos, one, nmsedec, - mqenc, vcausalflag); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - refpass_step(fp, dp, bitpos, one, nmsedec, - mqenc, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - refpass_step(fp, dp, bitpos, one, nmsedec, - mqenc, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - refpass_step(fp, dp, bitpos, one, nmsedec, - mqenc, 0); - - } - } - - if (term) { - jpc_mqenc_flush(mqenc, term - 1); - } - - return jpc_mqenc_error(mqenc) ? (-1) : 0; -} - -#define rawrefpass_step(fp, dp, bitpos, one, nmsedec, out, vcausalflag) \ -{ \ - jpc_fix_t d; \ - jpc_fix_t v; \ - if (((*(fp)) & (JPC_SIG | JPC_VISIT)) == JPC_SIG) { \ - d = *(dp); \ - *(nmsedec) += JPC_GETREFNMSEDEC(abs(d), (bitpos) + JPC_NUMEXTRABITS); \ - v = (abs(d) & (one)) ? 1 : 0; \ - if (jpc_bitstream_putbit((out), v) == EOF) { \ - return -1; \ - } \ - *(fp) |= JPC_REFINE; \ - } \ -} - -static int jpc_encrawrefpass(jpc_bitstream_t *out, int bitpos, int vcausalflag, jas_matrix_t *flags, - jas_matrix_t *data, int term, long *nmsedec) -{ - int i; - int j; - int k; - int one; - int vscanlen; - int width; - int height; - int frowstep; - int drowstep; - int fstripestep; - int dstripestep; - jpc_fix_t *fstripestart; - jpc_fix_t *dstripestart; - jpc_fix_t *fvscanstart; - jpc_fix_t *dvscanstart; - jpc_fix_t *dp; - jpc_fix_t *fp; - - *nmsedec = 0; - width = jas_matrix_numcols(data); - height = jas_matrix_numrows(data); - frowstep = jas_matrix_rowstep(flags); - drowstep = jas_matrix_rowstep(data); - fstripestep = frowstep << 2; - dstripestep = drowstep << 2; - - one = 1 << (bitpos + JPC_NUMEXTRABITS); - - fstripestart = jas_matrix_getref(flags, 1, 1); - dstripestart = jas_matrix_getref(data, 0, 0); - for (i = height; i > 0; i -= 4, fstripestart += fstripestep, - dstripestart += dstripestep) { - fvscanstart = fstripestart; - dvscanstart = dstripestart; - vscanlen = JAS_MIN(i, 4); - for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { - fp = fvscanstart; - dp = dvscanstart; - k = vscanlen; - - rawrefpass_step(fp, dp, bitpos, one, nmsedec, - out, vcausalflag); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - rawrefpass_step(fp, dp, bitpos, one, nmsedec, - out, vcausalflag); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - rawrefpass_step(fp, dp, bitpos, one, nmsedec, - out, vcausalflag); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - rawrefpass_step(fp, dp, bitpos, one, nmsedec, - out, vcausalflag); - - } - } - - if (term) { - jpc_bitstream_outalign(out, 0x2a); - } - - return 0; -} - -/******************************************************************************\ -* Code for cleanup pass. -\******************************************************************************/ - -#define clnpass_step(fp, frowstep, dp, bitpos, one, orient, nmsedec, mqenc, label1, label2, vcausalflag) \ -{ \ - int f; \ - int v; \ -label1 \ - f = *(fp); \ - if (!(f & (JPC_SIG | JPC_VISIT))) { \ - jpc_mqenc_setcurctx(mqenc, JPC_GETZCCTXNO(f, (orient))); \ - v = (abs(*(dp)) & (one)) ? 1 : 0; \ - jpc_mqenc_putbit((mqenc), v); \ - if (v) { \ -label2 \ - f = *(fp); \ - /* Coefficient is significant. */ \ - *(nmsedec) += JPC_GETSIGNMSEDEC(abs(*(dp)), (bitpos) + JPC_NUMEXTRABITS); \ - jpc_mqenc_setcurctx((mqenc), JPC_GETSCCTXNO(f)); \ - v = ((*(dp) < 0) ? 1 : 0); \ - jpc_mqenc_putbit((mqenc), v ^ JPC_GETSPB(f)); \ - JPC_UPDATEFLAGS4((fp), (frowstep), v, vcausalflag); \ - *(fp) |= JPC_SIG; \ - } \ - } \ - *(fp) &= ~JPC_VISIT; \ -} - -static int jpc_encclnpass(jpc_mqenc_t *mqenc, int bitpos, int orient, int vcausalflag, int segsymflag, jas_matrix_t *flags, - jas_matrix_t *data, int term, long *nmsedec) -{ - int i; - int j; - int k; - int vscanlen; - int v; - int runlen; - jpc_fix_t *fp; - int width; - int height; - jpc_fix_t *dp; - int one; - int frowstep; - int drowstep; - int fstripestep; - int dstripestep; - jpc_fix_t *fstripestart; - jpc_fix_t *dstripestart; - jpc_fix_t *fvscanstart; - jpc_fix_t *dvscanstart; - - *nmsedec = 0; - width = jas_matrix_numcols(data); - height = jas_matrix_numrows(data); - frowstep = jas_matrix_rowstep(flags); - drowstep = jas_matrix_rowstep(data); - fstripestep = frowstep << 2; - dstripestep = drowstep << 2; - - one = 1 << (bitpos + JPC_NUMEXTRABITS); - - fstripestart = jas_matrix_getref(flags, 1, 1); - dstripestart = jas_matrix_getref(data, 0, 0); - for (i = height; i > 0; i -= 4, fstripestart += fstripestep, - dstripestart += dstripestep) { - fvscanstart = fstripestart; - dvscanstart = dstripestart; - vscanlen = JAS_MIN(i, 4); - for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { - - fp = fvscanstart; - if (vscanlen >= 4 && !((*fp) & (JPC_SIG | JPC_VISIT | - JPC_OTHSIGMSK)) && (fp += frowstep, !((*fp) & (JPC_SIG | - JPC_VISIT | JPC_OTHSIGMSK))) && (fp += frowstep, !((*fp) & - (JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK))) && (fp += frowstep, - !((*fp) & (JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK)))) { - dp = dvscanstart; - for (k = 0; k < vscanlen; ++k) { - v = (abs(*dp) & one) ? 1 : 0; - if (v) { - break; - } - dp += drowstep; - } - runlen = k; - if (runlen >= 4) { - jpc_mqenc_setcurctx(mqenc, JPC_AGGCTXNO); - jpc_mqenc_putbit(mqenc, 0); - continue; - } - jpc_mqenc_setcurctx(mqenc, JPC_AGGCTXNO); - jpc_mqenc_putbit(mqenc, 1); - jpc_mqenc_setcurctx(mqenc, JPC_UCTXNO); - jpc_mqenc_putbit(mqenc, runlen >> 1); - jpc_mqenc_putbit(mqenc, runlen & 1); - fp = fvscanstart + frowstep * runlen; - dp = dvscanstart + drowstep * runlen; - k = vscanlen - runlen; - switch (runlen) { - case 0: - goto clnpass_partial0; - break; - case 1: - goto clnpass_partial1; - break; - case 2: - goto clnpass_partial2; - break; - case 3: - goto clnpass_partial3; - break; - } - } else { - runlen = 0; - fp = fvscanstart; - dp = dvscanstart; - k = vscanlen; - goto clnpass_full0; - } - clnpass_step(fp, frowstep, dp, bitpos, one, - orient, nmsedec, mqenc, clnpass_full0:, clnpass_partial0:, vcausalflag); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - clnpass_step(fp, frowstep, dp, bitpos, one, - orient, nmsedec, mqenc, ;, clnpass_partial1:, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - clnpass_step(fp, frowstep, dp, bitpos, one, - orient, nmsedec, mqenc, ;, clnpass_partial2:, 0); - if (--k <= 0) { - continue; - } - fp += frowstep; - dp += drowstep; - clnpass_step(fp, frowstep, dp, bitpos, one, - orient, nmsedec, mqenc, ;, clnpass_partial3:, 0); - } - } - - if (segsymflag) { - jpc_mqenc_setcurctx(mqenc, JPC_UCTXNO); - jpc_mqenc_putbit(mqenc, 1); - jpc_mqenc_putbit(mqenc, 0); - jpc_mqenc_putbit(mqenc, 1); - jpc_mqenc_putbit(mqenc, 0); - } - - if (term) { - jpc_mqenc_flush(mqenc, term - 1); - } - - return jpc_mqenc_error(mqenc) ? (-1) : 0; -} diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_t1enc.h b/converter/other/jpeg2000/libjasper/jpc/jpc_t1enc.h deleted file mode 100644 index 9ce5ed2..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_t1enc.h +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Tier 1 Encoder - * - * $Id$ - */ - -#ifndef JPC_T1ENC_H -#define JPC_T1ENC_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include "jasper/jas_seq.h" - -#include "jpc_enc.h" -#include "jpc_t1cod.h" - -/******************************************************************************\ -* Functions. -\******************************************************************************/ - -/* Encode all of the code blocks. */ -int jpc_enc_enccblks(jpc_enc_t *enc); - -/* Encode a single code block. */ -int jpc_enc_enccblk(jpc_enc_t *enc, jas_stream_t *out, jpc_enc_tcmpt_t *comp, - jpc_enc_band_t *band, jpc_enc_cblk_t *cblk); - -#endif diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_t2cod.c b/converter/other/jpeg2000/libjasper/jpc/jpc_t2cod.c deleted file mode 100644 index a9ca0dc..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_t2cod.c +++ /dev/null @@ -1,733 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Tier-2 Coding Library - * - * $Id$ - */ - -#include "jasper/jas_math.h" -#include "jasper/jas_malloc.h" -#include "jasper/jas_math.h" - -#include "jpc_cs.h" -#include "jpc_t2cod.h" -#include "jpc_math.h" - -static int jpc_pi_nextlrcp(jpc_pi_t *pi); -static int jpc_pi_nextrlcp(jpc_pi_t *pi); -static int jpc_pi_nextrpcl(jpc_pi_t *pi); -static int jpc_pi_nextpcrl(jpc_pi_t *pi); -static int jpc_pi_nextcprl(jpc_pi_t *pi); - -int jpc_pi_next(jpc_pi_t *pi) -{ - jpc_pchg_t *pchg; - int ret; - - - for (;;) { - - pi->valid = false; - - if (!pi->pchg) { - ++pi->pchgno; - pi->compno = 0; - pi->rlvlno = 0; - pi->prcno = 0; - pi->lyrno = 0; - pi->prgvolfirst = true; - if (pi->pchgno < jpc_pchglist_numpchgs(pi->pchglist)) { - pi->pchg = jpc_pchglist_get(pi->pchglist, pi->pchgno); - } else if (pi->pchgno == jpc_pchglist_numpchgs(pi->pchglist)) { - pi->pchg = &pi->defaultpchg; - } else { - return 1; - } - } - - pchg = pi->pchg; - switch (pchg->prgord) { - case JPC_COD_LRCPPRG: - ret = jpc_pi_nextlrcp(pi); - break; - case JPC_COD_RLCPPRG: - ret = jpc_pi_nextrlcp(pi); - break; - case JPC_COD_RPCLPRG: - ret = jpc_pi_nextrpcl(pi); - break; - case JPC_COD_PCRLPRG: - ret = jpc_pi_nextpcrl(pi); - break; - case JPC_COD_CPRLPRG: - ret = jpc_pi_nextcprl(pi); - break; - default: - ret = -1; - break; - } - if (!ret) { - pi->valid = true; - ++pi->pktno; - return 0; - } - pi->pchg = 0; - } -} - -static int jpc_pi_nextlrcp(register jpc_pi_t *pi) -{ - jpc_pchg_t *pchg; - int *prclyrno; - - pchg = pi->pchg; - if (!pi->prgvolfirst) { - prclyrno = &pi->pirlvl->prclyrnos[pi->prcno]; - goto skip; - } else { - pi->prgvolfirst = false; - } - - for (pi->lyrno = 0; pi->lyrno < pi->numlyrs && pi->lyrno < - pchg->lyrnoend; ++pi->lyrno) { - for (pi->rlvlno = pchg->rlvlnostart; pi->rlvlno < pi->maxrlvls && - pi->rlvlno < pchg->rlvlnoend; ++pi->rlvlno) { - for (pi->compno = pchg->compnostart, pi->picomp = - &pi->picomps[pi->compno]; pi->compno < pi->numcomps - && pi->compno < pchg->compnoend; ++pi->compno, - ++pi->picomp) { - if (pi->rlvlno >= pi->picomp->numrlvls) { - continue; - } - pi->pirlvl = &pi->picomp->pirlvls[pi->rlvlno]; - for (pi->prcno = 0, prclyrno = - pi->pirlvl->prclyrnos; pi->prcno < - pi->pirlvl->numprcs; ++pi->prcno, - ++prclyrno) { - if (pi->lyrno >= *prclyrno) { - *prclyrno = pi->lyrno; - ++(*prclyrno); - return 0; - } -skip: - ; - } - } - } - } - return 1; -} - -static int jpc_pi_nextrlcp(register jpc_pi_t *pi) -{ - jpc_pchg_t *pchg; - int *prclyrno; - - pchg = pi->pchg; - if (!pi->prgvolfirst) { - assert(pi->prcno < pi->pirlvl->numprcs); - prclyrno = &pi->pirlvl->prclyrnos[pi->prcno]; - goto skip; - } else { - pi->prgvolfirst = 0; - } - - for (pi->rlvlno = pchg->rlvlnostart; pi->rlvlno < pi->maxrlvls && - pi->rlvlno < pchg->rlvlnoend; ++pi->rlvlno) { - for (pi->lyrno = 0; pi->lyrno < pi->numlyrs && pi->lyrno < - pchg->lyrnoend; ++pi->lyrno) { - for (pi->compno = pchg->compnostart, pi->picomp = - &pi->picomps[pi->compno]; pi->compno < pi->numcomps && - pi->compno < pchg->compnoend; ++pi->compno, ++pi->picomp) { - if (pi->rlvlno >= pi->picomp->numrlvls) { - continue; - } - pi->pirlvl = &pi->picomp->pirlvls[pi->rlvlno]; - for (pi->prcno = 0, prclyrno = pi->pirlvl->prclyrnos; - pi->prcno < pi->pirlvl->numprcs; ++pi->prcno, ++prclyrno) { - if (pi->lyrno >= *prclyrno) { - *prclyrno = pi->lyrno; - ++(*prclyrno); - return 0; - } -skip: - ; - } - } - } - } - return 1; -} - -static int jpc_pi_nextrpcl(register jpc_pi_t *pi) -{ - int rlvlno; - jpc_pirlvl_t *pirlvl; - jpc_pchg_t *pchg; - int prchind; - int prcvind; - int *prclyrno; - int compno; - jpc_picomp_t *picomp; - int xstep; - int ystep; - uint_fast32_t r; - uint_fast32_t rpx; - uint_fast32_t rpy; - uint_fast32_t trx0; - uint_fast32_t try0; - - pchg = pi->pchg; - if (!pi->prgvolfirst) { - goto skip; - } else { - pi->xstep = 0; - pi->ystep = 0; - for (compno = 0, picomp = pi->picomps; compno < pi->numcomps; - ++compno, ++picomp) { - for (rlvlno = 0, pirlvl = picomp->pirlvls; rlvlno < - picomp->numrlvls; ++rlvlno, ++pirlvl) { - xstep = picomp->hsamp * (1 << (pirlvl->prcwidthexpn + - picomp->numrlvls - rlvlno - 1)); - ystep = picomp->vsamp * (1 << (pirlvl->prcheightexpn + - picomp->numrlvls - rlvlno - 1)); - pi->xstep = (!pi->xstep) ? xstep : JAS_MIN(pi->xstep, xstep); - pi->ystep = (!pi->ystep) ? ystep : JAS_MIN(pi->ystep, ystep); - } - } - pi->prgvolfirst = 0; - } - - for (pi->rlvlno = pchg->rlvlnostart; pi->rlvlno < pchg->rlvlnoend && - pi->rlvlno < pi->maxrlvls; ++pi->rlvlno) { - for (pi->y = pi->ystart; pi->y < pi->yend; pi->y += - pi->ystep - (pi->y % pi->ystep)) { - for (pi->x = pi->xstart; pi->x < pi->xend; pi->x += - pi->xstep - (pi->x % pi->xstep)) { - for (pi->compno = pchg->compnostart, - pi->picomp = &pi->picomps[pi->compno]; - pi->compno < pchg->compnoend && pi->compno < - pi->numcomps; ++pi->compno, ++pi->picomp) { - if (pi->rlvlno >= pi->picomp->numrlvls) { - continue; - } - pi->pirlvl = &pi->picomp->pirlvls[pi->rlvlno]; - if (pi->pirlvl->numprcs == 0) { - continue; - } - r = pi->picomp->numrlvls - 1 - pi->rlvlno; - rpx = r + pi->pirlvl->prcwidthexpn; - rpy = r + pi->pirlvl->prcheightexpn; - trx0 = JPC_CEILDIV(pi->xstart, pi->picomp->hsamp << r); - try0 = JPC_CEILDIV(pi->ystart, pi->picomp->vsamp << r); - if (((pi->x == pi->xstart && ((trx0 << r) % (1 << rpx))) - || !(pi->x % (1 << rpx))) && - ((pi->y == pi->ystart && ((try0 << r) % (1 << rpy))) - || !(pi->y % (1 << rpy)))) { - prchind = JPC_FLOORDIVPOW2(JPC_CEILDIV(pi->x, pi->picomp->hsamp - << r), pi->pirlvl->prcwidthexpn) - JPC_FLOORDIVPOW2(trx0, - pi->pirlvl->prcwidthexpn); - prcvind = JPC_FLOORDIVPOW2(JPC_CEILDIV(pi->y, pi->picomp->vsamp - << r), pi->pirlvl->prcheightexpn) - JPC_FLOORDIVPOW2(try0, - pi->pirlvl->prcheightexpn); - pi->prcno = prcvind * pi->pirlvl->numhprcs + prchind; - - assert(pi->prcno < pi->pirlvl->numprcs); - for (pi->lyrno = 0; pi->lyrno < - pi->numlyrs && pi->lyrno < pchg->lyrnoend; ++pi->lyrno) { - prclyrno = &pi->pirlvl->prclyrnos[pi->prcno]; - if (pi->lyrno >= *prclyrno) { - ++(*prclyrno); - return 0; - } -skip: - ; - } - } - } - } - } - } - return 1; -} - -static int jpc_pi_nextpcrl(register jpc_pi_t *pi) -{ - int rlvlno; - jpc_pirlvl_t *pirlvl; - jpc_pchg_t *pchg; - int prchind; - int prcvind; - int *prclyrno; - int compno; - jpc_picomp_t *picomp; - int xstep; - int ystep; - uint_fast32_t trx0; - uint_fast32_t try0; - uint_fast32_t r; - uint_fast32_t rpx; - uint_fast32_t rpy; - - pchg = pi->pchg; - if (!pi->prgvolfirst) { - goto skip; - } else { - pi->xstep = 0; - pi->ystep = 0; - for (compno = 0, picomp = pi->picomps; compno < pi->numcomps; - ++compno, ++picomp) { - for (rlvlno = 0, pirlvl = picomp->pirlvls; rlvlno < - picomp->numrlvls; ++rlvlno, ++pirlvl) { - xstep = picomp->hsamp * (1 << - (pirlvl->prcwidthexpn + picomp->numrlvls - - rlvlno - 1)); - ystep = picomp->vsamp * (1 << - (pirlvl->prcheightexpn + picomp->numrlvls - - rlvlno - 1)); - pi->xstep = (!pi->xstep) ? xstep : - JAS_MIN(pi->xstep, xstep); - pi->ystep = (!pi->ystep) ? ystep : - JAS_MIN(pi->ystep, ystep); - } - } - pi->prgvolfirst = 0; - } - - for (pi->y = pi->ystart; pi->y < pi->yend; pi->y += pi->ystep - - (pi->y % pi->ystep)) { - for (pi->x = pi->xstart; pi->x < pi->xend; pi->x += pi->xstep - - (pi->x % pi->xstep)) { - for (pi->compno = pchg->compnostart, pi->picomp = - &pi->picomps[pi->compno]; pi->compno < pi->numcomps - && pi->compno < pchg->compnoend; ++pi->compno, - ++pi->picomp) { - for (pi->rlvlno = pchg->rlvlnostart, - pi->pirlvl = &pi->picomp->pirlvls[pi->rlvlno]; - pi->rlvlno < pi->picomp->numrlvls && - pi->rlvlno < pchg->rlvlnoend; ++pi->rlvlno, - ++pi->pirlvl) { - if (pi->pirlvl->numprcs == 0) { - continue; - } - r = pi->picomp->numrlvls - 1 - pi->rlvlno; - trx0 = JPC_CEILDIV(pi->xstart, pi->picomp->hsamp << r); - try0 = JPC_CEILDIV(pi->ystart, pi->picomp->vsamp << r); - rpx = r + pi->pirlvl->prcwidthexpn; - rpy = r + pi->pirlvl->prcheightexpn; - if (((pi->x == pi->xstart && ((trx0 << r) % (1 << rpx))) || - !(pi->x % (pi->picomp->hsamp << rpx))) && - ((pi->y == pi->ystart && ((try0 << r) % (1 << rpy))) || - !(pi->y % (pi->picomp->vsamp << rpy)))) { - prchind = JPC_FLOORDIVPOW2(JPC_CEILDIV(pi->x, pi->picomp->hsamp - << r), pi->pirlvl->prcwidthexpn) - JPC_FLOORDIVPOW2(trx0, - pi->pirlvl->prcwidthexpn); - prcvind = JPC_FLOORDIVPOW2(JPC_CEILDIV(pi->y, pi->picomp->vsamp - << r), pi->pirlvl->prcheightexpn) - JPC_FLOORDIVPOW2(try0, - pi->pirlvl->prcheightexpn); - pi->prcno = prcvind * pi->pirlvl->numhprcs + prchind; - assert(pi->prcno < pi->pirlvl->numprcs); - for (pi->lyrno = 0; pi->lyrno < pi->numlyrs && - pi->lyrno < pchg->lyrnoend; ++pi->lyrno) { - prclyrno = &pi->pirlvl->prclyrnos[pi->prcno]; - if (pi->lyrno >= *prclyrno) { - ++(*prclyrno); - return 0; - } -skip: - ; - } - } - } - } - } - } - return 1; -} - -static int jpc_pi_nextcprl(register jpc_pi_t *pi) -{ - int rlvlno; - jpc_pirlvl_t *pirlvl; - jpc_pchg_t *pchg; - int prchind; - int prcvind; - int *prclyrno; - uint_fast32_t trx0; - uint_fast32_t try0; - uint_fast32_t r; - uint_fast32_t rpx; - uint_fast32_t rpy; - - pchg = pi->pchg; - if (!pi->prgvolfirst) { - goto skip; - } else { - pi->prgvolfirst = 0; - } - - for (pi->compno = pchg->compnostart, pi->picomp = - &pi->picomps[pi->compno]; pi->compno < pchg->compnoend; ++pi->compno, - ++pi->picomp) { - pirlvl = pi->picomp->pirlvls; - pi->xstep = pi->picomp->hsamp * (1 << (pirlvl->prcwidthexpn + - pi->picomp->numrlvls - 1)); - pi->ystep = pi->picomp->vsamp * (1 << (pirlvl->prcheightexpn + - pi->picomp->numrlvls - 1)); - for (rlvlno = 1, pirlvl = &pi->picomp->pirlvls[1]; - rlvlno < pi->picomp->numrlvls; ++rlvlno, ++pirlvl) { - pi->xstep = JAS_MIN(pi->xstep, pi->picomp->hsamp * (1 << - (pirlvl->prcwidthexpn + pi->picomp->numrlvls - - rlvlno - 1))); - pi->ystep = JAS_MIN(pi->ystep, pi->picomp->vsamp * (1 << - (pirlvl->prcheightexpn + pi->picomp->numrlvls - - rlvlno - 1))); - } - for (pi->y = pi->ystart; pi->y < pi->yend; - pi->y += pi->ystep - (pi->y % pi->ystep)) { - for (pi->x = pi->xstart; pi->x < pi->xend; - pi->x += pi->xstep - (pi->x % pi->xstep)) { - for (pi->rlvlno = pchg->rlvlnostart, - pi->pirlvl = &pi->picomp->pirlvls[pi->rlvlno]; - pi->rlvlno < pi->picomp->numrlvls && pi->rlvlno < - pchg->rlvlnoend; ++pi->rlvlno, ++pi->pirlvl) { - if (pi->pirlvl->numprcs == 0) { - continue; - } - r = pi->picomp->numrlvls - 1 - pi->rlvlno; - trx0 = JPC_CEILDIV(pi->xstart, pi->picomp->hsamp << r); - try0 = JPC_CEILDIV(pi->ystart, pi->picomp->vsamp << r); - rpx = r + pi->pirlvl->prcwidthexpn; - rpy = r + pi->pirlvl->prcheightexpn; - if (((pi->x == pi->xstart && ((trx0 << r) % (1 << rpx))) || - !(pi->x % (pi->picomp->hsamp << rpx))) && - ((pi->y == pi->ystart && ((try0 << r) % (1 << rpy))) || - !(pi->y % (pi->picomp->vsamp << rpy)))) { - prchind = JPC_FLOORDIVPOW2(JPC_CEILDIV(pi->x, pi->picomp->hsamp - << r), pi->pirlvl->prcwidthexpn) - JPC_FLOORDIVPOW2(trx0, - pi->pirlvl->prcwidthexpn); - prcvind = JPC_FLOORDIVPOW2(JPC_CEILDIV(pi->y, pi->picomp->vsamp - << r), pi->pirlvl->prcheightexpn) - JPC_FLOORDIVPOW2(try0, - pi->pirlvl->prcheightexpn); - pi->prcno = prcvind * - pi->pirlvl->numhprcs + - prchind; - assert(pi->prcno < - pi->pirlvl->numprcs); - for (pi->lyrno = 0; pi->lyrno < - pi->numlyrs && pi->lyrno < pchg->lyrnoend; ++pi->lyrno) { - prclyrno = &pi->pirlvl->prclyrnos[pi->prcno]; - if (pi->lyrno >= *prclyrno) { - ++(*prclyrno); - return 0; - } -skip: - ; - } - } - } - } - } - } - return 1; -} - -static void pirlvl_destroy(jpc_pirlvl_t *rlvl) -{ - if (rlvl->prclyrnos) { - jas_free(rlvl->prclyrnos); - } -} - -static void jpc_picomp_destroy(jpc_picomp_t *picomp) -{ - int rlvlno; - jpc_pirlvl_t *pirlvl; - if (picomp->pirlvls) { - for (rlvlno = 0, pirlvl = picomp->pirlvls; rlvlno < - picomp->numrlvls; ++rlvlno, ++pirlvl) { - pirlvl_destroy(pirlvl); - } - jas_free(picomp->pirlvls); - } -} - -void jpc_pi_destroy(jpc_pi_t *pi) -{ - jpc_picomp_t *picomp; - int compno; - if (pi->picomps) { - for (compno = 0, picomp = pi->picomps; compno < pi->numcomps; - ++compno, ++picomp) { - jpc_picomp_destroy(picomp); - } - jas_free(pi->picomps); - } - if (pi->pchglist) { - jpc_pchglist_destroy(pi->pchglist); - } - jas_free(pi); -} - -jpc_pi_t *jpc_pi_create0(void) -{ - jpc_pi_t *pi; - if (!(pi = jas_malloc(sizeof(jpc_pi_t)))) { - return 0; - } - pi->picomps = 0; - pi->pchgno = 0; - if (!(pi->pchglist = jpc_pchglist_create())) { - jas_free(pi); - return 0; - } - return pi; -} - -int jpc_pi_addpchg(jpc_pi_t *pi, jpc_pocpchg_t *pchg) -{ - return jpc_pchglist_insert(pi->pchglist, -1, pchg); -} - -jpc_pchglist_t *jpc_pchglist_create(void) -{ - jpc_pchglist_t *pchglist; - if (!(pchglist = jas_malloc(sizeof(jpc_pchglist_t)))) { - return 0; - } - pchglist->numpchgs = 0; - pchglist->maxpchgs = 0; - pchglist->pchgs = 0; - return pchglist; -} - -int jpc_pchglist_insert(jpc_pchglist_t *pchglist, int pchgno, jpc_pchg_t *pchg) -{ - int i; - int newmaxpchgs; - jpc_pchg_t **newpchgs; - if (pchgno < 0) { - pchgno = pchglist->numpchgs; - } - if (pchglist->numpchgs >= pchglist->maxpchgs) { - newmaxpchgs = pchglist->maxpchgs + 128; - if (!(newpchgs = jas_realloc(pchglist->pchgs, newmaxpchgs * sizeof(jpc_pchg_t *)))) { - return -1; - } - pchglist->maxpchgs = newmaxpchgs; - pchglist->pchgs = newpchgs; - } - for (i = pchglist->numpchgs; i > pchgno; --i) { - pchglist->pchgs[i] = pchglist->pchgs[i - 1]; - } - pchglist->pchgs[pchgno] = pchg; - ++pchglist->numpchgs; - return 0; -} - -jpc_pchg_t *jpc_pchglist_remove(jpc_pchglist_t *pchglist, int pchgno) -{ - int i; - jpc_pchg_t *pchg; - assert(pchgno < pchglist->numpchgs); - pchg = pchglist->pchgs[pchgno]; - for (i = pchgno + 1; i < pchglist->numpchgs; ++i) { - pchglist->pchgs[i - 1] = pchglist->pchgs[i]; - } - --pchglist->numpchgs; - return pchg; -} - -jpc_pchg_t *jpc_pchg_copy(jpc_pchg_t *pchg) -{ - jpc_pchg_t *newpchg; - if (!(newpchg = jas_malloc(sizeof(jpc_pchg_t)))) { - return 0; - } - *newpchg = *pchg; - return newpchg; -} - -jpc_pchglist_t *jpc_pchglist_copy(jpc_pchglist_t *pchglist) -{ - jpc_pchglist_t *newpchglist; - jpc_pchg_t *newpchg; - int pchgno; - if (!(newpchglist = jpc_pchglist_create())) { - return 0; - } - for (pchgno = 0; pchgno < pchglist->numpchgs; ++pchgno) { - if (!(newpchg = jpc_pchg_copy(pchglist->pchgs[pchgno])) || - jpc_pchglist_insert(newpchglist, -1, newpchg)) { - jpc_pchglist_destroy(newpchglist); - return 0; - } - } - return newpchglist; -} - -void jpc_pchglist_destroy(jpc_pchglist_t *pchglist) -{ - int pchgno; - if (pchglist->pchgs) { - for (pchgno = 0; pchgno < pchglist->numpchgs; ++pchgno) { - jpc_pchg_destroy(pchglist->pchgs[pchgno]); - } - jas_free(pchglist->pchgs); - } - jas_free(pchglist); -} - -void jpc_pchg_destroy(jpc_pchg_t *pchg) -{ - jas_free(pchg); -} - -jpc_pchg_t *jpc_pchglist_get(jpc_pchglist_t *pchglist, int pchgno) -{ - return pchglist->pchgs[pchgno]; -} - -int jpc_pchglist_numpchgs(jpc_pchglist_t *pchglist) -{ - return pchglist->numpchgs; -} - -int jpc_pi_init(jpc_pi_t *pi) -{ - int compno; - int rlvlno; - int prcno; - jpc_picomp_t *picomp; - jpc_pirlvl_t *pirlvl; - int *prclyrno; - - pi->prgvolfirst = 0; - pi->valid = 0; - pi->pktno = -1; - pi->pchgno = -1; - pi->pchg = 0; - - for (compno = 0, picomp = pi->picomps; compno < pi->numcomps; - ++compno, ++picomp) { - for (rlvlno = 0, pirlvl = picomp->pirlvls; rlvlno < - picomp->numrlvls; ++rlvlno, ++pirlvl) { - for (prcno = 0, prclyrno = pirlvl->prclyrnos; - prcno < pirlvl->numprcs; ++prcno, ++prclyrno) { - *prclyrno = 0; - } - } - } - return 0; -} diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_t2cod.h b/converter/other/jpeg2000/libjasper/jpc/jpc_t2cod.h deleted file mode 100644 index 82dafcc..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_t2cod.h +++ /dev/null @@ -1,348 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Tier-2 Coding Library - * - * $Id$ - */ - -#ifndef JPC_T2COD_H -#define JPC_T2COD_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include "jpc_cs.h" - -/******************************************************************************\ -* Types. -\******************************************************************************/ - -/* Progression change list. */ - -typedef struct { - - /* The number of progression changes. */ - int numpchgs; - - /* The maximum number of progression changes that can be accommodated - without growing the progression change array. */ - int maxpchgs; - - /* The progression changes. */ - jpc_pchg_t **pchgs; - -} jpc_pchglist_t; - -/* Packet iterator per-resolution-level information. */ - -typedef struct { - - /* The number of precincts. */ - int numprcs; - - /* The last layer processed for each precinct. */ - int *prclyrnos; - - /* The precinct width exponent. */ - int prcwidthexpn; - - /* The precinct height exponent. */ - int prcheightexpn; - - /* The number of precincts spanning the resolution level in the horizontal - direction. */ - int numhprcs; - -} jpc_pirlvl_t; - -/* Packet iterator per-component information. */ - -typedef struct { - - /* The number of resolution levels. */ - int numrlvls; - - /* The per-resolution-level information. */ - jpc_pirlvl_t *pirlvls; - - /* The horizontal sampling period. */ - int hsamp; - - /* The vertical sampling period. */ - int vsamp; - -} jpc_picomp_t; - -/* Packet iterator class. */ - -typedef struct { - - /* The number of layers. */ - int numlyrs; - - /* The number of resolution levels. */ - int maxrlvls; - - /* The number of components. */ - int numcomps; - - /* The per-component information. */ - jpc_picomp_t *picomps; - - /* The current component. */ - jpc_picomp_t *picomp; - - /* The current resolution level. */ - jpc_pirlvl_t *pirlvl; - - /* The number of the current component. */ - int compno; - - /* The number of the current resolution level. */ - int rlvlno; - - /* The number of the current precinct. */ - int prcno; - - /* The number of the current layer. */ - int lyrno; - - /* The x-coordinate of the current position. */ - int x; - - /* The y-coordinate of the current position. */ - int y; - - /* The horizontal step size. */ - int xstep; - - /* The vertical step size. */ - int ystep; - - /* The x-coordinate of the top-left corner of the tile on the reference - grid. */ - int xstart; - - /* The y-coordinate of the top-left corner of the tile on the reference - grid. */ - int ystart; - - /* The x-coordinate of the bottom-right corner of the tile on the - reference grid (plus one). */ - int xend; - - /* The y-coordinate of the bottom-right corner of the tile on the - reference grid (plus one). */ - int yend; - - /* The current progression change. */ - jpc_pchg_t *pchg; - - /* The progression change list. */ - jpc_pchglist_t *pchglist; - - /* The progression to use in the absence of explicit specification. */ - jpc_pchg_t defaultpchg; - - /* The current progression change number. */ - int pchgno; - - /* Is this the first time in the current progression volume? */ - bool prgvolfirst; - - /* Is the current iterator value valid? */ - bool valid; - - /* The current packet number. */ - int pktno; - -} jpc_pi_t; - -/******************************************************************************\ -* Functions/macros for packet iterators. -\******************************************************************************/ - -/* Create a packet iterator. */ -jpc_pi_t *jpc_pi_create0(void); - -/* Destroy a packet iterator. */ -void jpc_pi_destroy(jpc_pi_t *pi); - -/* Add a progression change to a packet iterator. */ -int jpc_pi_addpchg(jpc_pi_t *pi, jpc_pocpchg_t *pchg); - -/* Prepare a packet iterator for iteration. */ -int jpc_pi_init(jpc_pi_t *pi); - -/* Set the iterator to the first packet. */ -int jpc_pi_begin(jpc_pi_t *pi); - -/* Proceed to the next packet in sequence. */ -int jpc_pi_next(jpc_pi_t *pi); - -/* Get the index of the current packet. */ -#define jpc_pi_getind(pi) ((pi)->pktno) - -/* Get the component number of the current packet. */ -#define jpc_pi_cmptno(pi) (assert(pi->valid), (pi)->compno) - -/* Get the resolution level of the current packet. */ -#define jpc_pi_rlvlno(pi) (assert(pi->valid), (pi)->rlvlno) - -/* Get the layer number of the current packet. */ -#define jpc_pi_lyrno(pi) (assert(pi->valid), (pi)->lyrno) - -/* Get the precinct number of the current packet. */ -#define jpc_pi_prcno(pi) (assert(pi->valid), (pi)->prcno) - -/* Get the progression order for the current packet. */ -#define jpc_pi_prg(pi) (assert(pi->valid), (pi)->pchg->prgord) - -/******************************************************************************\ -* Functions/macros for progression change lists. -\******************************************************************************/ - -/* Create a progression change list. */ -jpc_pchglist_t *jpc_pchglist_create(void); - -/* Destroy a progression change list. */ -void jpc_pchglist_destroy(jpc_pchglist_t *pchglist); - -/* Insert a new element into a progression change list. */ -int jpc_pchglist_insert(jpc_pchglist_t *pchglist, int pchgno, jpc_pchg_t *pchg); - -/* Remove an element from a progression change list. */ -jpc_pchg_t *jpc_pchglist_remove(jpc_pchglist_t *pchglist, int pchgno); - -/* Get an element from a progression change list. */ -jpc_pchg_t *jpc_pchglist_get(jpc_pchglist_t *pchglist, int pchgno); - -/* Copy a progression change list. */ -jpc_pchglist_t *jpc_pchglist_copy(jpc_pchglist_t *pchglist); - -/* Get the number of elements in a progression change list. */ -int jpc_pchglist_numpchgs(jpc_pchglist_t *pchglist); - -/******************************************************************************\ -* Functions/macros for progression changes. -\******************************************************************************/ - -/* Destroy a progression change. */ -void jpc_pchg_destroy(jpc_pchg_t *pchg); - -/* Copy a progression change. */ -jpc_pchg_t *jpc_pchg_copy(jpc_pchg_t *pchg); - -#endif diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_t2dec.c b/converter/other/jpeg2000/libjasper/jpc/jpc_t2dec.c deleted file mode 100644 index 9aaaa55..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_t2dec.c +++ /dev/null @@ -1,626 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Tier 2 Decoder - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include -#include - -#include "jasper/jas_types.h" -#include "jasper/jas_fix.h" -#include "jasper/jas_malloc.h" -#include "jasper/jas_math.h" -#include "jasper/jas_stream.h" -#include "jasper/jas_debug.h" - -#include "jpc_bs.h" -#include "jpc_dec.h" -#include "jpc_cs.h" -#include "jpc_mqdec.h" -#include "jpc_t2dec.h" -#include "jpc_t1cod.h" -#include "jpc_math.h" - -/******************************************************************************\ -* -\******************************************************************************/ - -long jpc_dec_lookahead(jas_stream_t *in); -static int jpc_getcommacode(jpc_bitstream_t *in); -static int jpc_getnumnewpasses(jpc_bitstream_t *in); -static int jpc_dec_decodepkt(jpc_dec_t *dec, jas_stream_t *pkthdrstream, jas_stream_t *in, int compno, int lvlno, - int prcno, int lyrno); - -/******************************************************************************\ -* Code. -\******************************************************************************/ - -static int jpc_getcommacode(jpc_bitstream_t *in) -{ - int n; - int v; - - n = 0; - for (;;) { - if ((v = jpc_bitstream_getbit(in)) < 0) { - return -1; - } - if (jpc_bitstream_eof(in)) { - return -1; - } - if (!v) { - break; - } - ++n; - } - - return n; -} - -static int jpc_getnumnewpasses(jpc_bitstream_t *in) -{ - int n; - - if ((n = jpc_bitstream_getbit(in)) > 0) { - if ((n = jpc_bitstream_getbit(in)) > 0) { - if ((n = jpc_bitstream_getbits(in, 2)) == 3) { - if ((n = jpc_bitstream_getbits(in, 5)) == 31) { - if ((n = jpc_bitstream_getbits(in, 7)) >= 0) { - n += 36 + 1; - } - } else if (n >= 0) { - n += 5 + 1; - } - } else if (n >= 0) { - n += 2 + 1; - } - } else if (!n) { - n += 2; - } - } else if (!n) { - ++n; - } - - return n; -} - -static int jpc_dec_decodepkt(jpc_dec_t *dec, jas_stream_t *pkthdrstream, jas_stream_t *in, int compno, int rlvlno, - int prcno, int lyrno) -{ - jpc_bitstream_t *inb; - jpc_dec_tcomp_t *tcomp; - jpc_dec_rlvl_t *rlvl; - jpc_dec_band_t *band; - jpc_dec_cblk_t *cblk; - int n; - int m; - int i; - jpc_tagtreenode_t *leaf; - int included; - int ret; - int numnewpasses; - jpc_dec_seg_t *seg; - int len; - int present; - int savenumnewpasses; - int mycounter; - jpc_ms_t *ms; - jpc_dec_tile_t *tile; - jpc_dec_ccp_t *ccp; - jpc_dec_cp_t *cp; - int bandno; - jpc_dec_prc_t *prc; - int usedcblkcnt; - int cblkno; - uint_fast32_t bodylen; - bool discard; - int passno; - int maxpasses; - int hdrlen; - int hdroffstart; - int hdroffend; - - discard = (lyrno >= dec->maxlyrs); - - tile = dec->curtile; - cp = tile->cp; - ccp = &cp->ccps[compno]; - - /* - * Decode the packet header. - */ - - /* Decode the SOP marker segment if present. */ - if (cp->csty & JPC_COD_SOP) { - if (jpc_dec_lookahead(in) == JPC_MS_SOP) { - if (!(ms = jpc_getms(in, dec->cstate))) { - return -1; - } - if (jpc_ms_gettype(ms) != JPC_MS_SOP) { - jpc_ms_destroy(ms); - fprintf(stderr, "missing SOP marker segment\n"); - return -1; - } - jpc_ms_destroy(ms); - } - } - -hdroffstart = jas_stream_getrwcount(pkthdrstream); - - if (!(inb = jpc_bitstream_sopen(pkthdrstream, "r"))) { - return -1; - } - - if ((present = jpc_bitstream_getbit(inb)) < 0) { - return 1; - } - JAS_DBGLOG(10, ("\n", present)); - JAS_DBGLOG(10, ("present=%d ", present)); - - /* Is the packet non-empty? */ - if (present) { - /* The packet is non-empty. */ - tcomp = &tile->tcomps[compno]; - rlvl = &tcomp->rlvls[rlvlno]; - bodylen = 0; - for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands; - ++bandno, ++band) { - if (!band->data) { - continue; - } - prc = &band->prcs[prcno]; - if (!prc->cblks) { - continue; - } - usedcblkcnt = 0; - for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks; - ++cblkno, ++cblk) { - ++usedcblkcnt; - if (!cblk->numpasses) { - leaf = jpc_tagtree_getleaf(prc->incltagtree, usedcblkcnt - 1); - if ((included = jpc_tagtree_decode(prc->incltagtree, leaf, lyrno + 1, inb)) < 0) { - return -1; - } - } else { - if ((included = jpc_bitstream_getbit(inb)) < 0) { - return -1; - } - } - JAS_DBGLOG(10, ("\n")); - JAS_DBGLOG(10, ("included=%d ", included)); - if (!included) { - continue; - } - if (!cblk->numpasses) { - i = 1; - leaf = jpc_tagtree_getleaf(prc->numimsbstagtree, usedcblkcnt - 1); - for (;;) { - if ((ret = jpc_tagtree_decode(prc->numimsbstagtree, leaf, i, inb)) < 0) { - return -1; - } - if (ret) { - break; - } - ++i; - } - cblk->numimsbs = i - 1; - cblk->firstpassno = cblk->numimsbs * 3; - } - if ((numnewpasses = jpc_getnumnewpasses(inb)) < 0) { - return -1; - } - JAS_DBGLOG(10, ("numnewpasses=%d ", numnewpasses)); - seg = cblk->curseg; - savenumnewpasses = numnewpasses; - mycounter = 0; - if (numnewpasses > 0) { - if ((m = jpc_getcommacode(inb)) < 0) { - return -1; - } - cblk->numlenbits += m; - JAS_DBGLOG(10, ("increment=%d ", m)); - while (numnewpasses > 0) { - passno = cblk->firstpassno + cblk->numpasses + mycounter; - /* XXX - the maxpasses is not set precisely but this doesn't matter... */ - maxpasses = JPC_SEGPASSCNT(passno, cblk->firstpassno, 10000, (ccp->cblkctx & JPC_COX_LAZY) != 0, (ccp->cblkctx & JPC_COX_TERMALL) != 0); - if (!discard && !seg) { - if (!(seg = jpc_seg_alloc())) { - return -1; - } - jpc_seglist_insert(&cblk->segs, cblk->segs.tail, seg); - if (!cblk->curseg) { - cblk->curseg = seg; - } - seg->passno = passno; - seg->type = JPC_SEGTYPE(seg->passno, cblk->firstpassno, (ccp->cblkctx & JPC_COX_LAZY) != 0); - seg->maxpasses = maxpasses; - } - n = JAS_MIN(numnewpasses, maxpasses); - mycounter += n; - numnewpasses -= n; - if ((len = jpc_bitstream_getbits(inb, cblk->numlenbits + jpc_floorlog2(n))) < 0) { - return -1; - } - JAS_DBGLOG(10, ("len=%d ", len)); - if (!discard) { - seg->lyrno = lyrno; - seg->numpasses += n; - seg->cnt = len; - seg = seg->next; - } - bodylen += len; - } - } - cblk->numpasses += savenumnewpasses; - } - } - - jpc_bitstream_inalign(inb, 0, 0); - - } else { - if (jpc_bitstream_inalign(inb, 0x7f, 0)) { - fprintf(stderr, "alignment failed\n"); - return -1; - } - } - jpc_bitstream_close(inb); - - hdroffend = jas_stream_getrwcount(pkthdrstream); - hdrlen = hdroffend - hdroffstart; - if (jas_getdbglevel() >= 5) { - fprintf(stderr, "hdrlen=%lu bodylen=%lu \n", (unsigned long) hdrlen, - (unsigned long) bodylen); - } - - if (cp->csty & JPC_COD_EPH) { - if (jpc_dec_lookahead(pkthdrstream) == JPC_MS_EPH) { - if (!(ms = jpc_getms(pkthdrstream, dec->cstate))) { - fprintf(stderr, "cannot get (EPH) marker segment\n"); - return -1; - } - if (jpc_ms_gettype(ms) != JPC_MS_EPH) { - jpc_ms_destroy(ms); - fprintf(stderr, "missing EPH marker segment\n"); - return -1; - } - jpc_ms_destroy(ms); - } - } - - /* decode the packet body. */ - - if (jas_getdbglevel() >= 1) { - fprintf(stderr, "packet body offset=%06ld\n", (long) jas_stream_getrwcount(in)); - } - - if (!discard) { - tcomp = &tile->tcomps[compno]; - rlvl = &tcomp->rlvls[rlvlno]; - for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands; - ++bandno, ++band) { - if (!band->data) { - continue; - } - prc = &band->prcs[prcno]; - if (!prc->cblks) { - continue; - } - for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks; - ++cblkno, ++cblk) { - seg = cblk->curseg; - while (seg) { - if (!seg->stream) { - if (!(seg->stream = jas_stream_memopen(0, 0))) { - return -1; - } - } -#if 0 -fprintf(stderr, "lyrno=%02d, compno=%02d, lvlno=%02d, prcno=%02d, bandno=%02d, cblkno=%02d, passno=%02d numpasses=%02d cnt=%d numbps=%d, numimsbs=%d\n", lyrno, compno, rlvlno, prcno, band - rlvl->bands, cblk - prc->cblks, seg->passno, seg->numpasses, seg->cnt, band->numbps, cblk->numimsbs); -#endif - if (seg->cnt > 0) { - if (jpc_getdata(in, seg->stream, seg->cnt) < 0) { - return -1; - } - seg->cnt = 0; - } - if (seg->numpasses >= seg->maxpasses) { - cblk->curseg = seg->next; - } - seg = seg->next; - } - } - } - } else { - if (jas_stream_gobble(in, bodylen) != bodylen) { - return -1; - } - } - return 0; -} - -/********************************************************************************************/ -/********************************************************************************************/ - -int jpc_dec_decodepkts(jpc_dec_t *dec, jas_stream_t *pkthdrstream, jas_stream_t *in) -{ - jpc_dec_tile_t *tile; - jpc_pi_t *pi; - int ret; - - tile = dec->curtile; - pi = tile->pi; - for (;;) { -if (!tile->pkthdrstream || jas_stream_peekc(tile->pkthdrstream) == EOF) { - switch (jpc_dec_lookahead(in)) { - case JPC_MS_EOC: - case JPC_MS_SOT: - return 0; - break; - case JPC_MS_SOP: - case JPC_MS_EPH: - case 0: - break; - default: - return -1; - break; - } -} - if ((ret = jpc_pi_next(pi))) { - return ret; - } -if (dec->maxpkts >= 0 && dec->numpkts >= dec->maxpkts) { - fprintf(stderr, "warning: stopping decode prematurely as requested\n"); - return 0; -} - if (jas_getdbglevel() >= 1) { - fprintf(stderr, "packet offset=%08ld prg=%d cmptno=%02d " - "rlvlno=%02d prcno=%03d lyrno=%02d\n", (long) - jas_stream_getrwcount(in), jpc_pi_prg(pi), jpc_pi_cmptno(pi), - jpc_pi_rlvlno(pi), jpc_pi_prcno(pi), jpc_pi_lyrno(pi)); - } - if (jpc_dec_decodepkt(dec, pkthdrstream, in, jpc_pi_cmptno(pi), jpc_pi_rlvlno(pi), - jpc_pi_prcno(pi), jpc_pi_lyrno(pi))) { - return -1; - } -++dec->numpkts; - } - - return 0; -} - -jpc_pi_t *jpc_dec_pi_create(jpc_dec_t *dec, jpc_dec_tile_t *tile) -{ - jpc_pi_t *pi; - int compno; - jpc_picomp_t *picomp; - jpc_pirlvl_t *pirlvl; - jpc_dec_tcomp_t *tcomp; - int rlvlno; - jpc_dec_rlvl_t *rlvl; - int prcno; - int *prclyrno; - jpc_dec_cmpt_t *cmpt; - - if (!(pi = jpc_pi_create0())) { - return 0; - } - pi->numcomps = dec->numcomps; - if (!(pi->picomps = jas_malloc(pi->numcomps * sizeof(jpc_picomp_t)))) { - jpc_pi_destroy(pi); - return 0; - } - for (compno = 0, picomp = pi->picomps; compno < pi->numcomps; ++compno, - ++picomp) { - picomp->pirlvls = 0; - } - - for (compno = 0, tcomp = tile->tcomps, picomp = pi->picomps; - compno < pi->numcomps; ++compno, ++tcomp, ++picomp) { - picomp->numrlvls = tcomp->numrlvls; - if (!(picomp->pirlvls = jas_malloc(picomp->numrlvls * - sizeof(jpc_pirlvl_t)))) { - jpc_pi_destroy(pi); - return 0; - } - for (rlvlno = 0, pirlvl = picomp->pirlvls; rlvlno < - picomp->numrlvls; ++rlvlno, ++pirlvl) { - pirlvl->prclyrnos = 0; - } - for (rlvlno = 0, pirlvl = picomp->pirlvls, rlvl = tcomp->rlvls; - rlvlno < picomp->numrlvls; ++rlvlno, ++pirlvl, ++rlvl) { -/* XXX sizeof(long) should be sizeof different type */ - pirlvl->numprcs = rlvl->numprcs; - if (!(pirlvl->prclyrnos = jas_malloc(pirlvl->numprcs * - sizeof(long)))) { - jpc_pi_destroy(pi); - return 0; - } - } - } - - pi->maxrlvls = 0; - for (compno = 0, tcomp = tile->tcomps, picomp = pi->picomps, cmpt = - dec->cmpts; compno < pi->numcomps; ++compno, ++tcomp, ++picomp, - ++cmpt) { - picomp->hsamp = cmpt->hstep; - picomp->vsamp = cmpt->vstep; - for (rlvlno = 0, pirlvl = picomp->pirlvls, rlvl = tcomp->rlvls; - rlvlno < picomp->numrlvls; ++rlvlno, ++pirlvl, ++rlvl) { - pirlvl->prcwidthexpn = rlvl->prcwidthexpn; - pirlvl->prcheightexpn = rlvl->prcheightexpn; - for (prcno = 0, prclyrno = pirlvl->prclyrnos; - prcno < pirlvl->numprcs; ++prcno, ++prclyrno) { - *prclyrno = 0; - } - pirlvl->numhprcs = rlvl->numhprcs; - } - if (pi->maxrlvls < tcomp->numrlvls) { - pi->maxrlvls = tcomp->numrlvls; - } - } - - pi->numlyrs = tile->cp->numlyrs; - pi->xstart = tile->xstart; - pi->ystart = tile->ystart; - pi->xend = tile->xend; - pi->yend = tile->yend; - - pi->picomp = 0; - pi->pirlvl = 0; - pi->x = 0; - pi->y = 0; - pi->compno = 0; - pi->rlvlno = 0; - pi->prcno = 0; - pi->lyrno = 0; - pi->xstep = 0; - pi->ystep = 0; - - pi->pchgno = -1; - - pi->defaultpchg.prgord = tile->cp->prgord; - pi->defaultpchg.compnostart = 0; - pi->defaultpchg.compnoend = pi->numcomps; - pi->defaultpchg.rlvlnostart = 0; - pi->defaultpchg.rlvlnoend = pi->maxrlvls; - pi->defaultpchg.lyrnoend = pi->numlyrs; - pi->pchg = 0; - - pi->valid = 0; - - return pi; -} - -long jpc_dec_lookahead(jas_stream_t *in) -{ - uint_fast16_t x; - if (jpc_getuint16(in, &x)) { - return -1; - } - if (jas_stream_ungetc(in, x & 0xff) == EOF || - jas_stream_ungetc(in, x >> 8) == EOF) { - return -1; - } - if (x >= JPC_MS_INMIN && x <= JPC_MS_INMAX) { - return x; - } - return 0; -} diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_t2dec.h b/converter/other/jpeg2000/libjasper/jpc/jpc_t2dec.h deleted file mode 100644 index 923d7c1..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_t2dec.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Tier 2 Decoder - * - * $Id$ - */ - -#ifndef JPC_T2DEC_H -#define JPC_T2DEC_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include "jasper/jas_fix.h" -#include "jasper/jas_stream.h" - -#include "jpc_bs.h" -#include "jpc_dec.h" -#include "jpc_mqdec.h" - -/******************************************************************************\ -* Functions. -\******************************************************************************/ - -/* Decode the packets for a tile-part. */ -int jpc_dec_decodepkts(jpc_dec_t *dec, jas_stream_t *pkthdrstream, - jas_stream_t *in); - -/* Create a packet iterator for the decoder. */ -jpc_pi_t *jpc_dec_pi_create(jpc_dec_t *dec, jpc_dec_tile_t *tile); - -#endif diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_t2enc.c b/converter/other/jpeg2000/libjasper/jpc/jpc_t2enc.c deleted file mode 100644 index 1444dc7..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_t2enc.c +++ /dev/null @@ -1,704 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Tier 2 Encoder - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include -#include - -#include "jasper/jas_fix.h" -#include "jasper/jas_malloc.h" -#include "jasper/jas_math.h" -#include "jasper/jas_debug.h" - -#include "jpc_flt.h" -#include "jpc_t2enc.h" -#include "jpc_t2cod.h" -#include "jpc_tagtree.h" -#include "jpc_enc.h" -#include "jpc_math.h" - -/******************************************************************************\ -* Code. -\******************************************************************************/ - -static int jpc_putcommacode(jpc_bitstream_t *out, int n) -{ - assert(n >= 0); - - while (--n >= 0) { - if (jpc_bitstream_putbit(out, 1) == EOF) { - return -1; - } - } - if (jpc_bitstream_putbit(out, 0) == EOF) { - return -1; - } - return 0; -} - -static int jpc_putnumnewpasses(jpc_bitstream_t *out, int n) -{ - int ret; - - if (n <= 0) { - return -1; - } else if (n == 1) { - ret = jpc_bitstream_putbit(out, 0); - } else if (n == 2) { - ret = jpc_bitstream_putbits(out, 2, 2); - } else if (n <= 5) { - ret = jpc_bitstream_putbits(out, 4, 0xc | (n - 3)); - } else if (n <= 36) { - ret = jpc_bitstream_putbits(out, 9, 0x1e0 | (n - 6)); - } else if (n <= 164) { - ret = jpc_bitstream_putbits(out, 16, 0xff80 | (n - 37)); - } else { - /* The standard has no provision for encoding a larger value. - In practice, however, it is highly unlikely that this - limitation will ever be encountered. */ - return -1; - } - - return (ret != EOF) ? 0 : (-1); -} - -int jpc_enc_encpkts(jpc_enc_t *enc, jas_stream_t *out) -{ - jpc_enc_tile_t *tile; - jpc_pi_t *pi; - - tile = enc->curtile; - - jpc_init_t2state(enc, 0); - pi = tile->pi; - jpc_pi_init(pi); - - if (!jpc_pi_next(pi)) { - for (;;) { - if (jpc_enc_encpkt(enc, out, jpc_pi_cmptno(pi), jpc_pi_rlvlno(pi), - jpc_pi_prcno(pi), jpc_pi_lyrno(pi))) { - return -1; - } - if (jpc_pi_next(pi)) { - break; - } - } - } - - return 0; -} - -int jpc_enc_encpkt(jpc_enc_t *enc, jas_stream_t *out, int compno, int lvlno, int prcno, int lyrno) -{ - jpc_enc_tcmpt_t *comp; - jpc_enc_rlvl_t *lvl; - jpc_enc_band_t *band; - jpc_enc_band_t *endbands; - jpc_enc_cblk_t *cblk; - jpc_enc_cblk_t *endcblks; - jpc_bitstream_t *outb; - jpc_enc_pass_t *pass; - jpc_enc_pass_t *startpass; - jpc_enc_pass_t *lastpass; - jpc_enc_pass_t *endpass; - jpc_enc_pass_t *endpasses; - int i; - int included; - int ret; - jpc_tagtreenode_t *leaf; - int n; - int t1; - int t2; - int adjust; - int maxadjust; - int datalen; - int numnewpasses; - int passcount; - jpc_enc_tile_t *tile; - jpc_enc_prc_t *prc; - jpc_enc_cp_t *cp; - jpc_ms_t *ms; - - tile = enc->curtile; - cp = enc->cp; - - if (cp->tcp.csty & JPC_COD_SOP) { - if (!(ms = jpc_ms_create(JPC_MS_SOP))) { - return -1; - } - ms->parms.sop.seqno = jpc_pi_getind(tile->pi); - if (jpc_putms(out, enc->cstate, ms)) { - return -1; - } - jpc_ms_destroy(ms); - } - - outb = jpc_bitstream_sopen(out, "w+"); - assert(outb); - - if (jpc_bitstream_putbit(outb, 1) == EOF) { - return -1; - } - JAS_DBGLOG(10, ("\n")); - JAS_DBGLOG(10, ("present. ")); - - comp = &tile->tcmpts[compno]; - lvl = &comp->rlvls[lvlno]; - endbands = &lvl->bands[lvl->numbands]; - for (band = lvl->bands; band != endbands; ++band) { - if (!band->data) { - continue; - } - prc = &band->prcs[prcno]; - if (!prc->cblks) { - continue; - } - - endcblks = &prc->cblks[prc->numcblks]; - for (cblk = prc->cblks; cblk != endcblks; ++cblk) { - if (!lyrno) { - leaf = jpc_tagtree_getleaf(prc->nlibtree, cblk - prc->cblks); - jpc_tagtree_setvalue(prc->nlibtree, leaf, cblk->numimsbs); - } - pass = cblk->curpass; - included = (pass && pass->lyrno == lyrno); - if (included && (!cblk->numencpasses)) { - assert(pass->lyrno == lyrno); - leaf = jpc_tagtree_getleaf(prc->incltree, - cblk - prc->cblks); - jpc_tagtree_setvalue(prc->incltree, leaf, pass->lyrno); - } - } - - endcblks = &prc->cblks[prc->numcblks]; - for (cblk = prc->cblks; cblk != endcblks; ++cblk) { - pass = cblk->curpass; - included = (pass && pass->lyrno == lyrno); - if (!cblk->numencpasses) { - leaf = jpc_tagtree_getleaf(prc->incltree, - cblk - prc->cblks); - if (jpc_tagtree_encode(prc->incltree, leaf, lyrno - + 1, outb) < 0) { - return -1; - } - } else { - if (jpc_bitstream_putbit(outb, included) == EOF) { - return -1; - } - } - JAS_DBGLOG(10, ("included=%d ", included)); - if (!included) { - continue; - } - if (!cblk->numencpasses) { - i = 1; - leaf = jpc_tagtree_getleaf(prc->nlibtree, cblk - prc->cblks); - for (;;) { - if ((ret = jpc_tagtree_encode(prc->nlibtree, leaf, i, outb)) < 0) { - return -1; - } - if (ret) { - break; - } - ++i; - } - assert(leaf->known_ && i == leaf->value_ + 1); - } - - endpasses = &cblk->passes[cblk->numpasses]; - startpass = pass; - endpass = startpass; - while (endpass != endpasses && endpass->lyrno == lyrno){ - ++endpass; - } - numnewpasses = endpass - startpass; - if (jpc_putnumnewpasses(outb, numnewpasses)) { - return -1; - } - JAS_DBGLOG(10, ("numnewpasses=%d ", numnewpasses)); - - lastpass = endpass - 1; - n = startpass->start; - passcount = 1; - maxadjust = 0; - for (pass = startpass; pass != endpass; ++pass) { - if (pass->term || pass == lastpass) { - datalen = pass->end - n; - t1 = jpc_firstone(datalen) + 1; - t2 = cblk->numlenbits + jpc_floorlog2(passcount); - adjust = JAS_MAX(t1 - t2, 0); - maxadjust = JAS_MAX(adjust, maxadjust); - n += datalen; - passcount = 1; - } else { - ++passcount; - } - } - if (jpc_putcommacode(outb, maxadjust)) { - return -1; - } - cblk->numlenbits += maxadjust; - - lastpass = endpass - 1; - n = startpass->start; - passcount = 1; - for (pass = startpass; pass != endpass; ++pass) { - if (pass->term || pass == lastpass) { - datalen = pass->end - n; -assert(jpc_firstone(datalen) < cblk->numlenbits + jpc_floorlog2(passcount)); - if (jpc_bitstream_putbits(outb, cblk->numlenbits + jpc_floorlog2(passcount), datalen) == EOF) { - return -1; - } - n += datalen; - passcount = 1; - } else { - ++passcount; - } - } - } - } - - jpc_bitstream_outalign(outb, 0); - jpc_bitstream_close(outb); - - if (cp->tcp.csty & JPC_COD_EPH) { - if (!(ms = jpc_ms_create(JPC_MS_EPH))) { - return -1; - } - jpc_putms(out, enc->cstate, ms); - jpc_ms_destroy(ms); - } - - comp = &tile->tcmpts[compno]; - lvl = &comp->rlvls[lvlno]; - endbands = &lvl->bands[lvl->numbands]; - for (band = lvl->bands; band != endbands; ++band) { - if (!band->data) { - continue; - } - prc = &band->prcs[prcno]; - if (!prc->cblks) { - continue; - } - endcblks = &prc->cblks[prc->numcblks]; - for (cblk = prc->cblks; cblk != endcblks; ++cblk) { - pass = cblk->curpass; - - if (!pass) { - continue; - } - if (pass->lyrno != lyrno) { - assert(pass->lyrno < 0 || pass->lyrno > lyrno); - continue; - } - - endpasses = &cblk->passes[cblk->numpasses]; - startpass = pass; - endpass = startpass; - while (endpass != endpasses && endpass->lyrno == lyrno){ - ++endpass; - } - lastpass = endpass - 1; - numnewpasses = endpass - startpass; - - jas_stream_seek(cblk->stream, startpass->start, SEEK_SET); - assert(jas_stream_tell(cblk->stream) == startpass->start); - if (jas_stream_copy(out, cblk->stream, lastpass->end - startpass->start)) { - return -1; - } - cblk->curpass = (endpass != endpasses) ? endpass : 0; - cblk->numencpasses += numnewpasses; - - } - } - - return 0; -} - -void jpc_save_t2state(jpc_enc_t *enc) -{ -/* stream pos in embedded T1 stream may be wrong since not saved/restored! */ - - jpc_enc_tcmpt_t *comp; - jpc_enc_tcmpt_t *endcomps; - jpc_enc_rlvl_t *lvl; - jpc_enc_rlvl_t *endlvls; - jpc_enc_band_t *band; - jpc_enc_band_t *endbands; - jpc_enc_cblk_t *cblk; - jpc_enc_cblk_t *endcblks; - jpc_enc_tile_t *tile; - uint_fast32_t prcno; - jpc_enc_prc_t *prc; - - tile = enc->curtile; - - endcomps = &tile->tcmpts[tile->numtcmpts]; - for (comp = tile->tcmpts; comp != endcomps; ++comp) { - endlvls = &comp->rlvls[comp->numrlvls]; - for (lvl = comp->rlvls; lvl != endlvls; ++lvl) { - if (!lvl->bands) { - continue; - } - endbands = &lvl->bands[lvl->numbands]; - for (band = lvl->bands; band != endbands; ++band) { - if (!band->data) { - continue; - } - for (prcno = 0, prc = band->prcs; prcno < lvl->numprcs; ++prcno, ++prc) { - if (!prc->cblks) { - continue; - } - jpc_tagtree_copy(prc->savincltree, prc->incltree); - jpc_tagtree_copy(prc->savnlibtree, prc->nlibtree); - endcblks = &prc->cblks[prc->numcblks]; - for (cblk = prc->cblks; cblk != endcblks; ++cblk) { - cblk->savedcurpass = cblk->curpass; - cblk->savednumencpasses = cblk->numencpasses; - cblk->savednumlenbits = cblk->numlenbits; - } - } - } - } - } - -} - -void jpc_restore_t2state(jpc_enc_t *enc) -{ - - jpc_enc_tcmpt_t *comp; - jpc_enc_tcmpt_t *endcomps; - jpc_enc_rlvl_t *lvl; - jpc_enc_rlvl_t *endlvls; - jpc_enc_band_t *band; - jpc_enc_band_t *endbands; - jpc_enc_cblk_t *cblk; - jpc_enc_cblk_t *endcblks; - jpc_enc_tile_t *tile; - uint_fast32_t prcno; - jpc_enc_prc_t *prc; - - tile = enc->curtile; - - endcomps = &tile->tcmpts[tile->numtcmpts]; - for (comp = tile->tcmpts; comp != endcomps; ++comp) { - endlvls = &comp->rlvls[comp->numrlvls]; - for (lvl = comp->rlvls; lvl != endlvls; ++lvl) { - if (!lvl->bands) { - continue; - } - endbands = &lvl->bands[lvl->numbands]; - for (band = lvl->bands; band != endbands; ++band) { - if (!band->data) { - continue; - } - for (prcno = 0, prc = band->prcs; prcno < lvl->numprcs; ++prcno, ++prc) { - if (!prc->cblks) { - continue; - } - jpc_tagtree_copy(prc->incltree, prc->savincltree); - jpc_tagtree_copy(prc->nlibtree, prc->savnlibtree); - endcblks = &prc->cblks[prc->numcblks]; - for (cblk = prc->cblks; cblk != endcblks; ++cblk) { - cblk->curpass = cblk->savedcurpass; - cblk->numencpasses = cblk->savednumencpasses; - cblk->numlenbits = cblk->savednumlenbits; - } - } - } - } - } -} - -void jpc_init_t2state(jpc_enc_t *enc, int raflag) -{ -/* It is assumed that band->numbps and cblk->numbps precomputed */ - - jpc_enc_tcmpt_t *comp; - jpc_enc_tcmpt_t *endcomps; - jpc_enc_rlvl_t *lvl; - jpc_enc_rlvl_t *endlvls; - jpc_enc_band_t *band; - jpc_enc_band_t *endbands; - jpc_enc_cblk_t *cblk; - jpc_enc_cblk_t *endcblks; - jpc_enc_pass_t *pass; - jpc_enc_pass_t *endpasses; - jpc_tagtreenode_t *leaf; - jpc_enc_tile_t *tile; - uint_fast32_t prcno; - jpc_enc_prc_t *prc; - - tile = enc->curtile; - - endcomps = &tile->tcmpts[tile->numtcmpts]; - for (comp = tile->tcmpts; comp != endcomps; ++comp) { - endlvls = &comp->rlvls[comp->numrlvls]; - for (lvl = comp->rlvls; lvl != endlvls; ++lvl) { - if (!lvl->bands) { - continue; - } - endbands = &lvl->bands[lvl->numbands]; - for (band = lvl->bands; band != endbands; ++band) { - if (!band->data) { - continue; - } - for (prcno = 0, prc = band->prcs; prcno < lvl->numprcs; ++prcno, ++prc) { - if (!prc->cblks) { - continue; - } - jpc_tagtree_reset(prc->incltree); - jpc_tagtree_reset(prc->nlibtree); - endcblks = &prc->cblks[prc->numcblks]; - for (cblk = prc->cblks; cblk != endcblks; ++cblk) { - if (jas_stream_rewind(cblk->stream)) { - assert(0); - } - cblk->curpass = (cblk->numpasses > 0) ? cblk->passes : 0; - cblk->numencpasses = 0; - cblk->numlenbits = 3; - cblk->numimsbs = band->numbps - cblk->numbps; - assert(cblk->numimsbs >= 0); - leaf = jpc_tagtree_getleaf(prc->nlibtree, cblk - prc->cblks); - jpc_tagtree_setvalue(prc->nlibtree, leaf, cblk->numimsbs); - - if (raflag) { - endpasses = &cblk->passes[cblk->numpasses]; - for (pass = cblk->passes; pass != endpasses; ++pass) { - pass->lyrno = -1; - pass->lyrno = 0; - } - } - } - } - } - } - } - -} - -jpc_pi_t *jpc_enc_pi_create(jpc_enc_cp_t *cp, jpc_enc_tile_t *tile) -{ - jpc_pi_t *pi; - int compno; - jpc_picomp_t *picomp; - jpc_pirlvl_t *pirlvl; - jpc_enc_tcmpt_t *tcomp; - int rlvlno; - jpc_enc_rlvl_t *rlvl; - int prcno; - int *prclyrno; - - if (!(pi = jpc_pi_create0())) { - return 0; - } - pi->pktno = -1; - pi->numcomps = cp->numcmpts; - if (!(pi->picomps = jas_malloc(pi->numcomps * sizeof(jpc_picomp_t)))) { - jpc_pi_destroy(pi); - return 0; - } - for (compno = 0, picomp = pi->picomps; compno < pi->numcomps; ++compno, - ++picomp) { - picomp->pirlvls = 0; - } - - for (compno = 0, tcomp = tile->tcmpts, picomp = pi->picomps; - compno < pi->numcomps; ++compno, ++tcomp, ++picomp) { - picomp->numrlvls = tcomp->numrlvls; - if (!(picomp->pirlvls = jas_malloc(picomp->numrlvls * - sizeof(jpc_pirlvl_t)))) { - jpc_pi_destroy(pi); - return 0; - } - for (rlvlno = 0, pirlvl = picomp->pirlvls; rlvlno < - picomp->numrlvls; ++rlvlno, ++pirlvl) { - pirlvl->prclyrnos = 0; - } - for (rlvlno = 0, pirlvl = picomp->pirlvls, rlvl = tcomp->rlvls; - rlvlno < picomp->numrlvls; ++rlvlno, ++pirlvl, ++rlvl) { -/* XXX sizeof(long) should be sizeof different type */ - pirlvl->numprcs = rlvl->numprcs; - if (rlvl->numprcs) { - if (!(pirlvl->prclyrnos = jas_malloc(pirlvl->numprcs * - sizeof(long)))) { - jpc_pi_destroy(pi); - return 0; - } - } else { - pirlvl->prclyrnos = 0; - } - } - } - - pi->maxrlvls = 0; - for (compno = 0, tcomp = tile->tcmpts, picomp = pi->picomps; - compno < pi->numcomps; ++compno, ++tcomp, ++picomp) { - picomp->hsamp = cp->ccps[compno].sampgrdstepx; - picomp->vsamp = cp->ccps[compno].sampgrdstepy; - for (rlvlno = 0, pirlvl = picomp->pirlvls, rlvl = tcomp->rlvls; - rlvlno < picomp->numrlvls; ++rlvlno, ++pirlvl, ++rlvl) { - pirlvl->prcwidthexpn = rlvl->prcwidthexpn; - pirlvl->prcheightexpn = rlvl->prcheightexpn; - for (prcno = 0, prclyrno = pirlvl->prclyrnos; - prcno < pirlvl->numprcs; ++prcno, ++prclyrno) { - *prclyrno = 0; - } - pirlvl->numhprcs = rlvl->numhprcs; - } - if (pi->maxrlvls < tcomp->numrlvls) { - pi->maxrlvls = tcomp->numrlvls; - } - } - - pi->numlyrs = tile->numlyrs; - pi->xstart = tile->tlx; - pi->ystart = tile->tly; - pi->xend = tile->brx; - pi->yend = tile->bry; - - pi->picomp = 0; - pi->pirlvl = 0; - pi->x = 0; - pi->y = 0; - pi->compno = 0; - pi->rlvlno = 0; - pi->prcno = 0; - pi->lyrno = 0; - pi->xstep = 0; - pi->ystep = 0; - - pi->pchgno = -1; - - pi->defaultpchg.prgord = tile->prg; - pi->defaultpchg.compnostart = 0; - pi->defaultpchg.compnoend = pi->numcomps; - pi->defaultpchg.rlvlnostart = 0; - pi->defaultpchg.rlvlnoend = pi->maxrlvls; - pi->defaultpchg.lyrnoend = pi->numlyrs; - pi->pchg = 0; - - pi->valid = 0; - - return pi; -} diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_t2enc.h b/converter/other/jpeg2000/libjasper/jpc/jpc_t2enc.h deleted file mode 100644 index e97f8c0..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_t2enc.h +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Tier 2 Encoder - * - * $Id$ - */ - -#ifndef JPC_T2ENC_H -#define JPC_T2ENC_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include -#include - -#include "jpc_enc.h" - -/******************************************************************************\ -* Functions. -\******************************************************************************/ - -/* Encode the packets for a tile. */ -int jpc_enc_encpkts(jpc_enc_t *enc, jas_stream_t *out); - -/* Encode the specified packet. */ -int jpc_enc_encpkt(jpc_enc_t *enc, jas_stream_t *out, int compno, int lvlno, - int prcno, int lyrno); - -/* Save the tier-2 coding state. */ -void jpc_save_t2state(jpc_enc_t *enc); - -/* Restore the tier-2 coding state. */ -void jpc_restore_t2state(jpc_enc_t *enc); - -/* Initialize the tier-2 coding state. */ -void jpc_init_t2state(jpc_enc_t *enc, int raflag); - -/* Create a packet iterator for the encoder. */ -jpc_pi_t *jpc_enc_pi_create(jpc_enc_cp_t *cp, jpc_enc_tile_t *tile); - -#endif diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_tagtree.c b/converter/other/jpeg2000/libjasper/jpc/jpc_tagtree.c deleted file mode 100644 index 2b13fcf..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_tagtree.c +++ /dev/null @@ -1,426 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Tag Tree Library - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include -#include -#include -#include - -#include "jasper/jas_malloc.h" - -#include "jpc_tagtree.h" - -/******************************************************************************\ -* Code for creating and destroying tag trees. -\******************************************************************************/ - -static jpc_tagtree_t *jpc_tagtree_alloc(void) -{ - jpc_tagtree_t *tree; - - if (!(tree = jas_malloc(sizeof(jpc_tagtree_t)))) { - return 0; - } - tree->numleafsh_ = 0; - tree->numleafsv_ = 0; - tree->numnodes_ = 0; - tree->nodes_ = 0; - - return tree; -} - -/* Create a tag tree. */ - -jpc_tagtree_t *jpc_tagtree_create(int numleafsh, int numleafsv) -{ - int nplh[JPC_TAGTREE_MAXDEPTH]; - int nplv[JPC_TAGTREE_MAXDEPTH]; - jpc_tagtreenode_t *node; - jpc_tagtreenode_t *parentnode; - jpc_tagtreenode_t *parentnode0; - jpc_tagtree_t *tree; - int i; - int j; - int k; - int numlvls; - int n; - - assert(numleafsh > 0 && numleafsv > 0); - - if (!(tree = jpc_tagtree_alloc())) { - return 0; - } - tree->numleafsh_ = numleafsh; - tree->numleafsv_ = numleafsv; - - numlvls = 0; - nplh[0] = numleafsh; - nplv[0] = numleafsv; - do { - n = nplh[numlvls] * nplv[numlvls]; - nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2; - nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2; - tree->numnodes_ += n; - ++numlvls; - } while (n > 1); - - if (!(tree->nodes_ = jas_malloc(tree->numnodes_ * sizeof(jpc_tagtreenode_t)))) { - return 0; - } - - /* Initialize the parent links for all nodes in the tree. */ - - node = tree->nodes_; - parentnode = &tree->nodes_[tree->numleafsh_ * tree->numleafsv_]; - parentnode0 = parentnode; - - for (i = 0; i < numlvls - 1; ++i) { - for (j = 0; j < nplv[i]; ++j) { - k = nplh[i]; - while (--k >= 0) { - node->parent_ = parentnode; - ++node; - if (--k >= 0) { - node->parent_ = parentnode; - ++node; - } - ++parentnode; - } - if ((j & 1) || j == nplv[i] - 1) { - parentnode0 = parentnode; - } else { - parentnode = parentnode0; - parentnode0 += nplh[i]; - } - } - } - node->parent_ = 0; - - /* Initialize the data values to something sane. */ - - jpc_tagtree_reset(tree); - - return tree; -} - -/* Destroy a tag tree. */ - -void jpc_tagtree_destroy(jpc_tagtree_t *tree) -{ - if (tree->nodes_) { - jas_free(tree->nodes_); - } - jas_free(tree); -} - -/******************************************************************************\ -* Code. -\******************************************************************************/ - -/* Copy state information from one tag tree to another. */ - -void jpc_tagtree_copy(jpc_tagtree_t *dsttree, jpc_tagtree_t *srctree) -{ - int n; - jpc_tagtreenode_t *srcnode; - jpc_tagtreenode_t *dstnode; - - /* The two tag trees must have similar sizes. */ - assert(srctree->numleafsh_ == dsttree->numleafsh_ && - srctree->numleafsv_ == dsttree->numleafsv_); - - n = srctree->numnodes_; - srcnode = srctree->nodes_; - dstnode = dsttree->nodes_; - while (--n >= 0) { - dstnode->value_ = srcnode->value_; - dstnode->low_ = srcnode->low_; - dstnode->known_ = srcnode->known_; - ++dstnode; - ++srcnode; - } -} - -/* Reset all of the state information associated with a tag tree. */ - -void jpc_tagtree_reset(jpc_tagtree_t *tree) -{ - int n; - jpc_tagtreenode_t *node; - - n = tree->numnodes_; - node = tree->nodes_; - - while (--n >= 0) { - node->value_ = INT_MAX; - node->low_ = 0; - node->known_ = 0; - ++node; - } -} - -/* Set the value associated with the specified leaf node, updating -the other nodes as necessary. */ - -void jpc_tagtree_setvalue(jpc_tagtree_t *tree, jpc_tagtreenode_t *leaf, int value) -{ - jpc_tagtreenode_t *node; - - assert(value >= 0); - - node = leaf; - while (node && node->value_ > value) { - node->value_ = value; - node = node->parent_; - } -} - -/* Get a particular leaf node. */ - -jpc_tagtreenode_t *jpc_tagtree_getleaf(jpc_tagtree_t *tree, int n) -{ - return &tree->nodes_[n]; -} - -/* Invoke the tag tree encoding procedure. */ - -int jpc_tagtree_encode(jpc_tagtree_t *tree, jpc_tagtreenode_t *leaf, int threshold, - jpc_bitstream_t *out) -{ - jpc_tagtreenode_t *stk[JPC_TAGTREE_MAXDEPTH - 1]; - jpc_tagtreenode_t **stkptr; - jpc_tagtreenode_t *node; - int low; - - assert(leaf); - assert(threshold >= 0); - - /* Traverse to the root of the tree, recording the path taken. */ - stkptr = stk; - node = leaf; - while (node->parent_) { - *stkptr++ = node; - node = node->parent_; - } - - low = 0; - for (;;) { - if (low > node->low_) { - /* Deferred propagation of the lower bound downward in - the tree. */ - node->low_ = low; - } else { - low = node->low_; - } - - while (low < threshold) { - if (low >= node->value_) { - if (!node->known_) { - if (jpc_bitstream_putbit(out, 1) == EOF) { - return -1; - } - node->known_ = 1; - } - break; - } - if (jpc_bitstream_putbit(out, 0) == EOF) { - return -1; - } - ++low; - } - node->low_ = low; - if (stkptr == stk) { - break; - } - node = *--stkptr; - - } - return (leaf->low_ < threshold) ? 1 : 0; - -} - -/* Invoke the tag tree decoding procedure. */ - -int jpc_tagtree_decode(jpc_tagtree_t *tree, jpc_tagtreenode_t *leaf, int threshold, - jpc_bitstream_t *in) -{ - jpc_tagtreenode_t *stk[JPC_TAGTREE_MAXDEPTH - 1]; - jpc_tagtreenode_t **stkptr; - jpc_tagtreenode_t *node; - int low; - int ret; - - assert(threshold >= 0); - - /* Traverse to the root of the tree, recording the path taken. */ - stkptr = stk; - node = leaf; - while (node->parent_) { - *stkptr++ = node; - node = node->parent_; - } - - low = 0; - for (;;) { - if (low > node->low_) { - node->low_ = low; - } else { - low = node->low_; - } - while (low < threshold && low < node->value_) { - if ((ret = jpc_bitstream_getbit(in)) < 0) { - return -1; - } - if (ret) { - node->value_ = low; - } else { - ++low; - } - } - node->low_ = low; - if (stkptr == stk) { - break; - } - node = *--stkptr; - } - - return (node->value_ < threshold) ? 1 : 0; -} - -/******************************************************************************\ -* Code for debugging. -\******************************************************************************/ - -void jpc_tagtree_dump(jpc_tagtree_t *tree, FILE *out) -{ - jpc_tagtreenode_t *node; - int n; - - node = tree->nodes_; - n = tree->numnodes_; - while (--n >= 0) { - fprintf(out, "node %p, parent %p, value %d, lower %d, known %d\n", - (void *) node, (void *) node->parent_, node->value_, node->low_, - node->known_); - ++node; - } -} diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_tagtree.h b/converter/other/jpeg2000/libjasper/jpc/jpc_tagtree.h deleted file mode 100644 index 1892b13..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_tagtree.h +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Tag Tree Library - * - * $Id$ - */ - -#ifndef JPC_TAGTREE_H -#define JPC_TAGTREE_H - -/******************************************************************************\ -* Includes -\******************************************************************************/ - -#include -#include - -#include "jpc_bs.h" - -/******************************************************************************\ -* Constants -\******************************************************************************/ - -/* The maximum allowable depth for a tag tree. */ -#define JPC_TAGTREE_MAXDEPTH 32 - -/******************************************************************************\ -* Types -\******************************************************************************/ - -/* - * Tag tree node. - */ - -typedef struct jpc_tagtreenode_ { - - /* The parent of this node. */ - struct jpc_tagtreenode_ *parent_; - - /* The value associated with this node. */ - int value_; - - /* The lower bound on the value associated with this node. */ - int low_; - - /* A flag indicating if the value is known exactly. */ - int known_; - -} jpc_tagtreenode_t; - -/* - * Tag tree. - */ - -typedef struct { - - /* The number of leaves in the horizontal direction. */ - int numleafsh_; - - /* The number of leaves in the vertical direction. */ - int numleafsv_; - - /* The total number of nodes in the tree. */ - int numnodes_; - - /* The nodes. */ - jpc_tagtreenode_t *nodes_; - -} jpc_tagtree_t; - -/******************************************************************************\ -* Functions. -\******************************************************************************/ - -/* Create a tag tree. */ -jpc_tagtree_t *jpc_tagtree_create(int numleafsh, int numleafsv); - -/* Destroy a tag tree. */ -void jpc_tagtree_destroy(jpc_tagtree_t *tree); - -/* Copy data from one tag tree to another. */ -void jpc_tagtree_copy(jpc_tagtree_t *dsttree, jpc_tagtree_t *srctree); - -/* Reset the tag tree state. */ -void jpc_tagtree_reset(jpc_tagtree_t *tree); - -/* Set the value associated with a particular leaf node of a tag tree. */ -void jpc_tagtree_setvalue(jpc_tagtree_t *tree, jpc_tagtreenode_t *leaf, - int value); - -/* Get a pointer to a particular leaf node. */ -jpc_tagtreenode_t *jpc_tagtree_getleaf(jpc_tagtree_t *tree, int n); - -/* Invoke the tag tree decoding procedure. */ -int jpc_tagtree_decode(jpc_tagtree_t *tree, jpc_tagtreenode_t *leaf, - int threshold, jpc_bitstream_t *in); - -/* Invoke the tag tree encoding procedure. */ -int jpc_tagtree_encode(jpc_tagtree_t *tree, jpc_tagtreenode_t *leaf, - int threshold, jpc_bitstream_t *out); - -/* Dump a tag tree (for debugging purposes). */ -void jpc_tagtree_dump(jpc_tagtree_t *tree, FILE *out); - -#endif diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_tsfb.c b/converter/other/jpeg2000/libjasper/jpc/jpc_tsfb.c deleted file mode 100644 index f7d66b5..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_tsfb.c +++ /dev/null @@ -1,662 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Tree-Structured Filter Bank (TSFB) Library - * - * $Id$ - */ - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include - -#include "jasper/jas_malloc.h" -#include "jasper/jas_seq.h" - -#include "jpc_tsfb.h" -#include "jpc_cod.h" -#include "jpc_cs.h" -#include "jpc_util.h" - -/******************************************************************************\ -* -\******************************************************************************/ - -#define bandnotovind(tsfbnode, x) ((x) / (tsfbnode)->numhchans) -#define bandnotohind(tsfbnode, x) ((x) % (tsfbnode)->numhchans) - -static jpc_tsfb_t *jpc_tsfb_create(void); -static jpc_tsfbnode_t *jpc_tsfbnode_create(void); -static void jpc_tsfbnode_destroy(jpc_tsfbnode_t *node); -static void jpc_tsfbnode_synthesize(jpc_tsfbnode_t *node, int flags, jas_seq2d_t *x); -static void jpc_tsfbnode_analyze(jpc_tsfbnode_t *node, int flags, jas_seq2d_t *x); -static void qmfb2d_getbands(jpc_qmfb1d_t *hqmfb, jpc_qmfb1d_t *vqmfb, - uint_fast32_t xstart, uint_fast32_t ystart, uint_fast32_t xend, - uint_fast32_t yend, int maxbands, int *numbandsptr, jpc_tsfbnodeband_t *bands); -static void jpc_tsfbnode_getbandstree(jpc_tsfbnode_t *node, uint_fast32_t posxstart, - uint_fast32_t posystart, uint_fast32_t xstart, uint_fast32_t ystart, - uint_fast32_t xend, uint_fast32_t yend, jpc_tsfb_band_t **bands); -static int jpc_tsfbnode_findchild(jpc_tsfbnode_t *parnode, jpc_tsfbnode_t *cldnode); -static int jpc_tsfbnode_getequivfilters(jpc_tsfbnode_t *tsfbnode, int cldind, - int width, int height, jas_seq_t **vfilter, jas_seq_t **hfilter); - -/******************************************************************************\ -* -\******************************************************************************/ - -jpc_tsfb_t *jpc_tsfb_wavelet(jpc_qmfb1d_t *hqmfb, jpc_qmfb1d_t *vqmfb, int numdlvls) -{ - jpc_tsfb_t *tsfb; - int dlvlno; - jpc_tsfbnode_t *curnode; - jpc_tsfbnode_t *prevnode; - int childno; - if (!(tsfb = jpc_tsfb_create())) { - return 0; - } - prevnode = 0; - for (dlvlno = 0; dlvlno < numdlvls; ++dlvlno) { - if (!(curnode = jpc_tsfbnode_create())) { - jpc_tsfb_destroy(tsfb); - return 0; - } - if (prevnode) { - prevnode->children[0] = curnode; - ++prevnode->numchildren; - curnode->parent = prevnode; - } else { - tsfb->root = curnode; - curnode->parent = 0; - } - if (hqmfb) { - curnode->numhchans = jpc_qmfb1d_getnumchans(hqmfb); - if (!(curnode->hqmfb = jpc_qmfb1d_copy(hqmfb))) { - jpc_tsfb_destroy(tsfb); - return 0; - } - } else { - curnode->hqmfb = 0; - curnode->numhchans = 1; - } - if (vqmfb) { - curnode->numvchans = jpc_qmfb1d_getnumchans(vqmfb); - if (!(curnode->vqmfb = jpc_qmfb1d_copy(vqmfb))) { - jpc_tsfb_destroy(tsfb); - return 0; - } - } else { - curnode->vqmfb = 0; - curnode->numvchans = 1; - } - curnode->maxchildren = curnode->numhchans * curnode->numvchans; - for (childno = 0; childno < curnode->maxchildren; - ++childno) { - curnode->children[childno] = 0; - } - prevnode = curnode; - } - return tsfb; -} - -static jpc_tsfb_t *jpc_tsfb_create() -{ - jpc_tsfb_t *tsfb; - if (!(tsfb = jas_malloc(sizeof(jpc_tsfb_t)))) { - return 0; - } - tsfb->root = 0; - return tsfb; -} - -void jpc_tsfb_destroy(jpc_tsfb_t *tsfb) -{ - if (tsfb->root) { - jpc_tsfbnode_destroy(tsfb->root); - } - jas_free(tsfb); -} - -/******************************************************************************\ -* -\******************************************************************************/ - -void jpc_tsfb_analyze(jpc_tsfb_t *tsfb, int flags, jas_seq2d_t *x) -{ - if (tsfb->root) { - jpc_tsfbnode_analyze(tsfb->root, flags, x); - } -} - -static void jpc_tsfbnode_analyze(jpc_tsfbnode_t *node, int flags, jas_seq2d_t *x) -{ - jpc_tsfbnodeband_t nodebands[JPC_TSFB_MAXBANDSPERNODE]; - int numbands; - jas_seq2d_t *y; - int bandno; - jpc_tsfbnodeband_t *band; - - if (node->vqmfb) { - jpc_qmfb1d_analyze(node->vqmfb, flags | JPC_QMFB1D_VERT, x); - } - if (node->hqmfb) { - jpc_qmfb1d_analyze(node->hqmfb, flags, x); - } - if (node->numchildren > 0) { - qmfb2d_getbands(node->hqmfb, node->vqmfb, jas_seq2d_xstart(x), - jas_seq2d_ystart(x), jas_seq2d_xend(x), jas_seq2d_yend(x), - JPC_TSFB_MAXBANDSPERNODE, &numbands, nodebands); - y = jas_seq2d_create(0, 0, 0, 0); - assert(y); - for (bandno = 0, band = nodebands; bandno < numbands; ++bandno, ++band) { - if (node->children[bandno]) { - if (band->xstart != band->xend && band->ystart != band->yend) { - jas_seq2d_bindsub(y, x, band->locxstart, band->locystart, - band->locxend, band->locyend); - jas_seq2d_setshift(y, band->xstart, band->ystart); - jpc_tsfbnode_analyze(node->children[bandno], flags, y); - } - } - } - jas_matrix_destroy(y); - } -} - -void jpc_tsfb_synthesize(jpc_tsfb_t *tsfb, int flags, jas_seq2d_t *x) -{ - if (tsfb->root) { - jpc_tsfbnode_synthesize(tsfb->root, flags, x); - } -} - -static void jpc_tsfbnode_synthesize(jpc_tsfbnode_t *node, int flags, jas_seq2d_t *x) -{ - jpc_tsfbnodeband_t nodebands[JPC_TSFB_MAXBANDSPERNODE]; - int numbands; - jas_seq2d_t *y; - int bandno; - jpc_tsfbnodeband_t *band; - - if (node->numchildren > 0) { - qmfb2d_getbands(node->hqmfb, node->vqmfb, jas_seq2d_xstart(x), - jas_seq2d_ystart(x), jas_seq2d_xend(x), jas_seq2d_yend(x), - JPC_TSFB_MAXBANDSPERNODE, &numbands, nodebands); - y = jas_seq2d_create(0, 0, 0, 0); - for (bandno = 0, band = nodebands; bandno < numbands; ++bandno, ++band) { - if (node->children[bandno]) { - if (band->xstart != band->xend && band->ystart != band->yend) { - jas_seq2d_bindsub(y, x, band->locxstart, band->locystart, - band->locxend, band->locyend); - jas_seq2d_setshift(y, band->xstart, band->ystart); - jpc_tsfbnode_synthesize(node->children[bandno], flags, y); - } - } - } - jas_seq2d_destroy(y); - } - if (node->hqmfb) { - jpc_qmfb1d_synthesize(node->hqmfb, flags, x); - } - if (node->vqmfb) { - jpc_qmfb1d_synthesize(node->vqmfb, flags | JPC_QMFB1D_VERT, x); - } -} - -/******************************************************************************\ -* -\******************************************************************************/ - - -int jpc_tsfb_getbands(jpc_tsfb_t *tsfb, uint_fast32_t xstart, uint_fast32_t ystart, - uint_fast32_t xend, uint_fast32_t yend, jpc_tsfb_band_t *bands) -{ - jpc_tsfb_band_t *savbands; - savbands = bands; - if (!tsfb->root) { - bands[0].xstart = xstart; - bands[0].ystart = ystart; - bands[0].xend = xend; - bands[0].yend = yend; - bands[0].locxstart = xstart; - bands[0].locystart = ystart; - bands[0].locxend = xend; - bands[0].locyend = yend; - bands[0].orient = JPC_TSFB_LL; - bands[0].synenergywt = JPC_FIX_ONE; - ++bands; - } else { - jpc_tsfbnode_getbandstree(tsfb->root, xstart, ystart, - xstart, ystart, xend, yend, &bands); - } - return bands - savbands; -} - -static void jpc_tsfbnode_getbandstree(jpc_tsfbnode_t *node, uint_fast32_t posxstart, - uint_fast32_t posystart, uint_fast32_t xstart, uint_fast32_t ystart, - uint_fast32_t xend, uint_fast32_t yend, jpc_tsfb_band_t **bands) -{ - jpc_tsfbnodeband_t nodebands[JPC_TSFB_MAXBANDSPERNODE]; - jpc_tsfbnodeband_t *nodeband; - int nodebandno; - int numnodebands; - jpc_tsfb_band_t *band; - jas_seq_t *hfilter; - jas_seq_t *vfilter; - - qmfb2d_getbands(node->hqmfb, node->vqmfb, xstart, ystart, xend, yend, - JPC_TSFB_MAXBANDSPERNODE, &numnodebands, nodebands); - if (node->numchildren > 0) { - for (nodebandno = 0, nodeband = nodebands; - nodebandno < numnodebands; ++nodebandno, ++nodeband) { - if (node->children[nodebandno]) { - jpc_tsfbnode_getbandstree(node->children[ - nodebandno], posxstart + - nodeband->locxstart - xstart, posystart + - nodeband->locystart - ystart, nodeband->xstart, - nodeband->ystart, nodeband->xend, - nodeband->yend, bands); - - } - } - } -assert(numnodebands == 4 || numnodebands == 3); - for (nodebandno = 0, nodeband = nodebands; nodebandno < numnodebands; - ++nodebandno, ++nodeband) { - if (!node->children[nodebandno]) { - band = *bands; - band->xstart = nodeband->xstart; - band->ystart = nodeband->ystart; - band->xend = nodeband->xend; - band->yend = nodeband->yend; - band->locxstart = posxstart + nodeband->locxstart - - xstart; - band->locystart = posystart + nodeband->locystart - - ystart; - band->locxend = band->locxstart + band->xend - - band->xstart; - band->locyend = band->locystart + band->yend - - band->ystart; - if (numnodebands == 4) { - switch (nodebandno) { - case 0: - band->orient = JPC_TSFB_LL; - break; - case 1: - band->orient = JPC_TSFB_HL; - break; - case 2: - band->orient = JPC_TSFB_LH; - break; - case 3: - band->orient = JPC_TSFB_HH; - break; - default: - abort(); - break; - } - } else { - switch (nodebandno) { - case 0: - band->orient = JPC_TSFB_HL; - break; - case 1: - band->orient = JPC_TSFB_LH; - break; - case 2: - band->orient = JPC_TSFB_HH; - break; - default: - abort(); - break; - } - } - jpc_tsfbnode_getequivfilters(node, nodebandno, band->xend - band->xstart, band->yend - band->ystart, &hfilter, &vfilter); - band->synenergywt = jpc_fix_mul(jpc_seq_norm(hfilter), - jpc_seq_norm(vfilter)); - jas_seq_destroy(hfilter); - jas_seq_destroy(vfilter); - ++(*bands); - } - } -} - -/******************************************************************************\ -* -\******************************************************************************/ - -static jpc_tsfbnode_t *jpc_tsfbnode_create() -{ - jpc_tsfbnode_t *node; - if (!(node = jas_malloc(sizeof(jpc_tsfbnode_t)))) { - return 0; - } - node->numhchans = 0; - node->numvchans = 0; - node->numchildren = 0; - node->maxchildren = 0; - node->hqmfb = 0; - node->vqmfb = 0; - node->parent = 0; - return node; -} - -static void jpc_tsfbnode_destroy(jpc_tsfbnode_t *node) -{ - jpc_tsfbnode_t **child; - int childno; - for (childno = 0, child = node->children; childno < node->maxchildren; - ++childno, ++child) { - if (*child) { - jpc_tsfbnode_destroy(*child); - } - } - if (node->hqmfb) { - jpc_qmfb1d_destroy(node->hqmfb); - } - if (node->vqmfb) { - jpc_qmfb1d_destroy(node->vqmfb); - } - jas_free(node); -} - - - - - - - - -static void qmfb2d_getbands(jpc_qmfb1d_t *hqmfb, jpc_qmfb1d_t *vqmfb, - uint_fast32_t xstart, uint_fast32_t ystart, uint_fast32_t xend, - uint_fast32_t yend, int maxbands, int *numbandsptr, jpc_tsfbnodeband_t *bands) -{ - jpc_qmfb1dband_t hbands[JPC_QMFB1D_MAXCHANS]; - jpc_qmfb1dband_t vbands[JPC_QMFB1D_MAXCHANS]; - int numhbands; - int numvbands; - int numbands; - int bandno; - int hbandno; - int vbandno; - jpc_tsfbnodeband_t *band; - - if (hqmfb) { - jpc_qmfb1d_getbands(hqmfb, 0, xstart, ystart, xend, yend, - JPC_QMFB1D_MAXCHANS, &numhbands, hbands); - } else { - numhbands = 1; - hbands[0].start = xstart; - hbands[0].end = xend; - hbands[0].locstart = xstart; - hbands[0].locend = xend; - } - if (vqmfb) { - jpc_qmfb1d_getbands(vqmfb, JPC_QMFB1D_VERT, xstart, ystart, xend, - yend, JPC_QMFB1D_MAXCHANS, &numvbands, vbands); - } else { - numvbands = 1; - vbands[0].start = ystart; - vbands[0].end = yend; - vbands[0].locstart = ystart; - vbands[0].locend = yend; - } - numbands = numhbands * numvbands; - *numbandsptr = numbands; - for (bandno = 0, band = bands; bandno < numbands; ++bandno, ++band) { - hbandno = bandno % numhbands; - vbandno = bandno / numhbands; - band->xstart = hbands[hbandno].start; - band->ystart = vbands[vbandno].start; - band->xend = hbands[hbandno].end; - band->yend = vbands[vbandno].end; - band->locxstart = hbands[hbandno].locstart; - band->locystart = vbands[vbandno].locstart; - band->locxend = hbands[hbandno].locend; - band->locyend = vbands[vbandno].locend; - assert(band->xstart <= band->xend && - band->ystart <= band->yend); - if (band->xstart == band->xend) { - band->yend = band->ystart; - band->locyend = band->locystart; - } else if (band->ystart == band->yend) { - band->xend = band->xstart; - band->locxend = band->locxstart; - } - } -} - -static int jpc_tsfbnode_getequivfilters(jpc_tsfbnode_t *tsfbnode, int cldind, - int width, int height, jas_seq_t **hfilter, jas_seq_t **vfilter) -{ - jas_seq_t *hseq; - jas_seq_t *vseq; - jpc_tsfbnode_t *node; - jas_seq2d_t *hfilters[JPC_QMFB1D_MAXCHANS]; - jas_seq2d_t *vfilters[JPC_QMFB1D_MAXCHANS]; - int numhchans; - int numvchans; - jas_seq_t *tmpseq; - - hseq = 0; - vseq = 0; - - if (!(hseq = jas_seq_create(0, 1))) { - goto error; - } - jas_seq_set(hseq, 0, jpc_inttofix(1)); - if (!(vseq = jas_seq_create(0, 1))) { - goto error; - } - jas_seq_set(vseq, 0, jpc_inttofix(1)); - - node = tsfbnode; - while (node) { - if (node->hqmfb) { - numhchans = jpc_qmfb1d_getnumchans(node->hqmfb); - if (jpc_qmfb1d_getsynfilters(node->hqmfb, width, hfilters)) { - goto error; - } - if (!(tmpseq = jpc_seq_upsample(hseq, numhchans))) { - goto error; - } - jas_seq_destroy(hseq); - hseq = tmpseq; - if (!(tmpseq = jpc_seq_conv(hseq, hfilters[bandnotohind(node, cldind)]))) { - goto error; - } - jas_seq_destroy(hfilters[0]); - jas_seq_destroy(hfilters[1]); - jas_seq_destroy(hseq); - hseq = tmpseq; - } - if (node->vqmfb) { - numvchans = jpc_qmfb1d_getnumchans(node->vqmfb); - if (jpc_qmfb1d_getsynfilters(node->vqmfb, height, vfilters)) { - abort(); - } - if (!(tmpseq = jpc_seq_upsample(vseq, numvchans))) { - goto error; - } - jas_seq_destroy(vseq); - vseq = tmpseq; - if (!(tmpseq = jpc_seq_conv(vseq, vfilters[bandnotovind(node, cldind)]))) { - goto error; - } - jas_seq_destroy(vfilters[0]); - jas_seq_destroy(vfilters[1]); - jas_seq_destroy(vseq); - vseq = tmpseq; - } - if (node->parent) { - cldind = jpc_tsfbnode_findchild(node->parent, node); - } - node = node->parent; - } - - *hfilter = hseq; - *vfilter = vseq; - - return 0; - -error: - if (hseq) { - jas_seq_destroy(hseq); - } - if (vseq) { - jas_seq_destroy(vseq); - } - return -1; - -} - -static int jpc_tsfbnode_findchild(jpc_tsfbnode_t *parnode, jpc_tsfbnode_t *cldnode) -{ - int i; - - for (i = 0; i < parnode->maxchildren; i++) { - if (parnode->children[i] == cldnode) - return i; - } - assert(0); - return -1; -} - -jpc_tsfb_t *jpc_cod_gettsfb(int qmfbid, int numlevels) -{ - jpc_tsfb_t *tsfb; - - switch (qmfbid) { - case JPC_COX_RFT: - qmfbid = JPC_QMFB1D_FT; - break; - case JPC_COX_INS: - qmfbid = JPC_QMFB1D_NS; - break; - default: - assert(0); - qmfbid = 10; - break; - } - -{ - jpc_qmfb1d_t *hqmfb; - hqmfb = jpc_qmfb1d_make(qmfbid); - assert(hqmfb); - tsfb = jpc_tsfb_wavelet(hqmfb, hqmfb, numlevels); - assert(tsfb); - jpc_qmfb1d_destroy(hqmfb); -} - - return tsfb; -} diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_tsfb.h b/converter/other/jpeg2000/libjasper/jpc/jpc_tsfb.h deleted file mode 100644 index 8670c22..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_tsfb.h +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * Tree-Structured Filter Bank (TSFB) Library - * - * $Id$ - */ - -#ifndef JPC_TSFB_H -#define JPC_TSFB_H - -/******************************************************************************\ -* Includes. -\******************************************************************************/ - -#include "jasper/jas_seq.h" - -#include "jpc_fix.h" -#include "jpc_qmfb.h" - -/******************************************************************************\ -* Constants. -\******************************************************************************/ - -#define JPC_TSFB_MAXBANDS (JPC_TSFB_MAXDEPTH * 3 + 1) -#define JPC_TSFB_MAXDEPTH 32 -#define JPC_TSFB_RITIMODE JPC_QMFB1D_RITIMODE - -#define JPC_TSFB_MAXBANDSPERNODE (JPC_QMFB1D_MAXCHANS * JPC_QMFB1D_MAXCHANS) - -#define JPC_TSFB_PRUNEVERT 0x01 -#define JPC_TSFB_PRUNEHORZ 0x02 - -#define JPC_TSFB_LL 0 -#define JPC_TSFB_LH 1 -#define JPC_TSFB_HL 2 -#define JPC_TSFB_HH 3 - -/******************************************************************************\ -* Types. -\******************************************************************************/ - -typedef struct { - - int xstart; - int ystart; - int xend; - int yend; - int locxstart; - int locystart; - int locxend; - int locyend; - -} jpc_tsfbnodeband_t; - -typedef struct jpc_tsfbnode_s { - - int numhchans; - int numvchans; - jpc_qmfb1d_t *hqmfb; - jpc_qmfb1d_t *vqmfb; - int maxchildren; - int numchildren; - struct jpc_tsfbnode_s *children[JPC_TSFB_MAXBANDSPERNODE]; - struct jpc_tsfbnode_s *parent; - -} jpc_tsfbnode_t; - -typedef struct { - jpc_tsfbnode_t *root; -} jpc_tsfb_t; - -typedef struct { - int xstart; - int ystart; - int xend; - int yend; - int orient; - int locxstart; - int locystart; - int locxend; - int locyend; - jpc_fix_t synenergywt; -} jpc_tsfb_band_t; - -/******************************************************************************\ -* Functions. -\******************************************************************************/ - -/* Create a TSFB. */ -jpc_tsfb_t *jpc_cod_gettsfb(int qmfbid, int numlevels); - -/* Create a wavelet-type TSFB with the specified horizontal and vertical - QMFBs. */ -jpc_tsfb_t *jpc_tsfb_wavelet(jpc_qmfb1d_t *hqmfb, jpc_qmfb1d_t *vqmfb, - int numdlvls); - -/* Destroy a TSFB. */ -void jpc_tsfb_destroy(jpc_tsfb_t *tsfb); - -/* Perform analysis. */ -void jpc_tsfb_analyze(jpc_tsfb_t *tsfb, int flags, jas_seq2d_t *x); - -/* Perform synthesis. */ -void jpc_tsfb_synthesize(jpc_tsfb_t *tsfb, int flags, jas_seq2d_t *x); - -/* Get band information for a TSFB. */ -int jpc_tsfb_getbands(jpc_tsfb_t *tsfb, uint_fast32_t xstart, - uint_fast32_t ystart, uint_fast32_t xend, uint_fast32_t yend, - jpc_tsfb_band_t *bands); - -#endif diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_util.c b/converter/other/jpeg2000/libjasper/jpc/jpc_util.c deleted file mode 100644 index 08ac238..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_util.c +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Copyright (c) 1999-2000 Image Power, Inc. and the University of - * British Columbia. - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -/* - * $Id$ - */ - -/******************************************************************************\ -* Includes -\******************************************************************************/ - -#include -#include -#include -#include -#include -#include - -#include "jasper/jas_math.h" -#include "jasper/jas_malloc.h" - -#include "jpc_fix.h" -#include "jpc_cs.h" -#include "jpc_flt.h" -#include "jpc_util.h" - -/******************************************************************************\ -* Miscellaneous Functions -\******************************************************************************/ - -int jpc_atoaf(const char *s, int *numvalues, double **values) -{ - static char delim[] = ", \t\n"; - char buf[4096]; - int n; - double *vs; - char *cp; - - strncpy(buf, s, sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - n = 0; - if ((cp = strtok(buf, delim))) { - ++n; - while ((cp = strtok(0, delim))) { - if (*cp != '\0') { - ++n; - } - } - } - - if (n) { - if (!(vs = jas_malloc(n * sizeof(double)))) { - return -1; - } - - strncpy(buf, s, sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - n = 0; - if ((cp = strtok(buf, delim))) { - vs[n] = atof(cp); - ++n; - while ((cp = strtok(0, delim))) { - if (*cp != '\0') { - vs[n] = atof(cp); - ++n; - } - } - } - } else { - vs = 0; - } - - *numvalues = n; - *values = vs; - - return 0; -} - -jas_seq_t *jpc_seq_upsample(jas_seq_t *x, int m) -{ - jas_seq_t *z; - int i; - - if (!(z = jas_seq_create(jas_seq_start(x) * m, (jas_seq_end(x) - 1) * m + 1))) - return 0; - for (i = jas_seq_start(z); i < jas_seq_end(z); i++) { - *jas_seq_getref(z, i) = (!JAS_MOD(i, m)) ? jas_seq_get(x, i / m) : - jpc_inttofix(0); - } - - return z; -} - -jpc_fix_t jpc_seq_norm(jas_seq_t *x) -{ - jpc_fix_t s; - int i; - - s = jpc_inttofix(0); - for (i = jas_seq_start(x); i < jas_seq_end(x); i++) { - s = jpc_fix_add(s, jpc_fix_mul(jas_seq_get(x, i), jas_seq_get(x, i))); - } - - return jpc_dbltofix(sqrt(jpc_fixtodbl(s))); -} - -jas_seq_t *jpc_seq_conv(jas_seq_t *x, jas_seq_t *y) -{ - int i; - int j; - int k; - jas_seq_t *z; - jpc_fix_t s; - jpc_fix_t v; - - z = jas_seq_create(jas_seq_start(x) + jas_seq_start(y), - jas_seq_end(x) + jas_seq_end(y) - 1); - assert(z); - for (i = jas_seq_start(z); i < jas_seq_end(z); i++) { - s = jpc_inttofix(0); - for (j = jas_seq_start(y); j < jas_seq_end(y); j++) { - k = i - j; - if (k < jas_seq_start(x) || k >= jas_seq_end(x)) { - v = JPC_FIX_ZERO; - } else { - v = jas_seq_get(x, k); - } - s = jpc_fix_add(s, jpc_fix_mul(jas_seq_get(y, j), v)); - } - *jas_seq_getref(z, i) = s; - } - - return z; -} diff --git a/converter/other/jpeg2000/libjasper/jpc/jpc_util.h b/converter/other/jpeg2000/libjasper/jpc/jpc_util.h deleted file mode 100644 index c23fc33..0000000 --- a/converter/other/jpeg2000/libjasper/jpc/jpc_util.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2001-2002 Michael David Adams. - * All rights reserved. - */ - -/* __START_OF_JASPER_LICENSE__ - * - * JasPer Software License - * - * IMAGE POWER JPEG-2000 PUBLIC LICENSE - * ************************************ - * - * GRANT: - * - * Permission is hereby granted, free of charge, to any person (the "User") - * obtaining a copy of this software and associated documentation, to deal - * in the JasPer Software without restriction, including without limitation - * the right to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the JasPer Software (in source and binary forms), - * and to permit persons to whom the JasPer Software is furnished to do so, - * provided further that the License Conditions below are met. - * - * License Conditions - * ****************** - * - * A. Redistributions of source code must retain the above copyright notice, - * and this list of conditions, and the following disclaimer. - * - * B. Redistributions in binary form must reproduce the above copyright - * notice, and this list of conditions, and the following disclaimer in - * the documentation and/or other materials provided with the distribution. - * - * C. Neither the name of Image Power, Inc. nor any other contributor - * (including, but not limited to, the University of British Columbia and - * Michael David Adams) may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * D. User agrees that it shall not commence any action against Image Power, - * Inc., the University of British Columbia, Michael David Adams, or any - * other contributors (collectively "Licensors") for infringement of any - * intellectual property rights ("IPR") held by the User in respect of any - * technology that User owns or has a right to license or sublicense and - * which is an element required in order to claim compliance with ISO/IEC - * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property - * rights worldwide arising under statutory or common law, and whether - * or not perfected, including, without limitation, all (i) patents and - * patent applications owned or licensable by User; (ii) rights associated - * with works of authorship including copyrights, copyright applications, - * copyright registrations, mask work rights, mask work applications, - * mask work registrations; (iii) rights relating to the protection of - * trade secrets and confidential information; (iv) any right analogous - * to those set forth in subsections (i), (ii), or (iii) and any other - * proprietary rights relating to intangible property (other than trademark, - * trade dress, or service mark rights); and (v) divisions, continuations, - * renewals, reissues and extensions of the foregoing (as and to the extent - * applicable) now existing, hereafter filed, issued or acquired. - * - * E. If User commences an infringement action against any Licensor(s) then - * such Licensor(s) shall have the right to terminate User's license and - * all sublicenses that have been granted hereunder by User to other parties. - * - * F. This software is for use only in hardware or software products that - * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license - * or right to this Software is granted for products that do not comply - * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased - * from the ISO. - * - * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. - * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER - * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND - * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY - * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, - * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, - * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING - * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE - * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING - * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE - * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE - * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY - * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY - * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, - * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, - * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE - * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., - * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE - * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO - * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, - * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR - * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF - * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY - * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT - * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR - * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING - * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, - * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT - * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE - * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY - * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE - * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS - * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT - * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING - * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS - * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE - * NOTICE SPECIFIED IN THIS SECTION. - * - * __END_OF_JASPER_LICENSE__ - */ - -#ifndef JPC_UTIL_H -#define JPC_UTIL_H - -/* Parse a comma separated list of real numbers into an array of doubles. */ -int jpc_atoaf(const char *s, int *numvalues, double **values); - -/* Upsample a sequence. */ -jas_seq_t *jpc_seq_upsample(jas_seq_t *seq, int n); - -/* Convolve two sequences. */ -jas_seq_t *jpc_seq_conv(jas_seq_t *seq0, jas_seq_t *seq1); - -/* Compute the norm of a sequence. */ -jpc_fix_t jpc_seq_norm(jas_seq_t *x); - -#endif