diff --git a/Makefile b/Makefile index 68da5b1..17927ed 100644 --- a/Makefile +++ b/Makefile @@ -64,10 +64,12 @@ BACKEND_NAME ?= gutenprint5X+usb # Libraries: LIBS6145_NAME = lib6145/libS6145ImageReProcess.$(LIB_SUFFIX) LIBS6145_SOURCES = lib6145/libS6145ImageReProcess.c +LIBS2245_NAME = lib2245/libS2245ImageReProcess.$(LIB_SUFFIX) +LIBS2245_SOURCES = lib2245/libS2245ImageReProcess.c LIB70X_NAME ?= lib70x/libMitsuD70ImageReProcess.$(LIB_SUFFIX) LIB70X_SOURCES = lib70x/libMitsuD70ImageReProcess.c -LIBRARIES = $(LIBS6145_NAME) $(LIB70X_NAME) +LIBRARIES = $(LIBS6145_NAME) $(LIB70X_NAME) $(LIBS2245_NAME) # Tools CC ?= $(CROSS_COMPILE)gcc @@ -90,7 +92,8 @@ E=true endif # Flags -CFLAGS += -Wall -Wextra -Wformat-security -funit-at-a-time -g -Og -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -std=c99 -D_POSIX_C_SOURCE=200809L # -Wconversion +CFLAGS += -Wall -Wextra -Wformat-security -funit-at-a-time -g -Og -D_FORTIFY_SOU +RCE=2 -D_GNU_SOURCE -std=c99 -D_POSIX_C_SOURCE=200809L # -Wconversion LDFLAGS += $(shell pkg-config $(PKG_CONFIG_EXTRA) --libs libusb-1.0) CPPFLAGS += $(shell pkg-config $(PKG_CONFIG_EXTRA) --cflags libusb-1.0) # CPPFLAGS += -DLIBUSB_PRE_1_0_10 @@ -247,3 +250,7 @@ $(LIB70X_NAME): $(LIB70X_SOURCES:.c=.o) $(LIBS6145_NAME): $(LIBS6145_SOURCES:.c=.o) @$(E) " CCLD " $@ $(Q)$(CC) $(LIBLDFLAGS) -o $@ $^ + +$(LIBS2245_NAME): $(LIBS2245_SOURCES:.c=.o) + @$(E) " CCLD " $@ + $(Q)$(CC) $(LIBLDFLAGS) -o $@ $^ diff --git a/lib2245/COPYING b/lib2245/COPYING new file mode 100644 index 0000000..94a9ed0 --- /dev/null +++ b/lib2245/COPYING @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/lib2245/Makefile b/lib2245/Makefile new file mode 100644 index 0000000..9b81161 --- /dev/null +++ b/lib2245/Makefile @@ -0,0 +1,48 @@ +# Basic stuff +LIBS2245_NAME ?= S2245ImageReProcess + +# Destination directories +DESTDIR ?= +LIBDIR ?= $(DESTDIR)/usr/local/lib + +# Tools +CC ?= $(CROSS_COMPILE)gcc +CPPCHECK ?= cppcheck +MKDIR ?= mkdir +INSTALL ?= install +RM ?= rm + +# Flags +CFLAGS += -Wall -Wextra -g -Os -std=c99 -D_FORTIFY_SOURCE=2 -fPIC --no-strict-overflow # -Wconversion +#LDFLAGS += +#CPPFLAGS += +CFLAGS += -funit-at-a-time + +ifneq (,$(findstring mingw,$(CC))) +SUFFIX=dll +else +SUFFIX=so +endif + +# Build stuff +SOURCES = libS2245ImageReProcess.c + +# And now the rules! +.PHONY: clean all install cppcheck + +all: lib$(LIBS2245_NAME).$(SUFFIX) + +cppcheck: + $(CPPCHECK) -q -v --std=c99 --enable=all -I/usr/include $(CPPFLAGS) $(SOURCES) + +install: + $(MKDIR) -p $(LIBDIR) + $(INSTALL) -o root -m 755 lib$(LIBS2245_NAME).$(SUFFIX) $(LIBDIR) +clean: + $(RM) -f lib$(LIBS6145_NAME).$(SUFFIX) *.o + +lib$(LIBS2245_NAME).$(SUFFIX): $(SOURCES:.c=.o) + $(CC) $(LDFLAGS) -g -shared -o $@ $^ + +%.o: %.c + $(CC) -c $(CFLAGS) -o $@ $< diff --git a/lib2245/libS2245ImageReProcess.c b/lib2245/libS2245ImageReProcess.c new file mode 100644 index 0000000..3b1da25 --- /dev/null +++ b/lib2245/libS2245ImageReProcess.c @@ -0,0 +1,1728 @@ +/* + libS2245ImageReProcess -- Re-implemented Image Processing library for + the Sinfonia CHC-S2245 printer family + + Copyright (c) 2020 Solomon Peachy + + ** ** ** ** Do NOT contact Sinfonia about this library! ** ** ** ** + + This is intended to be a drop-in replacement for Sinfonia's proprietary + libS225IP library, which is necessary in order to utilize their + CHC-S2245 printer family. + + Sinfonia Inc was not involved in the creation of this library, and + is not responsible in any way for the library or any deficiencies in + its output. They will provide no support if it is used. + + If you have the appropriate permission fron Sinfonia, we recommend + you use their official libS2245IP library instead, as it + will generate the highest quality output. However, it is only + available for x86/x86_64 targets on Windows. Please contact your local + Sinfonia distributor to obtain the official library. + + ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . + + SPDX-License-Identifier: GPL-3.0+ + +*/ + +#define LIB_VERSION "0.1.0" + +#include +#include +#include +#include +#include +#include + +#define USE_EXTRA_STUFF // For extensions made to the base library + +//------------------------------------------------------------------------- +// Exported Functions + +bool ip_imageProc(uint16_t *destData, uint8_t *srcInRgb, + uint16_t width, uint16_t height, void *srcIpp); + +bool ip_checkIpp(uint16_t width, uint16_t height, void *srcIpp); + +bool ip_getMemorySize(uint32_t *szMemory, + uint16_t width, uint16_t height, + void *srcIpp); + +//------------------------------------------------------------------------- +// Endian Manipulation macros +#if (__BYTE_ORDER == __LITTLE_ENDIAN) +#define le16_to_cpu(__x) __x +#define le32_to_cpu(__x) __x +#define be16_to_cpu(__x) __builtin_bswap16(__x) +#define be32_to_cpu(__x) __builtin_bswap32(__x) +#else +#define le16_to_cpu(__x) __builtin_bswap16(__x) +#define le32_to_cpu(__x) __builtin_bswap32(__x) +#define be16_to_cpu(__x) __x +#define be32_to_cpu(__x) __x +#endif + +#define cpu_to_le16 le16_to_cpu +#define cpu_to_le32 le32_to_cpu +#define cpu_to_be16 be16_to_cpu +#define cpu_to_be32 be32_to_cpu + +//------------------------------------------------------------------------- +// External data formats + +struct ippHeatCorr { + int32_t tankDivisor[4]; + int32_t tankRowInitVals[4]; + int32_t tankRowOldInitVals[4]; + int32_t tankCoef[5]; + int32_t tankPlusParam; + int32_t tankMinusParam; + int32_t tankPlusLimit; + int32_t tankMinusLimit; + int32_t useHeatCorrection; + uint8_t pad_0x58[40]; +} __attribute__((packed)); + +struct SIppData { + uint16_t field_0x0; // see getMaxPulse + uint16_t field_0x2; // see getMaxPulse + uint16_t maxLineSum; + uint16_t minRowSum; + uint16_t maxLineCorrectionFactor; + uint16_t nextWeight; + uint16_t prevWeight; + uint16_t mtfPreCalcCutoff; + uint16_t autoGenMode; + uint8_t autoGenBase[2]; + uint8_t pad_0x14[6]; + uint16_t pulseExMap[256]; + uint8_t pad_0x21a[2]; + struct ippHeatCorr heatCorrection; + int16_t heatCorrectionMinusTable[256]; + int16_t heatCorrectionPlusTable[256]; + uint16_t lineCorrection[256]; + uint8_t sideEdgeCorrectionComp[64]; + uint8_t sideEdgeCorrectionTable[256]; +} __attribute__((packed)); + +struct ippHeader { + char model[16]; + char ipp[4]; + uint8_t version; + uint8_t pad_0x15[43]; +} __attribute__((packed)); + +struct ippConf { + uint16_t width; /* Overridden at runtime */ + uint16_t height; /* Overridden at runtime */ + uint16_t headWidth; // Always 1920 + uint8_t planes; // 3 or 4, can be up to 16! + uint8_t printmode; // Corresponds to corrdata_req field 1 + uint8_t corrections1; // Corresponds to corrdata_req field 2 + uint8_t corrections2; // B0,B1,B2 + uint8_t borderCapable; // 0x02 if we can do 5x7-on-6x8 + uint8_t pad_0xb[21]; + uint8_t planeOrder[16]; + uint8_t pad_0x30[16]; +} __attribute__((packed)); + +struct ippData { + struct ippHeader header; + struct ippConf conf; + struct SIppData plane_rc; + struct SIppData plane_gm; + struct SIppData plane_by; + struct SIppData plane_oc; + // Can have up to 16 planes, think about this. +} __attribute__((packed)); + +//------------------------------------------------------------------------- +// Private Structures + +struct CHeatCorrProc { + struct SIppData ippData; + struct ippHeatCorr heatCorrection; + uint16_t width; + uint16_t height; + uint16_t headWidth; +// uint16_t pad_0xa62; + int32_t lineStartOffset; // always 0 + uint16_t maxPulse; + uint16_t tankWidth; +// uint8_t pad_0xa6c[4]; + int16_t *tankBuf; + int16_t *tankRowSrc; + int32_t *tankRowPtrs[2]; + int32_t *tankRowBufs[5]; + uint32_t curRow; + uint8_t initialized; +}; + +struct CIppMng { + struct ippHeader header; + struct ippConf conf; + struct SIppData *ippData; + uint8_t initialized; +}; + +struct CImageProc { + struct CIppMng *ippMng; + struct ippConf conf; + struct SIppData planeIPPdata; + uint32_t pixelsOCG; // width*height*3 + uint32_t pixelsOCM; // width*height*4 +// uint8_t pad_0xa2c[4]; + uint16_t *imageScratchDataPtr; + uint32_t imageDataLen; // width*height*4planes*2bpp +// uint8_t pad_0xa3c[4]; + uint16_t *imageDataPtr; + uint8_t planesOCG; + uint8_t planesOCM; + uint8_t currentPlane; + uint8_t correctMtf; + uint8_t correctHeat; + uint8_t correctLine; + uint8_t correctSideEdge; +// uint8_t pad_0xa4f; + uint32_t pixels; // width*height + int16_t mtfCorrPlaneTable[512]; + uint16_t srcWidth; + uint16_t srcHeight; +}; + +struct CMidDataGen { + struct SIppData *planeIppData; + uint8_t *outDataPtr; + uint8_t plane; + uint8_t pad; + uint16_t width; + uint16_t height; +}; + +struct crop_conf { + uint16_t startCol; + uint16_t startRow; + uint16_t numCols; + uint16_t numRows; +}; + +struct pic_data { + uint8_t *srcPtr; + uint16_t inCols; + uint16_t inRows; + uint16_t outCols; + uint16_t outRows; + uint8_t bytes_pp; +}; + +// Data format Sanity checks +#define STATIC_ASSERT(test_for_true) _Static_assert((test_for_true), "(" #test_for_true ") failed") + +STATIC_ASSERT(sizeof(struct ippData) == 10224); + +#undef STATIC_ASSERT + +//------------------------------------------------------------------------- +// Private data declarations + + +//------------------------------------------------------------------------- +// Private Function declarations + +/*** CIppMng ***/ +static void CIppMng_Init(struct CIppMng *this) +{ + memset(this, 0, sizeof(*this)); +} + +static void CIppMng_Cleanup(struct CIppMng *this) +{ + if (this->ippData) { + free(this->ippData); + this->ippData = NULL; + } +} + +static const char s2245HeaderModel[] = "CHC-S2245 "; +static const char s2245IppStr[] = "IPP="; + +static bool CIppMng_CheckHeader(struct CIppMng *this, struct ippData *ippData) + +{ + memcpy(&this->header, &ippData->header, sizeof(this->header)); + + if (memcmp(this->header.model, s2245HeaderModel, 16)) + return 0; + if (memcmp(this->header.ipp, s2245IppStr, 4)) + return 0; + if (this->header.version != 0x3) + return 0; + + return 1; +} + +static bool CIppMng_CheckConf(struct CIppMng *this, struct ippData *ippData) + +{ + uint8_t tmp; + +#ifndef USE_EXTRA_STUFF + memcpy(&this->conf, &ippData->conf, sizeof(this->conf)); +#else + (void)ippData; +#endif + + if (!this->conf.headWidth || !this->conf.planes) + return 0; + + /* OC mode, Glossy or matte */ + tmp = this->conf.printmode & 0x07; + if (tmp != 1 && tmp != 2) + return 0; + + /* Quality mode, 0 or 1*/ + tmp = (this->conf.printmode >> 3) & 3; + if (tmp > 1) + return 0; + + return 1; +} + +static bool CIppMng_CheckIpp(struct CIppMng *this, struct ippData *ippData) +{ + bool rval; + + rval = CIppMng_CheckHeader(this, ippData); + + if (rval) + rval = CIppMng_CheckConf(this, ippData); + + return rval; +} + +static bool CIppMng_SetConf(struct CIppMng *this, struct ippData *ippData, + uint16_t width, uint16_t height) + +{ + memcpy(&this->conf, &ippData->conf, sizeof(this->conf)); + + if (!width || !height) + return 0; + this->conf.width = width; + this->conf.height = height; + +#if (__BYTE_ORDER != __LITTLE_ENDIAN) + this->conf.headWidth = le16_to_cpu(this->conf.headWidth); +#endif + + return 1; +} + +static bool CIppMng_SetData(struct CIppMng *this, struct ippData *ippData) + +{ + if (this->ippData) + free(this->ippData); + + if (!this->conf.planes) + return 0; + + this->ippData = malloc(this->conf.planes * sizeof(*this->ippData)); + if (!this->ippData) + return 0; + + memcpy(this->ippData, &ippData->plane_rc, this->conf.planes * sizeof(*this->ippData)); + +#if (__BYTE_ORDER != __LITTLE_ENDIAN) +#define SWAP16(__x) __x = le16_to_cpu(ippBlock->__x) +#define SWAP32(__x) __x = le32_to_cpu(ippBlock->__x) + int i, j; + for (i = 0 ; i < this->conf.planes ; i++) { + struct SIppData *ippBlock = &ippData->plane_rc + i; + swap16(field_0x0); + swap16(field_0x2); + swap16(maxLineSum); + swap16(minRowSum); + swap16(maxLineCorrecitonFactor); + swap16(nextWeight); + swap16(prevWeight); + swap16(mtfPreCalcCutoff); + swap16(autoGenMode); + for (j = 0 ; j < 256 ; j++) { + swap16(pulseExMap[j]); + swap16(heatCorrectionMinusTable[j]); + swap16(heatCorrectionPlusTable[j]); + swap16(lineCorrection); + } + for (j = 0 ; j < 4 ; j++) { + swap32(heatCorrection.tankDivisor[j]); + swap32(heatCorrection.tankRowInitVals[j]); + swap32(heatCorrection.tankRowOldInitVals[j]); + } + for (j = 0 ; j < 5 ; j++) { + swap32(heatCorrection.tankCoef[j]); + } + swap32(tankPlusParam); + swap32(tankMinusParam); + swap32(tankPlusLimit); + swap32(tankMinusLimit); + swap32(useHeatCorrection); + } +#undef SWAP16 +#undef SWAP32 +#endif + + return 1; +} + +static bool CIppMng_SetIPP(struct CIppMng *this, struct ippData *ippData, + uint16_t width, uint16_t height) + +{ + bool rval; + + this->initialized = 0; + + rval = CIppMng_SetConf(this, ippData, width, height); + if (rval) + rval = CIppMng_CheckIpp(this, ippData); + if (rval) + rval = CIppMng_SetData(this, ippData); + if (rval) + this->initialized = 1; + + return rval; +} + +static bool CIppMng_GetNumOfColor(struct CIppMng *this, uint8_t *planesOCG, uint8_t *planesOCM) +{ + if (!this->initialized) + return 0; + + *planesOCG = 3; + *planesOCM = 4; + + return 1; +} + +static bool CIppMng_GetIppConf(struct CIppMng *this, struct ippConf *conf, + uint8_t *planesOCG, uint8_t *planesOCM) + +{ + if (!this->initialized) + return 0; + + memcpy(conf, &this->conf, sizeof(*conf)); + CIppMng_GetNumOfColor(this, planesOCG, planesOCM); + + return 1; +} + +static bool CIppMng_GetIppNo(struct CIppMng *this, uint8_t *planeOffset, uint8_t plane) +{ + if (!this->initialized || plane > 0x10) + return 0; + + *planeOffset = this->conf.planeOrder[plane]; + + return 1; +} + +static bool CIppMng_GetIppData(struct CIppMng *this, struct SIppData *destPtr, uint8_t planeOffset) + +{ + if (!this->initialized || planeOffset >= this->conf.planes) + return 0; + + memcpy(destPtr, &this->ippData[planeOffset], sizeof (*destPtr)); + + return 1; +} + +/*** CMidDataGen ***/ + +static void CMidDataGen_Init(struct CMidDataGen *this) +{ + this->planeIppData = NULL; +} + +static bool CMidDataGen_CheckAutoGenNo(struct CMidDataGen *this) + +{ + return (this->planeIppData->autoGenMode == 1 || // glossy + this->planeIppData->autoGenMode == 2); // matte +} + +static void CMidDataGen_GD01Proc(struct CMidDataGen *this, uint8_t *outDataPtr, + uint16_t width, uint16_t height, uint8_t *autoGenBase) +{ + memset(outDataPtr, *autoGenBase, height * width); + (void)this; +} + +static const uint8_t GD_02_MIDDATA[288] = { + 0xB3, 0xBD, 0x93, 0x27, 0xD6, 0x9F, 0xF6, 0xBD, 0xB3, 0x7D, 0xD6, 0x98, 0x36, 0xBD, 0x33, 0xBD, + 0x5C, 0xE2, 0x66, 0xA9, 0x3A, 0x0D, 0x7D, 0xFE, 0x4C, 0xEB, 0xC4, 0xED, 0xCD, 0xEC, 0x5D, 0xEF, + 0xD9, 0x8C, 0x9F, 0x89, 0x71, 0xAF, 0x5B, 0x4E, 0xB1, 0x1B, 0x31, 0xB9, 0xDB, 0x63, 0x36, 0x7A, + 0x87, 0x33, 0x11, 0xF3, 0xFC, 0xDF, 0xEE, 0x7D, 0xB7, 0xBE, 0x5F, 0x0E, 0xED, 0x6C, 0x92, 0x9C, + 0xDF, 0x78, 0xCD, 0xCE, 0xF1, 0x8C, 0xD1, 0x5F, 0x50, 0xEA, 0x9C, 0xFD, 0x5F, 0x53, 0x66, 0xFB, + 0x9F, 0x9C, 0x76, 0xFB, 0x6E, 0x3B, 0x47, 0xCE, 0x4E, 0xF9, 0xBA, 0x53, 0xFE, 0xFF, 0x7A, 0x7D, + 0x92, 0xD3, 0x7E, 0xF2, 0x73, 0x77, 0xD7, 0xD7, 0x36, 0xC7, 0x26, 0xC7, 0x57, 0xDC, 0x92, 0x99, + 0xF6, 0x19, 0x72, 0xC8, 0xFB, 0xBC, 0xFE, 0x3C, 0x3E, 0xEB, 0xF8, 0xA6, 0x76, 0xFE, 0x26, 0x7B, + 0xD8, 0xF6, 0x16, 0x63, 0xF2, 0xCA, 0xDF, 0x24, 0x16, 0x79, 0xF9, 0xCE, 0xD3, 0xEF, 0x93, 0x7D, + 0x1F, 0xE6, 0xD8, 0xE7, 0xCF, 0x5B, 0xF2, 0xE3, 0x97, 0x35, 0xF8, 0x48, 0xF6, 0x69, 0x36, 0x9D, + 0xF3, 0x47, 0x67, 0xCF, 0x76, 0x99, 0x13, 0xE7, 0x4F, 0x97, 0xF6, 0xF9, 0xCE, 0x27, 0x57, 0x94, + 0xCE, 0x4D, 0xCE, 0x39, 0xE5, 0x90, 0xFF, 0x0C, 0x03, 0xBB, 0xEC, 0xF9, 0x32, 0x9E, 0x77, 0xB2, + 0x8E, 0x79, 0x22, 0x87, 0xD1, 0xFE, 0xBA, 0x49, 0xCF, 0xE5, 0xCF, 0x7E, 0xFB, 0x8B, 0x09, 0x95, + 0xEC, 0xE6, 0x43, 0x3B, 0xF3, 0x9D, 0x69, 0xEE, 0x7F, 0x6B, 0x13, 0xEB, 0x73, 0x08, 0x18, 0xF7, + 0xF3, 0x67, 0xF8, 0x7F, 0xDF, 0x33, 0xFB, 0x65, 0xD1, 0xE3, 0x61, 0x7C, 0xBE, 0x79, 0xDF, 0xE1, + 0x39, 0xDF, 0x33, 0xF3, 0xC7, 0xF8, 0x19, 0x17, 0x59, 0x46, 0xEE, 0x73, 0xFD, 0x2F, 0xDC, 0x3F, + 0xAB, 0x77, 0x6E, 0xE6, 0x9C, 0x9F, 0x39, 0x67, 0xEC, 0xF4, 0xDC, 0xF9, 0x7C, 0x4C, 0x6E, 0x72, + 0xDF, 0x44, 0xCE, 0xCE, 0xEC, 0x6D, 0xD9, 0x4D, 0xFA, 0xA6, 0x3F, 0xAD, 0xD9, 0x05, 0xD3, 0xB0 +}; + +static void CMidDataGen_GD02Proc(struct CMidDataGen *this, uint8_t *outDataPtr, + uint16_t width, uint16_t height, uint8_t *autoGenBase) + +{ + const uint8_t *scratch = GD_02_MIDDATA; + uint16_t row; + uint8_t *outPtr = outDataPtr; + + for (row = 0 ; row < height ; row++) { + uint16_t col; + for (col = 0 ; col < width ; col++) { + uint8_t outVal; + if ((scratch[(col % 0x30 + (row % 0x30) * 0x30) >> 3] & + (1 << (((col % 0x30) % 8) & 0x1f))) == 0) { + outVal = autoGenBase[0]; + } else { + outVal = autoGenBase[1]; + } + *outPtr = outVal; + outPtr++; + } + } + (void)this; +} + +static void CMidDataGen_GenDataEx(struct CMidDataGen *this) + +{ + uint16_t autogen; + + autogen = this->planeIppData->autoGenMode; + if (autogen == 1) { // glossy + CMidDataGen_GD01Proc(this, this->outDataPtr + this->width * this->height * this->plane, + this->width, this->height, this->planeIppData->autoGenBase); + } else if (autogen == 2) { // matte + CMidDataGen_GD02Proc(this, this->outDataPtr + this->width * this->height * this->plane, + this->width, this->height, this->planeIppData->autoGenBase); + } + + return; +} + +static bool CMidDataGen_GenData(struct CMidDataGen *this, uint8_t *outDataPtr, uint8_t plane, + uint16_t width, uint16_t height, struct SIppData *ippData) +{ + if (!outDataPtr || !width || !height || !ippData) + return 0; + + this->outDataPtr = outDataPtr; + this->plane = plane; + this->width = width; + this->height = height; + this->planeIppData = ippData; + + if (!CMidDataGen_CheckAutoGenNo(this)) + return 0; + CMidDataGen_GenDataEx(this); + + return 1; +} + +/*** CHeatCorrProc ***/ +static void CHeatCorrProc_Init(struct CHeatCorrProc *this) +{ + memset(this, 0, sizeof(*this)); +} + +static bool CHeatCorrProc_SetIppData(struct CHeatCorrProc *this, struct SIppData *ippData, + uint16_t width, uint16_t height, uint16_t headWidth, + uint16_t maxPulse) + +{ + memcpy(&this->ippData, ippData, sizeof(this->ippData)); + memcpy(&this->heatCorrection, &this->ippData.heatCorrection, sizeof(this->heatCorrection)); + this->width = width; + this->height = height; + this->headWidth = headWidth; + this->maxPulse = maxPulse; + + if (this->width > this->headWidth) + return 0; + + this->lineStartOffset = 0; + this->initialized = 1; + + return 1; +} + +static bool CHeatCorrProc_InitTank(struct CHeatCorrProc *this) + +{ + bool rval = 0; + int i; + +#ifdef USE_EXTRA_STUFF + this->tankWidth = this->width + 5; /* Sinfonia algorithms read 1 element past this buffer */ +#else + this->tankWidth = this->width + 4; +#endif + if (!this->tankRowBufs[0]) { + this->tankRowBufs[0] = malloc(this->tankWidth * sizeof(uint32_t)); + if (!this->tankRowBufs[0]) + goto done; + } + for (i = 0 ; i < this->tankWidth ; i++) { + this->tankRowBufs[0][i] = this->heatCorrection.tankRowInitVals[3]; + } + if (!this->tankRowBufs[1]) { + this->tankRowBufs[1] = malloc(this->tankWidth * sizeof(uint32_t)); + if (!this->tankRowBufs[1]) + goto done; + } + for (i = 0 ; i < this->tankWidth ; i++) { + this->tankRowBufs[1][i] = this->heatCorrection.tankRowInitVals[2]; + } + if (!this->tankRowBufs[2]) { + this->tankRowBufs[2] = malloc(this->tankWidth * sizeof(uint32_t)); + if (!this->tankRowBufs[2]) + goto done; + } + for (i = 0 ; i < this->tankWidth ; i++) { + this->tankRowBufs[2][i] = this->heatCorrection.tankRowInitVals[1]; + } + if (!this->tankRowBufs[3]) { + this->tankRowBufs[3] = malloc(this->tankWidth * sizeof(uint32_t)); + if (!this->tankRowBufs[3]) + goto done; + } + for (i = 0 ; i < this->tankWidth ; i++) { + this->tankRowBufs[3][i] = this->heatCorrection.tankRowInitVals[0]; + } + if (!this->tankRowBufs[4]) { + this->tankRowBufs[4] = malloc(this->tankWidth * sizeof(uint32_t)); + if (!this->tankRowBufs[4]) + goto done; + } + for (i = 0 ; i < this->tankWidth ; i++) { + this->tankRowBufs[4][i] = 0; + } + if (!this->tankRowPtrs[0]) { + this->tankRowPtrs[0] = malloc(this->tankWidth * sizeof(uint32_t)); + if (!this->tankRowPtrs[0]) + goto done; + } + for (i = 0 ; i < this->tankWidth ; i++) { + this->tankRowPtrs[0][i] = 0; + } + if (!this->tankRowPtrs[1]) { + this->tankRowPtrs[1] = malloc(this->tankWidth * sizeof(uint32_t)); + if (!this->tankRowPtrs[1]) + goto done; + } + for (i = 0 ; i < this->tankWidth ; i++) { + this->tankRowPtrs[1][i] = 0; + } + +#ifdef USE_EXTRA_STUFF + this->tankWidth--; +#endif + + rval = 1; +done: + return rval; +} + +static void CHeatCorrProc_PreReadLine(struct CHeatCorrProc *this, uint16_t *tankSrc, uint16_t useHeatCorrection) + +{ + int i; + int heatStep; + int rowStep; + + if (!useHeatCorrection) + return; + + if (useHeatCorrection > 0xc) + useHeatCorrection = 0xc; + + for (i = 0 ; i < this->tankWidth ; i++) { + this->tankRowBufs[4][i] = 0; + } + + for (heatStep = useHeatCorrection, rowStep = 0 ; heatStep > 0 && ((rowStep + this->curRow) < this->height) ; heatStep--, rowStep++) { + int col; + + int *rowBufPtr = this->tankRowBufs[4] + this->lineStartOffset + 2; + for (col = 0; col < this->width ; col++) { + *rowBufPtr += heatStep * *tankSrc; + tankSrc++; + rowBufPtr++; + } + } + /* If we stopped early, clean up! */ + if (heatStep != useHeatCorrection) { + int col; + int local_50; + int local_48 = useHeatCorrection; + int divisor = 0; + int *rowBufPtr; + + for (local_50 = useHeatCorrection - heatStep ; local_50 > 0 ; local_50--) { + divisor += local_48; + local_48--; + } + if (divisor == 0) { + divisor = 1; + } + rowBufPtr = this->tankRowBufs[4] + this->lineStartOffset + 2; + for (col = 0 ; col < this->width ; col++) { + *rowBufPtr /= divisor; + rowBufPtr++; + } + } + + return; +} + +static uint16_t CHeatCorrProc_GetBitsOfPulse(struct CHeatCorrProc *this, uint16_t maxPulse) + +{ + uint16_t i; + + for (i = 0 ; maxPulse != 0 ; i++) { + maxPulse >>= 1; + } + (void)this; + return i; +} + + +static int32_t CHeatCorrProc_GetCorrPulsePreRead(struct CHeatCorrProc *this, int srcVal, int param_2) + +{ + int32_t local_28; + int32_t local_24; + int32_t local_20; + + if (this->heatCorrection.useHeatCorrection == 0) + return 0; + + param_2 -= srcVal; + + if (param_2 == 0) + return 0; + + if (param_2 < 1) { + local_24 = (this->heatCorrection).tankMinusLimit; + local_28 = (this->heatCorrection).tankMinusParam; + local_20 = -param_2; + } else { + local_24 = (this->heatCorrection).tankPlusLimit; + local_28 = (this->heatCorrection).tankPlusParam; + local_20 = param_2; + } + if (local_20 < local_24) { + return 0; + } + + return (local_28 * param_2 >> 10); +} + +static void CHeatCorrProc_CorrectEx(struct CHeatCorrProc *this, uint16_t *tankBuf, uint16_t *tankRowSrc, uint8_t *scratchRowBuf) +{ + uint16_t col; + uint8_t pulseBits; + int32_t tankDivisor; + + int32_t pulsePreRead; + int32_t outPulse; + int32_t heatCorrection; + int32_t *local_48; + int32_t *local_40; + uint16_t *srcPixel; + uint8_t *scratchPtr; + + pulseBits = CHeatCorrProc_GetBitsOfPulse(this,this->maxPulse); + tankDivisor = this->heatCorrection.tankDivisor[3]; + + local_40 = this->tankRowBufs[0] + (long)this->lineStartOffset + 2; + local_48 = this->tankRowBufs[4] + (long)this->lineStartOffset + 2; + srcPixel = tankRowSrc; + scratchPtr = scratchRowBuf; + for (col = this->width ; col != 0 ; col --) { + int iVar4 = *srcPixel - + ((((0x100000 << (pulseBits & 0x1f)) / tankDivisor) * (*srcPixel + *local_40)) >> 0x14); + if (iVar4 == 0) { + heatCorrection = 0; + } else { + if (iVar4 < 1) { + heatCorrection = (this->ippData).heatCorrectionPlusTable[*scratchPtr]; + } else { + heatCorrection = (this->ippData).heatCorrectionMinusTable[*scratchPtr]; + } + } + pulsePreRead = CHeatCorrProc_GetCorrPulsePreRead(this, *srcPixel, *local_48); + outPulse = pulsePreRead + *srcPixel + ((iVar4 * heatCorrection) >> (pulseBits & 0x1f)); + if (outPulse < 0) { + outPulse = 0; + } else { + if (this->maxPulse < outPulse) { + outPulse = this->maxPulse; + } + } + *tankBuf = outPulse; + *local_40 += outPulse; + srcPixel++; + tankBuf++; + scratchPtr++; + local_40++; + local_48++; + } + return; +} + +static void CHeatCorrProc_GetTankCoefTransfer(struct CHeatCorrProc *this, int32_t *param_1, int32_t *param_2, int32_t *param_3, + int32_t *param_4, int32_t *param_5, int32_t *param_6, int32_t *param_7, int32_t *param_8) + +{ + *param_1 = 0x10000; + *param_1 *= this->heatCorrection.tankCoef[4]; + *param_1 /= this->heatCorrection.tankDivisor[3]; + *param_2 = 0x10000; + *param_2 *= this->heatCorrection.tankCoef[3]; + *param_2 /= this->heatCorrection.tankDivisor[3]; + *param_3 = 0x10000; + *param_3 *= this->heatCorrection.tankCoef[3]; + *param_3 /= this->heatCorrection.tankDivisor[2]; + *param_4 = 0x10000; + *param_4 *= this->heatCorrection.tankCoef[2]; + *param_4 /= this->heatCorrection.tankDivisor[2]; + *param_5 = 0x10000; + *param_5 *= this->heatCorrection.tankCoef[2]; + *param_5 /= this->heatCorrection.tankDivisor[1]; + *param_6 = 0x10000; + *param_6 *= this->heatCorrection.tankCoef[1]; + *param_6 /= this->heatCorrection.tankDivisor[1]; + *param_7 = 0x10000; + *param_7 *= this->heatCorrection.tankCoef[1]; + *param_7 /= this->heatCorrection.tankDivisor[0]; + *param_8 = 0x10000; + *param_8 *= this->heatCorrection.tankCoef[0]; + *param_8 /= this->heatCorrection.tankDivisor[0]; +} + +static void CHeatCorrProc_TankHeatTransferEx(struct CHeatCorrProc *this, int32_t *param_1, int32_t *param_2, int32_t *param_3, + int32_t param_4, int32_t param_5, int32_t param_6, int32_t param_7) + +{ + int local_54; + int local_50; + uint16_t col; + int *local_48 = NULL; + int *local_40; + int *local_38 = NULL; + + if (0 < param_4) { + local_38 = param_1 + 2; + } + + local_40 = param_2 + 2; + if (0 < param_7) { + local_48 = param_3 + 2; + } + + for (col = this->width ; col != 0 ; col--) { + local_50 = *local_40 * param_5; + if (0 < param_4) { + local_50 -= *local_38 * param_4; + } + if (param_7 < 1) { + local_54 = 0; + } else { + local_54 = *local_48 * param_7; + } + *local_40 = ((local_54 - *local_40 * param_6) >> 0x10) + (*local_40 - (local_50 >> 0x10)); + if (0 < param_4) { + local_38++; + } + local_40++; + if (0 < param_7) { + local_48++; + } + } +} + +/* Computes the heat transfer across a single horizontal scanline! */ +static void CHeatCorrProc_DotHeatTransExRevOld(struct CHeatCorrProc *this, int32_t param_1, int32_t *tankRowBuf) + +{ + int i; + int32_t *outPtr; + int32_t local_50; + int32_t local_4c; + int32_t local_48; + int32_t pixelPlusTwo; + int32_t pixelPlusOne; + int32_t pixelCurrent; + int32_t *local_38; + + /* Initialize shoulders at either side (-2/+2) */ + for (i = 0 ; i < 2 ; i++) { + tankRowBuf[i] = tankRowBuf[2]; + tankRowBuf[this->tankWidth - 1 - i] = tankRowBuf[this->tankWidth - 3]; + } +#ifdef USE_EXTRA_STUFF + /* We allocated an extra element at the end; fill it in */ + tankRowBuf[this->tankWidth] = tankRowBuf[this->tankWidth-1]; +#endif + pixelCurrent = tankRowBuf[2]; + + param_1 /= 2; + local_48 = param_1 * (*tankRowBuf + tankRowBuf[1] * -2 + pixelCurrent); + pixelPlusOne = tankRowBuf[3]; + local_4c = param_1 * (tankRowBuf[1] + pixelCurrent * -2 + pixelPlusOne); + local_50 = pixelCurrent + pixelPlusOne * -2 + tankRowBuf[4]; + outPtr = tankRowBuf + 2; + pixelPlusTwo = tankRowBuf[4]; + local_38 = tankRowBuf + 5; // NOTE: this overflows the buffer on the last element, as buffer is +- 2 but this is +3! We work around it with USE_EXTRA_STUFF. + + for (i = this->width ; i > 0 ; i--) { + int32_t outPixel; + + local_50 *= param_1; + outPixel = ((local_4c >> 6) + pixelCurrent) - + (param_1 * (((local_4c * 2 - local_48) - local_50) >> 7) >> 7); + if (outPixel < 0) { + outPixel = 0; + } + local_48 = local_4c; + local_4c = local_50; + local_50 = pixelPlusOne + pixelPlusTwo * -2 + *local_38; + pixelCurrent = pixelPlusOne; + pixelPlusOne = pixelPlusTwo; + pixelPlusTwo = *local_38; + *outPtr = outPixel; + outPtr++; + local_38++; + } +} + +static void CHeatCorrProc_HeatTransferProc(struct CHeatCorrProc *this) + +{ + int32_t local_48; + int32_t local_44; + int32_t local_40; + int32_t local_3c; + int32_t local_38; + int32_t local_34; + int32_t local_30; + int32_t local_2c; + + CHeatCorrProc_GetTankCoefTransfer(this, &local_2c, &local_30, &local_34, &local_38, + &local_3c, &local_40, &local_44, &local_48); + memcpy(this->tankRowPtrs[0], this->tankRowBufs[0], this->tankWidth * 4); + + CHeatCorrProc_TankHeatTransferEx(this, NULL, this->tankRowBufs[0], this->tankRowBufs[1], + 0, local_2c, local_30, local_34); + memcpy(this->tankRowPtrs[1], this->tankRowBufs[1], this->tankWidth * 4); + + CHeatCorrProc_TankHeatTransferEx(this, this->tankRowPtrs[0], this->tankRowBufs[1], this->tankRowBufs[2], + local_30, local_34, local_38, local_3c); + memcpy(this->tankRowPtrs[0], this->tankRowBufs[2], this->tankWidth * 4); + + CHeatCorrProc_TankHeatTransferEx(this, this->tankRowPtrs[1], this->tankRowBufs[2], this->tankRowBufs[3], + local_38, local_3c, local_40, local_44); + CHeatCorrProc_TankHeatTransferEx(this, this->tankRowPtrs[0], this->tankRowBufs[3], NULL, + local_40, local_44, local_48, 0); + + CHeatCorrProc_DotHeatTransExRevOld(this, this->heatCorrection.tankRowOldInitVals[3], this->tankRowBufs[0]); + CHeatCorrProc_DotHeatTransExRevOld(this, this->heatCorrection.tankRowOldInitVals[2], this->tankRowBufs[1]); + CHeatCorrProc_DotHeatTransExRevOld(this, this->heatCorrection.tankRowOldInitVals[1], this->tankRowBufs[2]); + CHeatCorrProc_DotHeatTransExRevOld(this, this->heatCorrection.tankRowOldInitVals[0], this->tankRowBufs[3]); +} + +static bool CHeatCorrProc_Correction(struct CHeatCorrProc *this, + uint16_t *destData, uint16_t *srcData, + uint8_t *scratchData) +{ + bool rval = 0; + uint32_t pixels; + int i; + + if (!this->initialized || !this->width || !this->height) + goto done; + + pixels = this->width * this->height; + + this->tankBuf = malloc(pixels * 2); + if (!this->tankBuf) + goto done; + + CHeatCorrProc_InitTank(this); + this->tankRowSrc = (int16_t*) srcData; + + for (this->curRow = 0 ; this->curRow < this->height ; this->curRow++) { + uint16_t width; + uint16_t tankWidth; + uint16_t scratchWidth; + uint32_t row; + uint32_t tankRow; + uint32_t scratchRow; + + row = this->curRow; + width = this->width; + tankRow = this->curRow; + tankWidth = this->width; + scratchRow = this->curRow; + scratchWidth = this->width; + + CHeatCorrProc_PreReadLine(this, (uint16_t *)(this->tankRowSrc + (tankRow * tankWidth)), + this->heatCorrection.useHeatCorrection); + CHeatCorrProc_CorrectEx(this,(uint16_t *)(this->tankBuf + (row * width)), + (uint16_t *)(this->tankRowSrc + (tankRow * tankWidth)), + scratchData + (scratchRow * scratchWidth)); + CHeatCorrProc_HeatTransferProc(this); + } + + memcpy(destData, this->tankBuf, pixels * 2); + rval = 1; +done: + + if (this->tankBuf) { + free(this->tankBuf); + this->tankBuf = NULL; + } + for (i = 0 ; i < 2 ; i++) { + if (this->tankRowPtrs[i]) { + free(this->tankRowPtrs[i]); + this->tankRowPtrs[i] = NULL; + } + } + for (i = 0 ; i < 5 ; i++) { + if (this->tankRowBufs[i]) { + free(this->tankRowBufs[i]); + this->tankRowBufs[i] = NULL; + } + } + return rval; +} + +/*** CImageProc ***/ + +static void CImageProc_Init(struct CImageProc *this, struct CIppMng *ippMng) + +{ + memset(this, 0, sizeof(*this)); + this->ippMng = ippMng; + return; +} + +static bool CImageProc_Initialize(struct CImageProc *this) +{ + this->pixels = 0; + + CIppMng_GetIppConf(this->ippMng, &this->conf, &this->planesOCG, &this->planesOCM); + + /* Sanity checks */ + if (!this->conf.width || !this->conf.height || !this->conf.headWidth || + !this->planesOCG || !this->planesOCM) + return 0; + + /* If this is a 5x7 print.. */ + if (this->conf.borderCapable == 0x02 && + this->conf.width == 1548 && + this->conf.height == 2140) { + this->srcWidth = this->conf.width; + this->srcHeight = this->conf.height; + this->conf.width = 1844; + this->conf.height = 2434; + } + this->correctMtf = this->conf.corrections1 & 1; + this->correctHeat = this->conf.corrections2 & 1; + this->correctLine = (this->conf.corrections2 & 2) >> 1; + this->correctSideEdge = (this->conf.corrections2 & 4) >> 2; + + this->pixelsOCG = this->conf.width * this->conf.height * this->planesOCG; + this->pixelsOCM = this->conf.width * this->conf.height * this->planesOCM; + + this->imageScratchDataPtr = malloc(this->pixelsOCM); + if (!this->imageScratchDataPtr) + return 0; + + this->pixels = this->conf.width * this->conf.height; + this->imageDataLen = this->pixels * this->planesOCM * 2; + this->imageDataPtr = malloc(this->imageDataLen); + if (!this->imageDataPtr) { + free(this->imageScratchDataPtr); + this->imageScratchDataPtr = NULL; + return 0; + } + memset(this->imageDataPtr, 0, this->imageDataLen); + + return 1; +} + +static int CImageProc_CropPicDotSeq(struct CImageProc *this, uint8_t *destPtr, + struct pic_data *picData, struct crop_conf *cropConf) + +{ + uint16_t cols, rows; + uint8_t bypp; + uint8_t *scratch; + int row; + int offset; + + cols = cropConf->numCols; + rows = cropConf->numRows; + bypp = picData->bytes_pp; + + scratch = malloc(cols * rows * bypp); + if (!scratch) + return -1; + + for (row = 0, offset = 0; row < (cropConf->startRow + cropConf->numRows) ; row++) { + int col; + for (col = cropConf->startCol; col < (cropConf->startCol + cropConf->numCols) ; col++) { + uint32_t srcOffset = picData->bytes_pp * (col + row * picData->outCols); + int p; + for (p = 0 ; p < picData->bytes_pp ; p ++) { + scratch[offset] = picData->srcPtr[srcOffset]; + srcOffset++; + offset++; + } + } + } + + memcpy(destPtr, scratch, cols * rows * bypp); + if (scratch) + free(scratch); + + (void)this; /* Shut up, compiler */ + + return 0; +} + +static int CImageProc_AddBorderEx(struct CImageProc *this, uint8_t *destPtr, uint8_t *srcPtr, + struct pic_data *picData) + +{ + uint32_t outBufLen; + uint8_t *outBuf; + uint32_t outOffset, srcOffset; + int row; + + if (picData->outCols < picData->inCols || + picData->outRows < picData->inRows) + return -2; + + outBufLen = picData->outCols * picData->outRows * picData->bytes_pp; + outBuf = malloc(outBufLen); + if (!outBuf) + return -1; + + memset(outBuf, 0xff, outBufLen); + + srcOffset = 0; + for (row = 0; row < picData->inRows ; row++) { + int col; + for (col = 0 ; col < picData->inCols ; col++) { + int j; + + outOffset = picData->bytes_pp * + (col + ((picData->outCols - picData->inCols) / 2) + + ((row + ((picData->outRows - picData->inRows) / 2)) * + picData->outCols)); + + for (j = 0 ; j < picData->bytes_pp ; j++) { + outBuf[outOffset] = srcPtr[srcOffset]; + outOffset++; + srcOffset++; + } + } + + } + + memcpy(destPtr, outBuf, outBufLen); + free(outBuf); + + (void)this; /* Shut up, compiler */ + + return 0; +} + +static bool CImageProc_AddBorder(struct CImageProc *this, uint8_t *destPtr, uint8_t *srcRGBPtr) + +{ + /* If this is a 5x7 print.. */ + if (this->conf.borderCapable == 0x02 && + this->conf.width == 1548 && + this->conf.height == 2140) { + struct pic_data borderPicData; + struct crop_conf cropConf; + struct pic_data cropPicData; + + cropPicData.inCols = 0x60c; + cropPicData.inRows = 0x85c; + cropPicData.outCols = 0x60c; + cropPicData.outRows = 0x85c; + cropPicData.bytes_pp = 3; + cropPicData.srcPtr = srcRGBPtr; + + cropConf.startCol = 0x0018; + cropConf.startRow = 0x0012; + cropConf.numCols = 0x05e0; + cropConf.numRows = 0x0838; + + if (CImageProc_CropPicDotSeq(this, destPtr, &cropPicData, &cropConf)) + return 0; + + borderPicData.inCols = 0x5e0; + borderPicData.inRows = 0x838; + borderPicData.outCols = 0x734; + borderPicData.outRows = 0x982; + borderPicData.bytes_pp = 3; + borderPicData.srcPtr = destPtr; + if (CImageProc_AddBorderEx(this, destPtr, destPtr, &borderPicData)) + return 0; + + } else { + memcpy(destPtr, srcRGBPtr, this->pixelsOCG); + } + + return 1; +} + +static bool CImageProc_TransDotToPlane(struct CImageProc *this, uint8_t *destPtr, uint8_t *srcPtr) +{ + uint8_t *workBuf; + uint32_t offset; + + workBuf = malloc(this->pixelsOCG); + if (!workBuf) + return 0; + + for (offset = 0 ; offset < this->pixelsOCG ; offset++) { + workBuf[((this->planesOCG - 1) - offset % this->planesOCG) * + (this->pixelsOCG / this->planesOCG) + offset / this->planesOCG] = srcPtr[offset] ^ 0xff; + } + + memcpy(destPtr, workBuf, this->pixelsOCG); + free(workBuf); + + return 1; +} + +static bool CImageProc_GetIppData(struct CImageProc *this, uint8_t plane) + +{ + return CIppMng_GetIppData(this->ippMng, &this->planeIPPdata, plane); +} + +static bool CImageProc_SetProcConfig(struct CImageProc *this, uint8_t plane) + +{ + bool rval; + uint8_t planeOffset; + + this->currentPlane = plane; + rval = CIppMng_GetIppNo(this->ippMng, &planeOffset, this->currentPlane); + if (rval) + rval = CImageProc_GetIppData(this, planeOffset); + + return rval; +} + + +static bool CImageProc_MiddleDataGen(struct CImageProc *this, uint8_t plane) + +{ + struct CMidDataGen midData; + + CMidDataGen_Init(&midData); + + return CMidDataGen_GenData(&midData, (uint8_t *)this->imageScratchDataPtr, plane, + this->conf.width, this->conf.height, &this->planeIPPdata); +} + + +static void CImageProc_MtfPreCalcTableGen(struct CImageProc *this) + +{ + uint16_t uVar1; + int16_t i; + + uVar1 = (this->planeIPPdata).mtfPreCalcCutoff; + for (i = -0x100 ; i < 0x100 ; i++) { // XXX this is a 512 element array! + if (i * i < uVar1 * uVar1) { + this->mtfCorrPlaneTable[i + 0x100] = -i; + } else { + this->mtfCorrPlaneTable[i + 0x100] = i; + } + } + return; +} + +static bool CImageProc_MtfCorrPlaneEx(struct CImageProc *this, uint8_t *outData, uint8_t *inData) + +{ + uint32_t planeSize; + uint8_t *workBuf; + int16_t *mtfCorrPlaneTable; + uint16_t row; + + CImageProc_MtfPreCalcTableGen(this); + planeSize = this->conf.width * this->conf.height; + + workBuf = malloc(planeSize); + if (!workBuf) + return 0; + + mtfCorrPlaneTable = &this->mtfCorrPlaneTable[256]; /* Mid-point of array */ + memcpy(workBuf, inData, planeSize); + + for (row = 1 ; row < (this->conf.height - 1) ; row++) { + uint16_t col; + for (col = 1 ; col < (this->conf.width - 1) ; col++) { + uint32_t rowOffset = col + row * this->conf.width; + uint8_t *inPixel = inData + rowOffset; + + int outVal; + uint8_t outPixel; + + // (curPixel + ((diff_prevRowPixel + diff_prevColPixel) * prevWeight) + ((diff_nextRowPixel + diff_nextColPixel) * nextWeight) / 128 + + outVal = *inPixel + + (((mtfCorrPlaneTable[*inPixel - inPixel[-this->conf.width]] + + mtfCorrPlaneTable[*inPixel - inPixel[this->conf.width]]) * (this->planeIPPdata).prevWeight + + (mtfCorrPlaneTable[(*inPixel - inPixel[-1])] + + mtfCorrPlaneTable[(*inPixel - inPixel[1])]) * this->planeIPPdata.nextWeight) >> 7); + + outPixel = outVal; + if (outVal < 0x100) { + if (outVal < 1) { + outPixel = 1; + } + } else { + outPixel = 0xff; + } + workBuf[rowOffset] = outPixel; + } + } + + + memcpy(outData, workBuf, planeSize); + free(workBuf); + + return 1; +} + + +static bool CImageProc_MtfCorrPlane(struct CImageProc *this) +{ + uint32_t offset; + + if (!this->correctMtf) + return 1; + + offset = this->pixels * this->currentPlane; + + return CImageProc_MtfCorrPlaneEx(this, ((uint8_t *)this->imageScratchDataPtr) + offset, + ((uint8_t *)this->imageScratchDataPtr) + offset); +} + +static int32_t CImageProc_TransPlaneToPulseEx(struct CImageProc *this, uint16_t *outPtr, uint8_t *inPtr) + +{ + int32_t offset; + + for (offset = 0 ; offset < this->conf.width * this->conf.height ; offset++) { + outPtr[offset] = this->planeIPPdata.pulseExMap[inPtr[offset]]; + } + return offset; +} + +static void CImageProc_TransPlaneToPulse(struct CImageProc *this) + +{ + uint32_t offset = this->pixels * this->currentPlane; + + CImageProc_TransPlaneToPulseEx(this,this->imageDataPtr + offset, + ((uint8_t *)this->imageScratchDataPtr) + offset); + return; + +} + +static uint16_t CImageProc_GetMaxPulse(struct CImageProc *this) + +{ + return (this->planeIPPdata.field_0x0 * (this->planeIPPdata.field_0x2 + 1)) + this->planeIPPdata.field_0x2; +} + +static bool CImageProc_HeatCorrection(struct CImageProc *this) + +{ + struct CHeatCorrProc heatProc; + uint32_t offset; + uint16_t maxPulse; + bool rval; + + /* Don't correct heat transfer if so requested */ + if (!this->correctHeat) + return 1; + + CHeatCorrProc_Init(&heatProc); + + offset = this->pixels * this->currentPlane; + maxPulse = CImageProc_GetMaxPulse(this); + + rval = CHeatCorrProc_SetIppData(&heatProc, &this->planeIPPdata, + this->conf.width, this->conf.height, + this->conf.headWidth, maxPulse); + if (!rval) + return 0; + + + CHeatCorrProc_Correction(&heatProc, + this->imageDataPtr + offset, + this->imageDataPtr + offset, + ((uint8_t *)this->imageScratchDataPtr) + offset); + + return 1; +} + +static bool CImageProc_LineCorrEx(struct CImageProc *this, uint16_t *outDataPtr, uint16_t *inData, uint8_t *scratchData) + +{ + uint32_t pixels; + uint16_t *workBuf; + uint16_t minRowSum; + uint16_t maxPulse; + int32_t pageSum; + uint32_t lineCorrectionFactor; + uint16_t *workPtr; + uint8_t *scratchPtr; + uint16_t *inPtr; + int32_t maxLineSum; + int32_t rowSum; + + uint16_t row; + + pixels = this->conf.width * this->conf.height; + + workBuf = malloc(pixels * 2); + if (!workBuf) + return 0; + + pageSum = 0; + lineCorrectionFactor = 0; + maxLineSum = this->conf.width * this->planeIPPdata.maxLineSum; + minRowSum = this->planeIPPdata.minRowSum; + maxPulse = CImageProc_GetMaxPulse(this); + workPtr = workBuf; + scratchPtr = scratchData; + inPtr = inData; + + for (row = 0 ; row < this->conf.height ; row ++) { + uint16_t col; + uint16_t local_54; + int32_t iVar3; + + rowSum = 0; + for (col = 0 ; col < this->conf.width ; col++) { + rowSum = *inPtr + rowSum; + iVar3 = *inPtr - (((this->planeIPPdata).lineCorrection[*scratchPtr] * lineCorrectionFactor) >> 10); + if (iVar3 < 0) { + local_54 = 0; + } else { + local_54 = iVar3; + if (maxPulse < iVar3) { + local_54 = maxPulse; + } + } + *workPtr = local_54; + workPtr++; + inPtr++; + scratchPtr++; + } + + if ((this->conf.width * minRowSum) < rowSum) { + pageSum = rowSum + pageSum; + if (maxLineSum < pageSum) { + pageSum -= maxLineSum; + lineCorrectionFactor++; + if (this->planeIPPdata.maxLineCorrectionFactor < lineCorrectionFactor) { + lineCorrectionFactor = this->planeIPPdata.maxLineCorrectionFactor; + } + } + } + } + + memcpy(outDataPtr, workBuf, pixels * 2); + free(workBuf); + + return 1; +} + +static bool CImageProc_LineCorrection(struct CImageProc *this) +{ + uint32_t offset; + + if (!this->correctLine) + return 1; + + offset = this->pixels * this->currentPlane; + + return CImageProc_LineCorrEx(this, this->imageDataPtr + offset, this->imageDataPtr + offset, + (uint8_t*)this->imageScratchDataPtr + offset); +} + +static bool CImageProc_SideEdgeCorrEx(struct CImageProc *this, uint16_t *outDataPtr, uint16_t *inDataPtr, uint8_t *scratchDataPtr) + +{ + uint32_t pixels = this->conf.width * this->conf.height; + uint16_t *workBuf, *workPtr; + uint16_t maxPulse; + uint8_t *scratchPtr; + uint16_t *inPtr; + + int col; + int row; + + workBuf = malloc(pixels * 2); + if (!workBuf) + return 0; + + maxPulse = CImageProc_GetMaxPulse(this); + + workPtr = workBuf; + scratchPtr = scratchDataPtr; + inPtr = inDataPtr; + + for (row = 0 ; row < this->conf.height ; row++) { + for (col = 0 ; col < this->conf.width ; col++) { + uint32_t corrVal; + uint16_t inPixel; + int32_t iVar3; + + if (col < 0x40) { + corrVal = this->planeIPPdata.sideEdgeCorrectionComp[col]; + } else { + if ((this->conf.width - 0x40) < col) { + corrVal = this->planeIPPdata.sideEdgeCorrectionComp[(this->conf.width - col) -1]; + } else { + corrVal = 0; + } + } + inPixel = *inPtr; + if (corrVal != 0) { + iVar3 = *inPtr - (((this->planeIPPdata).sideEdgeCorrectionTable[*scratchPtr] * corrVal) >> 7); + if (iVar3 < 0) { + inPixel = 0; + } else { + inPixel = iVar3; + if (maxPulse < iVar3) { + inPixel = maxPulse; + } + } + } + *workPtr = inPixel; + workPtr++; + inPtr++; + scratchPtr++; + } + } + + memcpy(outDataPtr, workBuf, pixels * 2); + free(workBuf); + return 1; +} + +static bool CImageProc_SideEdgeCorrection(struct CImageProc *this) + +{ + uint32_t offset; + + if (!this->correctSideEdge) + return 1; + + offset = this->pixels * this->currentPlane; + + return CImageProc_SideEdgeCorrEx(this, this->imageDataPtr + offset, this->imageDataPtr + offset, + ((uint8_t*)this->imageScratchDataPtr + offset)); +} + +static bool CImageProc_PulseGenEx(struct CImageProc *this) + +{ + bool rval; + + rval = CImageProc_MtfCorrPlane(this); + if (rval) { + CImageProc_TransPlaneToPulse(this); + rval = CImageProc_HeatCorrection(this); + } + if (rval) + rval = CImageProc_LineCorrection(this); + if (rval) + rval = CImageProc_SideEdgeCorrection(this); + + return rval; +} + + +static bool CImageProc_PulseGen(struct CImageProc *this, uint16_t *outImgPtr, uint8_t *srcRGB) +{ + bool rval; + uint32_t i; + + rval = CImageProc_Initialize(this); + if (rval) + rval = CImageProc_AddBorder(this, (uint8_t*)this->imageScratchDataPtr, srcRGB); + if (rval) + rval = CImageProc_TransDotToPlane(this, (uint8_t*)this->imageScratchDataPtr, + (uint8_t*)this->imageScratchDataPtr); + if (!rval) + goto done; + + for (i = 0 ; i < this->planesOCM ; i++) { + rval = CImageProc_SetProcConfig(this, i); + if (!rval) + goto done; + + /* Generate the lamination plane as needed */ + if ((this->planesOCG <= i) && + !(rval = CImageProc_MiddleDataGen(this, i))) + goto done; + if (!(rval = CImageProc_PulseGenEx(this))) + goto done; + } + +#if (__BYTE_ORDER != __LITTLE_ENDIAN) + for (i = 0 ; i < this->imageDataLen / 2 ; i++) { + outImgPtr[i] = cpu_to_le16(this->imageDataPtr[i]); + } +#else + memcpy(outImgPtr, this->imageDataPtr, this->imageDataLen); +#endif + +done: + if (this->imageScratchDataPtr) { + free(this->imageScratchDataPtr); + this->imageScratchDataPtr = NULL; + } + if (this->imageDataPtr) { + free(this->imageDataPtr); + this->imageDataPtr = NULL; + } + return rval; +} + +//------------------------------------------------------------------------- +// Exported Functions + +bool ip_imageProc(uint16_t *destData, uint8_t *srcInRgb, + uint16_t width, uint16_t height, void *srcIpp) +{ + bool rval = 0; + struct CIppMng ippMng; + struct CImageProc imageProc; + + fprintf(stderr, "INFO: libS2245ImageReProcess version '%s'\n", LIB_VERSION); + fprintf(stderr, "INFO: Copyright (c) 2020 Solomon Peachy\n"); + fprintf(stderr, "INFO: This free software comes with ABSOLUTELY NO WARRANTY!\n"); + fprintf(stderr, "INFO: Licensed under the GNU GPLv3.\n"); + fprintf(stderr, "INFO: *** This code is NOT supported or endorsed by Sinfonia! ***\n"); + + CIppMng_Init(&ippMng); + CImageProc_Init(&imageProc, &ippMng); + + if (!width || !height || !srcIpp || !srcInRgb || !destData) + goto done; + + rval = CIppMng_SetIPP(&ippMng, srcIpp, width, height); + if (rval) + rval = CImageProc_PulseGen(&imageProc, destData, srcInRgb); + +done: + CIppMng_Cleanup(&ippMng); + + return rval; +} + +bool ip_checkIpp(uint16_t width, uint16_t height, void *srcIpp) +{ + bool rval = 0; + struct CIppMng ippMng; + + if (!width || !height || !srcIpp) + goto done; + + CIppMng_Init(&ippMng); +#ifdef USE_EXTRA_STUFF + rval = CIppMng_SetConf(&ippMng, srcIpp, width, height); + if (!rval) + goto done; +#endif + rval = CIppMng_CheckIpp(&ippMng, srcIpp); + + CIppMng_Cleanup(&ippMng); + +done: + return rval; +} + +bool ip_getMemorySize(uint32_t *szMemory, + uint16_t width, uint16_t height, + void *srcIpp) +{ + struct ippData *ippData; + uint32_t pixels; + + if (!width || !height || !szMemory || !srcIpp) + return 0; + + ippData = srcIpp; + + if ((ippData->conf.borderCapable == 0x02) && + (width == 1548) && (height == 2140)) { + pixels = 2434*1844; /* ie 8x6 */ + } else { + pixels = height * width; + } + + *szMemory = pixels * 2 * ippData->conf.planes; + + if (!*szMemory) + return 0; + + return 1; +}