summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lcms2mt/plugins/fast_float')
-rw-r--r--lcms2mt/plugins/fast_float/COPYING.GPL3674
-rw-r--r--lcms2mt/plugins/fast_float/Makefile12
-rw-r--r--lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin.vcxproj201
-rw-r--r--lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin.vcxproj.filters69
-rw-r--r--lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin.vcxproj.user4
-rw-r--r--lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin_testbed.vcxproj170
-rw-r--r--lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin_testbed.vcxproj.filters22
-rw-r--r--lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin_testbed.vcxproj.user4
-rw-r--r--lcms2mt/plugins/fast_float/doc/LittleCMS fast float extensions 1.0.pdfbin0 -> 1345153 bytes
-rw-r--r--lcms2mt/plugins/fast_float/include/Makefile.am6
-rw-r--r--lcms2mt/plugins/fast_float/include/lcms2mt_fast_float.h139
-rw-r--r--lcms2mt/plugins/fast_float/src/Makefile.am27
-rw-r--r--lcms2mt/plugins/fast_float/src/fast_16_tethra.c370
-rw-r--r--lcms2mt/plugins/fast_float/src/fast_8_curves.c409
-rw-r--r--lcms2mt/plugins/fast_float/src/fast_8_matsh.c399
-rw-r--r--lcms2mt/plugins/fast_float/src/fast_8_tethra.c501
-rw-r--r--lcms2mt/plugins/fast_float/src/fast_float_15bits.c603
-rw-r--r--lcms2mt/plugins/fast_float/src/fast_float_15mats.c347
-rw-r--r--lcms2mt/plugins/fast_float/src/fast_float_cmyk.c379
-rw-r--r--lcms2mt/plugins/fast_float/src/fast_float_curves.c384
-rw-r--r--lcms2mt/plugins/fast_float/src/fast_float_internal.h249
-rw-r--r--lcms2mt/plugins/fast_float/src/fast_float_matsh.c323
-rw-r--r--lcms2mt/plugins/fast_float/src/fast_float_separate.c199
-rw-r--r--lcms2mt/plugins/fast_float/src/fast_float_sup.c90
-rw-r--r--lcms2mt/plugins/fast_float/src/fast_float_tethra.c292
-rw-r--r--lcms2mt/plugins/fast_float/testbed/Makefile.am22
-rw-r--r--lcms2mt/plugins/fast_float/testbed/fast_float_testbed.c1782
-rw-r--r--lcms2mt/plugins/fast_float/testbed/test0.iccbin0 -> 560 bytes
-rw-r--r--lcms2mt/plugins/fast_float/testbed/test1.iccbin0 -> 557536 bytes
-rw-r--r--lcms2mt/plugins/fast_float/testbed/test2.iccbin0 -> 654496 bytes
-rw-r--r--lcms2mt/plugins/fast_float/testbed/test3.iccbin0 -> 28484 bytes
-rw-r--r--lcms2mt/plugins/fast_float/testbed/test5.iccbin0 -> 3240 bytes
32 files changed, 7677 insertions, 0 deletions
diff --git a/lcms2mt/plugins/fast_float/COPYING.GPL3 b/lcms2mt/plugins/fast_float/COPYING.GPL3
new file mode 100644
index 00000000..20d40b6b
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/COPYING.GPL3
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ <program> Copyright (C) <year> <name of author>
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>. \ No newline at end of file
diff --git a/lcms2mt/plugins/fast_float/Makefile b/lcms2mt/plugins/fast_float/Makefile
new file mode 100644
index 00000000..c77ff48c
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/Makefile
@@ -0,0 +1,12 @@
+
+# Dummy
+all:
+check:
+install:
+install-exec:
+uninstall:
+clean:
+distclean:
+ echo .
+
+ \ No newline at end of file
diff --git a/lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin.vcxproj b/lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin.vcxproj
new file mode 100644
index 00000000..4c45cd6a
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin.vcxproj
@@ -0,0 +1,201 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\include\lcms2mt_fast_float.h" />
+ <ClInclude Include="..\..\src\fast_float_internal.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\src\fast_16_tethra.c" />
+ <ClCompile Include="..\..\src\fast_8_curves.c" />
+ <ClCompile Include="..\..\src\fast_8_matsh.c" />
+ <ClCompile Include="..\..\src\fast_8_tethra.c" />
+ <ClCompile Include="..\..\src\fast_float_15bits.c" />
+ <ClCompile Include="..\..\src\fast_float_15mats.c" />
+ <ClCompile Include="..\..\src\fast_float_cmyk.c" />
+ <ClCompile Include="..\..\src\fast_float_curves.c" />
+ <ClCompile Include="..\..\src\fast_float_matsh.c" />
+ <ClCompile Include="..\..\src\fast_float_separate.c" />
+ <ClCompile Include="..\..\src\fast_float_sup.c" />
+ <ClCompile Include="..\..\src\fast_float_tethra.c" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\..\..\Projects\VC2019\lcms2mt_static\lcms2mt_static.vcxproj">
+ <Project>{71dede59-3f1e-486b-a899-4283000f76b5}</Project>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="..\..\COPYING.GPL3" />
+ <None Include="..\..\doc\LittleCMS fast float extensions 1.0.pdf" />
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{AD9FF79B-CF6E-4971-A7CF-DAA47D636676}</ProjectGuid>
+ <Keyword>Win32Proj</Keyword>
+ <RootNamespace>fast</RootNamespace>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v142</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v142</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v142</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v142</PlatformToolset>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
+ <IntDir>$(Platform)\fast_float_plugin_$(Configuration)\</IntDir>
+ <OutDir>..\..\..\..\Lib\MS\</OutDir>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
+ <IntDir>$(Platform)\fast_float_plugin_$(Configuration)\</IntDir>
+ <OutDir>..\..\..\..\Lib\MS\</OutDir>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <IntDir>$(Platform)\fast_float_plugin_$(Configuration)\</IntDir>
+ <OutDir>..\..\..\..\Lib\MS\</OutDir>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <IntDir>$(Platform)\fast_float_plugin_$(Configuration)\</IntDir>
+ <OutDir>..\..\..\..\Lib\MS\</OutDir>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level4</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>..\..\include;..\..\..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <FloatingPointModel>Fast</FloatingPointModel>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level4</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>WIN32;WIN64;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>..\..\include;..\..\..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <FloatingPointModel>Fast</FloatingPointModel>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <WarningLevel>Level4</WarningLevel>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>..\..\include;..\..\..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <BrowseInformation>false</BrowseInformation>
+ <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
+ <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
+ <OmitFramePointers>true</OmitFramePointers>
+ <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
+ <FloatingPointModel>Fast</FloatingPointModel>
+ <EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ <Bscmake>
+ <PreserveSbr>true</PreserveSbr>
+ </Bscmake>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <WarningLevel>Level4</WarningLevel>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>WIN32;WIN64;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>..\..\include;..\..\..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
+ <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
+ <OmitFramePointers>true</OmitFramePointers>
+ <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
+ <EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
+ <FloatingPointModel>Fast</FloatingPointModel>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project> \ No newline at end of file
diff --git a/lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin.vcxproj.filters b/lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin.vcxproj.filters
new file mode 100644
index 00000000..f78d01cd
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin.vcxproj.filters
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="Header Files">
+ <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+ <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+ </Filter>
+ <Filter Include="Source Files">
+ <UniqueIdentifier>{7d5b1769-2be4-46f2-9e35-6260eea79d7f}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="doc">
+ <UniqueIdentifier>{012df308-35db-4909-b035-b1cd5fd1ee5b}</UniqueIdentifier>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\include\lcms2mt_fast_float.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\src\fast_float_internal.h">
+ <Filter>Source Files</Filter>
+ </ClInclude>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\src\fast_float_15bits.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\fast_float_curves.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\fast_float_separate.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\fast_float_sup.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\fast_float_tethra.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\fast_float_15mats.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\fast_float_matsh.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\fast_float_cmyk.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\fast_8_matsh.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\fast_8_curves.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\fast_8_tethra.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\src\fast_16_tethra.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="..\..\COPYING.GPL3">
+ <Filter>doc</Filter>
+ </None>
+ <None Include="..\..\doc\LittleCMS fast float extensions 1.0.pdf">
+ <Filter>doc</Filter>
+ </None>
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin.vcxproj.user b/lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin.vcxproj.user
new file mode 100644
index 00000000..88a55094
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin.vcxproj.user
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup />
+</Project> \ No newline at end of file
diff --git a/lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin_testbed.vcxproj b/lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin_testbed.vcxproj
new file mode 100644
index 00000000..771e42ec
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin_testbed.vcxproj
@@ -0,0 +1,170 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{7629D670-C419-402B-8A90-747952EE9FC0}</ProjectGuid>
+ <Keyword>Win32Proj</Keyword>
+ <RootNamespace>fast_testbed</RootNamespace>
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v142</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v142</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v142</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v142</PlatformToolset>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <LinkIncremental>true</LinkIncremental>
+ <IntDir>$(Platform)\testbed_$(Configuration)\</IntDir>
+ <OutDir>$(ProjectDir)..\..\testbed\</OutDir>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <LinkIncremental>true</LinkIncremental>
+ <IntDir>$(Platform)\testbed_$(Configuration)\</IntDir>
+ <OutDir>$(ProjectDir)..\..\testbed\</OutDir>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <LinkIncremental>false</LinkIncremental>
+ <IntDir>$(Platform)\testbed_$(Configuration)\</IntDir>
+ <OutDir>$(ProjectDir)..\..\testbed\</OutDir>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <LinkIncremental>false</LinkIncremental>
+ <IntDir>$(Platform)\testbed_$(Configuration)\</IntDir>
+ <OutDir>$(ProjectDir)..\..\testbed\</OutDir>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level4</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>..\..\..\..\include;..\..\include;..\..\src</AdditionalIncludeDirectories>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level4</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>..\..\..\..\include;..\..\include;..\..\src</AdditionalIncludeDirectories>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <WarningLevel>Level4</WarningLevel>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>..\..\..\..\include;..\..\include;..\..\src</AdditionalIncludeDirectories>
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <WarningLevel>Level4</WarningLevel>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>..\..\..\..\include;..\..\include;..\..\src</AdditionalIncludeDirectories>
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\testbed\fast_float_testbed.c" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\..\..\Projects\VC2019\lcms2mt_static\lcms2mt_static.vcxproj">
+ <Project>{71dede59-3f1e-486b-a899-4283000f76b5}</Project>
+ </ProjectReference>
+ <ProjectReference Include="lcms2mt_fast_float_plugin.vcxproj">
+ <Project>{ad9ff79b-cf6e-4971-a7cf-daa47d636676}</Project>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
diff --git a/lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin_testbed.vcxproj.filters b/lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin_testbed.vcxproj.filters
new file mode 100644
index 00000000..4cec6b7c
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin_testbed.vcxproj.filters
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="Source Files">
+ <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+ <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+ </Filter>
+ <Filter Include="Header Files">
+ <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+ <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
+ </Filter>
+ <Filter Include="Resource Files">
+ <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+ <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\testbed\fast_float_testbed.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin_testbed.vcxproj.user b/lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin_testbed.vcxproj.user
new file mode 100644
index 00000000..88a55094
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/Projects/VC2019/lcms2mt_fast_float_plugin_testbed.vcxproj.user
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup />
+</Project> \ No newline at end of file
diff --git a/lcms2mt/plugins/fast_float/doc/LittleCMS fast float extensions 1.0.pdf b/lcms2mt/plugins/fast_float/doc/LittleCMS fast float extensions 1.0.pdf
new file mode 100644
index 00000000..e6e0daa1
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/doc/LittleCMS fast float extensions 1.0.pdf
Binary files differ
diff --git a/lcms2mt/plugins/fast_float/include/Makefile.am b/lcms2mt/plugins/fast_float/include/Makefile.am
new file mode 100644
index 00000000..01d8ed71
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/include/Makefile.am
@@ -0,0 +1,6 @@
+#
+# Makefile for include directory
+
+include_HEADERS = lcms2mt_fast_float.h
+
+EXTRA_DIST = lcms2mt_fast_float.h
diff --git a/lcms2mt/plugins/fast_float/include/lcms2mt_fast_float.h b/lcms2mt/plugins/fast_float/include/lcms2mt_fast_float.h
new file mode 100644
index 00000000..572d82d1
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/include/lcms2mt_fast_float.h
@@ -0,0 +1,139 @@
+//---------------------------------------------------------------------------------
+//
+// Little Color Management System, fast floating point extensions
+// Copyright (c) 1998-2020 Marti Maria Saguer, all rights reserved
+//
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+//---------------------------------------------------------------------------------
+
+#ifndef _LCMS2MT_FAST_FLOAT_H
+#define _LCMS2MT_FAST_FLOAT_H
+
+#include "lcms2mt_plugin.h"
+
+#ifndef CMS_USE_CPP_API
+# ifdef __cplusplus
+extern "C" {
+# endif
+#endif
+
+#define LCMS2_FAST_FLOAT_VERSION 1200
+
+// The one and only plug-in entry point. To install this plugin in your code
+// you need to place this in some initialization place:
+//
+// cmsPlugin(cmsFastFloatExtensions());
+//
+
+void* cmsFastFloatExtensions(void);
+
+
+// New encodings that the plug-in implements
+
+#define BIT15_SH(a) ((a) << 26)
+#define T_BIT15(a) (((a)>>26)&1)
+#define DITHER_SH(a) ((a) << 27)
+#define T_DITHER(a) (((a)>>27)&1)
+
+#define TYPE_GRAY_15 (COLORSPACE_SH(PT_GRAY)|CHANNELS_SH(1)|BYTES_SH(2)|BIT15_SH(1))
+#define TYPE_GRAY_15_REV (COLORSPACE_SH(PT_GRAY)|CHANNELS_SH(1)|BYTES_SH(2)|FLAVOR_SH(1)|BIT15_SH(1))
+#define TYPE_GRAY_15_SE (COLORSPACE_SH(PT_GRAY)|CHANNELS_SH(1)|BYTES_SH(2)|ENDIAN16_SH(1)|BIT15_SH(1))
+#define TYPE_GRAYA_15 (COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|BYTES_SH(2)|BIT15_SH(1))
+#define TYPE_GRAYA_15_SE (COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|BYTES_SH(2)|ENDIAN16_SH(1)|BIT15_SH(1))
+#define TYPE_GRAYA_15_PLANAR (COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|BYTES_SH(2)|PLANAR_SH(1)|BIT15_SH(1))
+
+#define TYPE_RGB_15 (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(2)|BIT15_SH(1))
+#define TYPE_RGB_15_PLANAR (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(2)|PLANAR_SH(1)|BIT15_SH(1))
+#define TYPE_RGB_15_SE (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(2)|ENDIAN16_SH(1)|BIT15_SH(1))
+
+#define TYPE_BGR_15 (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1)|BIT15_SH(1))
+#define TYPE_BGR_15_PLANAR (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1)|PLANAR_SH(1)|BIT15_SH(1))
+#define TYPE_BGR_15_SE (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1)|BIT15_SH(1))
+
+#define TYPE_RGBA_15 (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|BIT15_SH(1))
+#define TYPE_RGBA_15_PLANAR (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|PLANAR_SH(1)|BIT15_SH(1))
+#define TYPE_RGBA_15_SE (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|ENDIAN16_SH(1)|BIT15_SH(1))
+
+#define TYPE_ARGB_15 (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|SWAPFIRST_SH(1)|BIT15_SH(1))
+
+#define TYPE_ABGR_15 (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1)|BIT15_SH(1))
+#define TYPE_ABGR_15_PLANAR (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1)|PLANAR_SH(1)|BIT15_SH(1))
+#define TYPE_ABGR_15_SE (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1)|BIT15_SH(1))
+
+#define TYPE_BGRA_15 (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1)|SWAPFIRST_SH(1)|BIT15_SH(1))
+#define TYPE_BGRA_15_SE (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|ENDIAN16_SH(1)|DOSWAP_SH(1)|SWAPFIRST_SH(1)|BIT15_SH(1))
+
+#define TYPE_CMY_15 (COLORSPACE_SH(PT_CMY)|CHANNELS_SH(3)|BYTES_SH(2)|BIT15_SH(1))
+#define TYPE_YMC_15 (COLORSPACE_SH(PT_CMY)|CHANNELS_SH(3)|BYTES_SH(2)|DOSWAP_SH(1)|BIT15_SH(1))
+#define TYPE_CMY_15_PLANAR (COLORSPACE_SH(PT_CMY)|CHANNELS_SH(3)|BYTES_SH(2)|PLANAR_SH(1)|BIT15_SH(1))
+#define TYPE_CMY_15_SE (COLORSPACE_SH(PT_CMY)|CHANNELS_SH(3)|BYTES_SH(2)|ENDIAN16_SH(1)|BIT15_SH(1))
+
+#define TYPE_CMYK_15 (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|BIT15_SH(1))
+#define TYPE_CMYK_15_REV (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|FLAVOR_SH(1)|BIT15_SH(1))
+#define TYPE_CMYK_15_PLANAR (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|PLANAR_SH(1)|BIT15_SH(1))
+#define TYPE_CMYK_15_SE (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|ENDIAN16_SH(1)|BIT15_SH(1))
+
+#define TYPE_KYMC_15 (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|DOSWAP_SH(1)|BIT15_SH(1))
+#define TYPE_KYMC_15_SE (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|DOSWAP_SH(1)|ENDIAN16_SH(1)|BIT15_SH(1))
+
+#define TYPE_KCMY_15 (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|SWAPFIRST_SH(1)|BIT15_SH(1))
+#define TYPE_KCMY_15_REV (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|FLAVOR_SH(1)|SWAPFIRST_SH(1)|BIT15_SH(1))
+#define TYPE_KCMY_15_SE (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(2)|ENDIAN16_SH(1)|SWAPFIRST_SH(1)|BIT15_SH(1))
+
+#define TYPE_GRAY_8_DITHER (COLORSPACE_SH(PT_GRAY)|CHANNELS_SH(1)|BYTES_SH(1)|DITHER_SH(1))
+#define TYPE_RGB_8_DITHER (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(1)|DITHER_SH(1))
+#define TYPE_RGBA_8_DITHER (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(1)|EXTRA_SH(1)|DITHER_SH(1))
+#define TYPE_BGR_8_DITHER (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(1)|DOSWAP_SH(1)|DITHER_SH(1))
+#define TYPE_ABGR_8_DITHER (COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(1)|DOSWAP_SH(1)|EXTRA_SH(1)|DITHER_SH(1))
+#define TYPE_CMYK_8_DITHER (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(1)|DITHER_SH(1))
+#define TYPE_KYMC_8_DITHER (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(1)|DOSWAP_SH(1)|DITHER_SH(1))
+
+
+#define TYPE_AGRAY_8 (COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|DOSWAP_SH(1)|BYTES_SH(1))
+#define TYPE_AGRAY_16 (COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|DOSWAP_SH(1)|BYTES_SH(2))
+#define TYPE_AGRAY_FLT (FLOAT_SH(1)|COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|DOSWAP_SH(1)|BYTES_SH(4))
+#define TYPE_GRAYA_FLT (FLOAT_SH(1)|COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|BYTES_SH(4))
+#define TYPE_AGRAY_DBL (FLOAT_SH(1)|COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|DOSWAP_SH(1)|BYTES_SH(0))
+
+#define TYPE_ACMYK_8 (COLORSPACE_SH(PT_CMYK)|EXTRA_SH(1)|CHANNELS_SH(4)|BYTES_SH(1)|SWAPFIRST_SH(1))
+#define TYPE_KYMCA_8 (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|EXTRA_SH(1)|BYTES_SH(1)|DOSWAP_SH(1)|SWAPFIRST_SH(1))
+#define TYPE_AKYMC_8 (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|EXTRA_SH(1)|BYTES_SH(1)|DOSWAP_SH(1))
+
+#define TYPE_CMYKA_16 (COLORSPACE_SH(PT_CMYK)|EXTRA_SH(1)|CHANNELS_SH(4)|BYTES_SH(2))
+#define TYPE_ACMYK_16 (COLORSPACE_SH(PT_CMYK)|EXTRA_SH(1)|CHANNELS_SH(4)|BYTES_SH(2)|SWAPFIRST_SH(1))
+#define TYPE_KYMCA_16 (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|EXTRA_SH(1)|BYTES_SH(2)|DOSWAP_SH(1)|SWAPFIRST_SH(1))
+#define TYPE_AKYMC_16 (COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|EXTRA_SH(1)|BYTES_SH(2)|DOSWAP_SH(1))
+
+
+#define TYPE_AGRAY_8_PLANAR (COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|BYTES_SH(1)|PLANAR_SH(1)|SWAPFIRST_SH(1))
+#define TYPE_AGRAY_16_PLANAR (COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|BYTES_SH(2)|PLANAR_SH(1)|SWAPFIRST_SH(1))
+
+#define TYPE_GRAYA_FLT_PLANAR (FLOAT_SH(1)|COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|BYTES_SH(4)|PLANAR_SH(1))
+#define TYPE_AGRAY_FLT_PLANAR (FLOAT_SH(1)|COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|BYTES_SH(4)|PLANAR_SH(1)|SWAPFIRST_SH(1))
+
+#define TYPE_GRAYA_DBL_PLANAR (FLOAT_SH(1)|COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|BYTES_SH(0)|PLANAR_SH(1))
+#define TYPE_AGRAY_DBL_PLANAR (FLOAT_SH(1)|COLORSPACE_SH(PT_GRAY)|EXTRA_SH(1)|CHANNELS_SH(1)|BYTES_SH(0)|PLANAR_SH(1)|SWAPFIRST_SH(1))
+
+#define TYPE_ARGB_16_PLANAR (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|SWAPFIRST_SH(1)|PLANAR_SH(1))
+#define TYPE_BGRA_16_PLANAR (COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(2)|SWAPFIRST_SH(1)|DOSWAP_SH(1)|PLANAR_SH(1))
+
+#ifndef CMS_USE_CPP_API
+# ifdef __cplusplus
+ }
+# endif
+#endif
+
+#endif
diff --git a/lcms2mt/plugins/fast_float/src/Makefile.am b/lcms2mt/plugins/fast_float/src/Makefile.am
new file mode 100644
index 00000000..a7d1af38
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/src/Makefile.am
@@ -0,0 +1,27 @@
+#
+# Makefile for building lcms2_fast_float library
+#
+
+# Don't require all the GNU mandated files
+AUTOMAKE_OPTIONS = 1.7 foreign
+
+includedir = ${prefix}/include
+
+# Shared libraries built in this directory
+lib_LTLIBRARIES = liblcms2mt_fast_float.la
+
+LIBRARY_CURRENT = 1
+LIBRARY_REVISION = 1
+LIBRARY_AGE = 0
+
+INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I$(srcdir)/../include -I$(builddir)/../include
+
+liblcms2mt_fast_float_la_LDFLAGS = -no-undefined \
+ -version-info $(LIBRARY_CURRENT):$(LIBRARY_REVISION):$(LIBRARY_AGE)
+
+liblcms2mt_fast_float_la_LIBADD = $(LCMS_LIB_DEPLIBS) $(top_builddir)/src/liblcms2mt.la
+
+liblcms2mt_fast_float_la_SOURCES = \
+ fast_float_15bits.c fast_float_15mats.c fast_float_curves.c fast_float_matsh.c fast_float_separate.c \
+ fast_float_sup.c fast_float_tethra.c fast_float_cmyk.c fast_float_internal.h \
+ fast_8_curves.c fast_8_matsh.c fast_8_tethra.c
diff --git a/lcms2mt/plugins/fast_float/src/fast_16_tethra.c b/lcms2mt/plugins/fast_float/src/fast_16_tethra.c
new file mode 100644
index 00000000..a67340d5
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/src/fast_16_tethra.c
@@ -0,0 +1,370 @@
+//---------------------------------------------------------------------------------
+//
+// Little Color Management System, fast floating point extensions
+// Copyright (c) 1998-2020 Marti Maria Saguer, all rights reserved
+//
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+//---------------------------------------------------------------------------------
+
+#include "fast_float_internal.h"
+
+// lcms internal
+cmsBool _cmsOptimizePipeline(cmsContext ContextID,
+ cmsPipeline** Lut,
+ cmsUInt32Number Intent,
+ cmsUInt32Number* InputFormat,
+ cmsUInt32Number* OutputFormat,
+ cmsUInt32Number* dwFlags);
+
+
+// Optimization for 16 bits, 3 inputs only
+typedef struct {
+
+ const cmsInterpParams* p; // Tetrahedrical interpolation parameters. This is a not-owned pointer.
+
+} Performance16Data;
+
+
+// Precomputes tables for 16-bit on input devicelink.
+static
+Performance16Data* Performance16alloc(cmsContext ContextID, const cmsInterpParams* p)
+{
+ Performance16Data* p16;
+
+ p16 = (Performance16Data*) _cmsMallocZero(ContextID, sizeof(Performance16Data));
+ if (p16 == NULL) return NULL;
+
+ p16 ->p = p;
+
+ return p16;
+}
+
+static
+void Performance16free(cmsContext ContextID, void* ptr)
+{
+ _cmsFree(ContextID, ptr);
+}
+
+/**
+* Because cmsChangeBuffersFormat, we have to allow this code to output data in either 8 or 16 bits.
+* The increments are already computed correctly, but the data may change. So, we use a macro to
+* increase xput
+*/
+#define TO_OUTPUT_16(d,v) do { *(cmsUInt16Number*) (d) = v; } while(0)
+#define TO_OUTPUT_8(d,v) do { *(cmsUInt8Number*) (d) = FROM_16_TO_8(v); } while(0)
+
+#define TO_OUTPUT(d,v) do { if (out16) TO_OUTPUT_16(d,v); else TO_OUTPUT_8(d,v); } while(0)
+
+#define FROM_INPUT(v) (in16 ? (*((const cmsUInt16Number*)(v))) : FROM_8_TO_16(*((const cmsUInt8Number*)(v))))
+
+static
+void PerformanceEval16(cmsContext ContextID,
+ struct _cmstransform_struct *CMMcargo,
+ const void* Input,
+ void* Output,
+ cmsUInt32Number PixelsPerLine,
+ cmsUInt32Number LineCount,
+ const cmsStride* Stride)
+{
+
+ cmsUInt16Number r, g, b;
+ int x0, y0, z0;
+ cmsS15Fixed16Number rx, ry, rz;
+ cmsS15Fixed16Number fx, fy, fz;
+ cmsS15Fixed16Number c0, c1, c2, c3, Rest;
+ cmsUInt32Number OutChan, TotalPlusAlpha;
+ cmsS15Fixed16Number X0, X1, Y0, Y1, Z0, Z1;
+ Performance16Data* p16 = (Performance16Data*)_cmsGetTransformUserData(CMMcargo);
+ const cmsInterpParams* p = p16->p;
+ cmsUInt32Number TotalOut = p->nOutputs;
+ const cmsUInt16Number* BaseTable = (const cmsUInt16Number*)p->Table;
+ const cmsUInt16Number* LutTable;
+
+ cmsUInt8Number* out[cmsMAXCHANNELS];
+ cmsUInt16Number res16;
+
+ cmsUInt32Number i, ii;
+
+ cmsUInt32Number SourceStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number SourceIncrements[cmsMAXCHANNELS];
+ cmsUInt32Number DestStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number DestIncrements[cmsMAXCHANNELS];
+
+ const cmsUInt8Number* rin;
+ const cmsUInt8Number* gin;
+ const cmsUInt8Number* bin;
+ const cmsUInt8Number* ain = NULL;
+
+ int in16, out16; // Used by macros!
+
+ cmsUInt32Number nalpha, strideIn, strideOut;
+
+ cmsUInt32Number dwInFormat = cmsGetTransformInputFormat(ContextID, (cmsHTRANSFORM)CMMcargo);
+ cmsUInt32Number dwOutFormat = cmsGetTransformOutputFormat(ContextID, (cmsHTRANSFORM)CMMcargo);
+
+ _cmsComputeComponentIncrements(dwInFormat, Stride->BytesPerPlaneIn, NULL, &nalpha, SourceStartingOrder, SourceIncrements);
+ _cmsComputeComponentIncrements(dwOutFormat, Stride->BytesPerPlaneOut, NULL, &nalpha, DestStartingOrder, DestIncrements);
+
+ in16 = (T_BYTES(dwInFormat) == 2);
+ out16 = (T_BYTES(dwOutFormat) == 2);
+
+ strideIn = strideOut = 0;
+ for (i = 0; i < LineCount; i++) {
+
+ rin = (const cmsUInt8Number*)Input + SourceStartingOrder[0] + strideIn;
+ gin = (const cmsUInt8Number*)Input + SourceStartingOrder[1] + strideIn;
+ bin = (const cmsUInt8Number*)Input + SourceStartingOrder[2] + strideIn;
+ if (nalpha)
+ ain = (const cmsUInt8Number*)Input + SourceStartingOrder[3] + strideIn;
+
+ TotalPlusAlpha = TotalOut;
+ if (ain) TotalPlusAlpha++;
+
+ for (OutChan = 0; OutChan < TotalPlusAlpha; OutChan++) {
+ out[OutChan] = (cmsUInt8Number*)Output + DestStartingOrder[OutChan] + strideOut;
+ }
+
+
+ for (ii = 0; ii < PixelsPerLine; ii++) {
+
+ r = FROM_INPUT(rin);
+ g = FROM_INPUT(gin);
+ b = FROM_INPUT(bin);
+
+ rin += SourceIncrements[0];
+ gin += SourceIncrements[1];
+ bin += SourceIncrements[2];
+
+ fx = _cmsToFixedDomain((int)r * p->Domain[0]);
+ fy = _cmsToFixedDomain((int)g * p->Domain[1]);
+ fz = _cmsToFixedDomain((int)b * p->Domain[2]);
+
+ x0 = FIXED_TO_INT(fx);
+ y0 = FIXED_TO_INT(fy);
+ z0 = FIXED_TO_INT(fz);
+
+ rx = FIXED_REST_TO_INT(fx);
+ ry = FIXED_REST_TO_INT(fy);
+ rz = FIXED_REST_TO_INT(fz);
+
+ X0 = p->opta[2] * x0;
+ X1 = (r == 0xFFFFU ? 0 : p->opta[2]);
+
+ Y0 = p->opta[1] * y0;
+ Y1 = (g == 0xFFFFU ? 0 : p->opta[1]);
+
+ Z0 = p->opta[0] * z0;
+ Z1 = (b == 0xFFFFU ? 0 : p->opta[0]);
+
+
+ LutTable = &BaseTable[X0 + Y0 + Z0];
+
+ // Output should be computed as x = ROUND_FIXED_TO_INT(_cmsToFixedDomain(Rest))
+ // which expands as: x = (Rest + ((Rest+0x7fff)/0xFFFF) + 0x8000)>>16
+ // This can be replaced by: t = Rest+0x8001, x = (t + (t>>16))>>16
+ // at the cost of being off by one at 7fff and 17ffe.
+
+ if (rx >= ry) {
+ if (ry >= rz) {
+ Y1 += X1;
+ Z1 += Y1;
+ for (OutChan = 0; OutChan < TotalOut; OutChan++) {
+ c1 = LutTable[X1];
+ c2 = LutTable[Y1];
+ c3 = LutTable[Z1];
+ c0 = *LutTable++;
+ c3 -= c2;
+ c2 -= c1;
+ c1 -= c0;
+ Rest = c1 * rx + c2 * ry + c3 * rz + 0x8001;
+ res16 = (cmsUInt16Number)c0 + ((Rest + (Rest >> 16)) >> 16);
+ TO_OUTPUT(out[OutChan], res16);
+ out[OutChan] += DestIncrements[OutChan];
+ }
+ }
+ else if (rz >= rx) {
+ X1 += Z1;
+ Y1 += X1;
+ for (OutChan = 0; OutChan < TotalOut; OutChan++) {
+ c1 = LutTable[X1];
+ c2 = LutTable[Y1];
+ c3 = LutTable[Z1];
+ c0 = *LutTable++;
+ c2 -= c1;
+ c1 -= c3;
+ c3 -= c0;
+ Rest = c1 * rx + c2 * ry + c3 * rz + 0x8001;
+ res16 = (cmsUInt16Number)c0 + ((Rest + (Rest >> 16)) >> 16);
+ TO_OUTPUT(out[OutChan], res16);
+ out[OutChan] += DestIncrements[OutChan];
+ }
+ }
+ else {
+ Z1 += X1;
+ Y1 += Z1;
+ for (OutChan = 0; OutChan < TotalOut; OutChan++) {
+ c1 = LutTable[X1];
+ c2 = LutTable[Y1];
+ c3 = LutTable[Z1];
+ c0 = *LutTable++;
+ c2 -= c3;
+ c3 -= c1;
+ c1 -= c0;
+ Rest = c1 * rx + c2 * ry + c3 * rz + 0x8001;
+ res16 = (cmsUInt16Number)c0 + ((Rest + (Rest >> 16)) >> 16);
+ TO_OUTPUT(out[OutChan], res16);
+ out[OutChan] += DestIncrements[OutChan];
+ }
+ }
+ }
+ else {
+ if (rx >= rz) {
+ X1 += Y1;
+ Z1 += X1;
+ for (OutChan = 0; OutChan < TotalOut; OutChan++) {
+ c1 = LutTable[X1];
+ c2 = LutTable[Y1];
+ c3 = LutTable[Z1];
+ c0 = *LutTable++;
+ c3 -= c1;
+ c1 -= c2;
+ c2 -= c0;
+ Rest = c1 * rx + c2 * ry + c3 * rz + 0x8001;
+ res16 = (cmsUInt16Number)c0 + ((Rest + (Rest >> 16)) >> 16);
+ TO_OUTPUT(out[OutChan], res16);
+ out[OutChan] += DestIncrements[OutChan];
+ }
+ }
+ else if (ry >= rz) {
+ Z1 += Y1;
+ X1 += Z1;
+ for (OutChan = 0; OutChan < TotalOut; OutChan++) {
+ c1 = LutTable[X1];
+ c2 = LutTable[Y1];
+ c3 = LutTable[Z1];
+ c0 = *LutTable++;
+ c1 -= c3;
+ c3 -= c2;
+ c2 -= c0;
+ Rest = c1 * rx + c2 * ry + c3 * rz + 0x8001;
+ res16 = (cmsUInt16Number)c0 + ((Rest + (Rest >> 16)) >> 16);
+ TO_OUTPUT(out[OutChan], res16);
+ out[OutChan] += DestIncrements[OutChan];
+ }
+ }
+ else {
+ Y1 += Z1;
+ X1 += Y1;
+ for (OutChan = 0; OutChan < TotalOut; OutChan++) {
+ c1 = LutTable[X1];
+ c2 = LutTable[Y1];
+ c3 = LutTable[Z1];
+ c0 = *LutTable++;
+ c1 -= c2;
+ c2 -= c3;
+ c3 -= c0;
+ Rest = c1 * rx + c2 * ry + c3 * rz + 0x8001;
+ res16 = (cmsUInt16Number)c0 + ((Rest + (Rest >> 16)) >> 16);
+ TO_OUTPUT(out[OutChan], res16);
+ out[OutChan] += DestIncrements[OutChan];
+ }
+ }
+ }
+
+ if (ain)
+ {
+ res16 = *(const cmsUInt16Number*)ain;
+ TO_OUTPUT(out[OutChan], res16);
+ out[TotalOut] += DestIncrements[TotalOut];
+ }
+
+ }
+
+ strideIn += Stride->BytesPerLineIn;
+ strideOut += Stride->BytesPerLineOut;
+ }
+}
+
+#undef DENS
+
+
+
+// --------------------------------------------------------------------------------------------------------------
+
+cmsBool Optimize16BitRGBTransform(cmsContext ContextID,
+ _cmsTransformFn* TransformFn,
+ void** UserData,
+ _cmsFreeUserDataFn* FreeDataFn,
+ cmsPipeline** Lut,
+ cmsUInt32Number* InputFormat,
+ cmsUInt32Number* OutputFormat,
+ cmsUInt32Number* dwFlags)
+{
+ cmsStage* mpe;
+ Performance16Data* p16;
+ _cmsStageCLutData* data;
+ cmsUInt32Number newFlags;
+ cmsStage* OptimizedCLUTmpe;
+
+
+ // For empty transforms, do nothing
+ if (*Lut == NULL) return FALSE;
+
+ // This is a loosy optimization! does not apply in floating-point cases
+ if (T_FLOAT(*InputFormat) || T_FLOAT(*OutputFormat)) return FALSE;
+
+ // Only on 16-bit
+ if (T_BYTES(*InputFormat) != 2 || T_BYTES(*OutputFormat) != 2) return FALSE;
+
+ // Only real 16 bits
+ if (T_BIT15(*InputFormat) != 0 || T_BIT15(*OutputFormat) != 0) return FALSE;
+
+ // Only on input RGB
+ if (T_COLORSPACE(*InputFormat) != PT_RGB) return FALSE;
+
+ // Named color pipelines cannot be optimized either
+ for (mpe = cmsPipelineGetPtrToFirstStage(ContextID, *Lut);
+ mpe != NULL;
+ mpe = cmsStageNext(ContextID, mpe)) {
+ if (cmsStageType(ContextID, mpe) == cmsSigNamedColorElemType) return FALSE;
+ }
+
+ newFlags = *dwFlags | cmsFLAGS_FORCE_CLUT;
+
+ if (!_cmsOptimizePipeline(ContextID,
+ Lut,
+ INTENT_PERCEPTUAL, // Dont care
+ InputFormat,
+ OutputFormat,
+ &newFlags)) return FALSE;
+
+ OptimizedCLUTmpe = cmsPipelineGetPtrToFirstStage(ContextID, *Lut);
+
+ // Set the evaluator
+ data = (_cmsStageCLutData*)cmsStageData(ContextID, OptimizedCLUTmpe);
+
+ p16 = Performance16alloc(ContextID, data->Params);
+ if (p16 == NULL) return FALSE;
+
+ *TransformFn = (_cmsTransformFn) PerformanceEval16;
+ *UserData = p16;
+ *FreeDataFn = Performance16free;
+ *InputFormat |= 0x02000000;
+ *OutputFormat |= 0x02000000;
+ *dwFlags |= cmsFLAGS_CAN_CHANGE_FORMATTER;
+
+ return TRUE;
+}
diff --git a/lcms2mt/plugins/fast_float/src/fast_8_curves.c b/lcms2mt/plugins/fast_float/src/fast_8_curves.c
new file mode 100644
index 00000000..cb8e5df6
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/src/fast_8_curves.c
@@ -0,0 +1,409 @@
+//---------------------------------------------------------------------------------
+//
+// Little Color Management System, fast floating point extensions
+// Copyright (c) 1998-2020 Marti Maria Saguer, all rights reserved
+//
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+//---------------------------------------------------------------------------------
+
+#include "fast_float_internal.h"
+
+// Curves, optimization is valid for 8 bits only
+typedef struct {
+
+ int nCurves;
+ cmsUInt8Number Curves[cmsMAXCHANNELS][256];
+
+} Curves8Data;
+
+
+// Evaluator for RGB 8-bit curves. This are just 1D tables
+static void FastEvaluateRGBCurves8(cmsContext ContextID,
+ struct _cmstransform_struct *CMMcargo,
+ const void* Input,
+ void* Output,
+ cmsUInt32Number PixelsPerLine,
+ cmsUInt32Number LineCount,
+ const cmsStride* Stride)
+{
+ cmsUInt32Number i, ii;
+
+ cmsUInt32Number SourceStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number SourceIncrements[cmsMAXCHANNELS];
+ cmsUInt32Number DestStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number DestIncrements[cmsMAXCHANNELS];
+
+ const cmsUInt8Number* rin;
+ const cmsUInt8Number* gin;
+ const cmsUInt8Number* bin;
+ const cmsUInt8Number* ain = NULL;
+
+ cmsUInt8Number* rout;
+ cmsUInt8Number* gout;
+ cmsUInt8Number* bout;
+ cmsUInt8Number* aout = NULL;
+
+ cmsUInt32Number nalpha, strideIn, strideOut;
+
+ Curves8Data* Data = (Curves8Data*)_cmsGetTransformUserData(CMMcargo);
+
+ _cmsComputeComponentIncrements(cmsGetTransformInputFormat(ContextID, (cmsHTRANSFORM)CMMcargo), Stride->BytesPerPlaneIn, NULL, &nalpha, SourceStartingOrder, SourceIncrements);
+ _cmsComputeComponentIncrements(cmsGetTransformOutputFormat(ContextID, (cmsHTRANSFORM)CMMcargo), Stride->BytesPerPlaneOut, NULL, &nalpha, DestStartingOrder, DestIncrements);
+
+ strideIn = strideOut = 0;
+ for (i = 0; i < LineCount; i++) {
+
+ rin = (const cmsUInt8Number*)Input + SourceStartingOrder[0] + strideIn;
+ gin = (const cmsUInt8Number*)Input + SourceStartingOrder[1] + strideIn;
+ bin = (const cmsUInt8Number*)Input + SourceStartingOrder[2] + strideIn;
+ if (nalpha)
+ ain = (const cmsUInt8Number*)Input + SourceStartingOrder[3] + strideIn;
+
+ rout = (cmsUInt8Number*)Output + DestStartingOrder[0] + strideOut;
+ gout = (cmsUInt8Number*)Output + DestStartingOrder[1] + strideOut;
+ bout = (cmsUInt8Number*)Output + DestStartingOrder[2] + strideOut;
+ if (nalpha)
+ aout = (cmsUInt8Number*)Output + DestStartingOrder[3] + strideOut;
+
+ for (ii = 0; ii < PixelsPerLine; ii++) {
+
+
+ *rout = Data->Curves[0][*rin];
+ *gout = Data->Curves[1][*gin];
+ *bout = Data->Curves[2][*bin];
+
+ // Handle alpha
+ if (ain) {
+ *aout = *ain;
+ }
+
+ rin += SourceIncrements[0];
+ gin += SourceIncrements[1];
+ bin += SourceIncrements[2];
+ if (ain) ain += SourceIncrements[3];
+
+ rout += DestIncrements[0];
+ gout += DestIncrements[1];
+ bout += DestIncrements[2];
+ if (aout) aout += DestIncrements[3];
+ }
+
+ strideIn += Stride->BytesPerLineIn;
+ strideOut += Stride->BytesPerLineOut;
+ }
+}
+
+
+// Do nothing but arrange the format. RGB
+static void FastRGBIdentity8(cmsContext ContextID,
+ struct _cmstransform_struct *CMMcargo,
+ const void* Input,
+ void* Output,
+ cmsUInt32Number PixelsPerLine,
+ cmsUInt32Number LineCount,
+ const cmsStride* Stride)
+{
+ cmsUInt32Number i, ii;
+
+ cmsUInt32Number SourceStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number SourceIncrements[cmsMAXCHANNELS];
+ cmsUInt32Number DestStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number DestIncrements[cmsMAXCHANNELS];
+
+ const cmsUInt8Number* rin;
+ const cmsUInt8Number* gin;
+ const cmsUInt8Number* bin;
+ const cmsUInt8Number* ain = NULL;
+
+ cmsUInt8Number* rout;
+ cmsUInt8Number* gout;
+ cmsUInt8Number* bout;
+ cmsUInt8Number* aout = NULL;
+
+ cmsUInt32Number nalpha, strideIn, strideOut;
+
+ _cmsComputeComponentIncrements(cmsGetTransformInputFormat(ContextID, (cmsHTRANSFORM)CMMcargo), Stride->BytesPerPlaneIn, NULL, &nalpha, SourceStartingOrder, SourceIncrements);
+ _cmsComputeComponentIncrements(cmsGetTransformOutputFormat(ContextID, (cmsHTRANSFORM)CMMcargo), Stride->BytesPerPlaneOut, NULL, &nalpha, DestStartingOrder, DestIncrements);
+
+ strideIn = strideOut = 0;
+ for (i = 0; i < LineCount; i++) {
+
+ rin = (const cmsUInt8Number*)Input + SourceStartingOrder[0] + strideIn;
+ gin = (const cmsUInt8Number*)Input + SourceStartingOrder[1] + strideIn;
+ bin = (const cmsUInt8Number*)Input + SourceStartingOrder[2] + strideIn;
+ if (nalpha)
+ ain = (const cmsUInt8Number*)Input + SourceStartingOrder[3] + strideIn;
+
+ rout = (cmsUInt8Number*)Output + DestStartingOrder[0] + strideOut;
+ gout = (cmsUInt8Number*)Output + DestStartingOrder[1] + strideOut;
+ bout = (cmsUInt8Number*)Output + DestStartingOrder[2] + strideOut;
+ if (nalpha)
+ aout = (cmsUInt8Number*)Output + DestStartingOrder[3] + strideOut;
+
+ for (ii = 0; ii < PixelsPerLine; ii++) {
+
+
+ *rout = *rin;
+ *gout = *gin;
+ *bout = *bin;
+
+ // Handle alpha
+ if (ain) {
+ *aout = *ain;
+ }
+
+ rin += SourceIncrements[0];
+ gin += SourceIncrements[1];
+ bin += SourceIncrements[2];
+ if (ain) ain += SourceIncrements[3];
+
+ rout += DestIncrements[0];
+ gout += DestIncrements[1];
+ bout += DestIncrements[2];
+ if (aout) aout += DestIncrements[3];
+ }
+
+ strideIn += Stride->BytesPerLineIn;
+ strideOut += Stride->BytesPerLineOut;
+ }
+}
+
+
+
+// Evaluate 1 channel only
+static void FastEvaluateGrayCurves8(cmsContext ContextID,
+ struct _cmstransform_struct *CMMcargo,
+ const void* Input,
+ void* Output,
+ cmsUInt32Number PixelsPerLine,
+ cmsUInt32Number LineCount,
+ const cmsStride* Stride)
+{
+ cmsUInt32Number i, ii;
+
+ cmsUInt32Number SourceStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number SourceIncrements[cmsMAXCHANNELS];
+ cmsUInt32Number DestStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number DestIncrements[cmsMAXCHANNELS];
+
+ const cmsUInt8Number* gin;
+ const cmsUInt8Number* ain = NULL;
+
+ cmsUInt8Number* gout;
+ cmsUInt8Number* aout = NULL;
+
+ cmsUInt32Number nalpha, strideIn, strideOut;
+
+ Curves8Data* Data = (Curves8Data*)_cmsGetTransformUserData(CMMcargo);
+
+ _cmsComputeComponentIncrements(cmsGetTransformInputFormat(ContextID, (cmsHTRANSFORM)CMMcargo), Stride->BytesPerPlaneIn, NULL, &nalpha, SourceStartingOrder, SourceIncrements);
+ _cmsComputeComponentIncrements(cmsGetTransformOutputFormat(ContextID, (cmsHTRANSFORM)CMMcargo), Stride->BytesPerPlaneOut, NULL, &nalpha, DestStartingOrder, DestIncrements);
+
+ strideIn = strideOut = 0;
+ for (i = 0; i < LineCount; i++) {
+
+ gin = (const cmsUInt8Number*)Input + SourceStartingOrder[0] + strideIn;
+ if (nalpha)
+ ain = (const cmsUInt8Number*)Input + SourceStartingOrder[1] + strideIn;
+
+ gout = (cmsUInt8Number*)Output + DestStartingOrder[0] + strideOut;
+ if (nalpha)
+ aout = (cmsUInt8Number*)Output + DestStartingOrder[1] + strideOut;
+
+ for (ii = 0; ii < PixelsPerLine; ii++) {
+
+ *gout = Data->Curves[0][*gin];
+
+ // Handle alpha
+ if (ain) {
+ *aout = *ain;
+ }
+
+ gin += SourceIncrements[0];
+
+ if (ain) ain += SourceIncrements[1];
+
+ gout += DestIncrements[0];
+
+ if (aout) aout += DestIncrements[1];
+ }
+
+ strideIn += Stride->BytesPerLineIn;
+ strideOut += Stride->BytesPerLineOut;
+ }
+}
+
+
+static void FastGrayIdentity8(cmsContext ContextID,
+ struct _cmstransform_struct *CMMcargo,
+ const void* Input,
+ void* Output,
+ cmsUInt32Number PixelsPerLine,
+ cmsUInt32Number LineCount,
+ const cmsStride* Stride)
+{
+ cmsUInt32Number i, ii;
+
+ cmsUInt32Number SourceStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number SourceIncrements[cmsMAXCHANNELS];
+ cmsUInt32Number DestStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number DestIncrements[cmsMAXCHANNELS];
+
+ const cmsUInt8Number* gin;
+ const cmsUInt8Number* ain = NULL;
+
+ cmsUInt8Number* gout;
+ cmsUInt8Number* aout = NULL;
+
+ cmsUInt32Number nalpha, strideIn, strideOut;
+
+ _cmsComputeComponentIncrements(cmsGetTransformInputFormat(ContextID, (cmsHTRANSFORM)CMMcargo), Stride->BytesPerPlaneIn, NULL, &nalpha, SourceStartingOrder, SourceIncrements);
+ _cmsComputeComponentIncrements(cmsGetTransformOutputFormat(ContextID, (cmsHTRANSFORM)CMMcargo), Stride->BytesPerPlaneOut, NULL, &nalpha, DestStartingOrder, DestIncrements);
+
+ strideIn = strideOut = 0;
+ for (i = 0; i < LineCount; i++) {
+
+ gin = (const cmsUInt8Number*)Input + SourceStartingOrder[0] + strideIn;
+ if (nalpha)
+ ain = (const cmsUInt8Number*)Input + SourceStartingOrder[1] + strideIn;
+
+ gout = (cmsUInt8Number*)Output + DestStartingOrder[0] + strideOut;
+ if (nalpha)
+ aout = (cmsUInt8Number*)Output + DestStartingOrder[1] + strideOut;
+
+ for (ii = 0; ii < PixelsPerLine; ii++) {
+
+ *gout = *gin;
+
+ // Handle alpha
+ if (ain) {
+ *aout = *ain;
+ }
+
+ gin += SourceIncrements[0];
+
+ if (ain) ain += SourceIncrements[1];
+
+ gout += DestIncrements[0];
+
+ if (aout) aout += DestIncrements[1];
+ }
+
+ strideIn += Stride->BytesPerLineIn;
+ strideOut += Stride->BytesPerLineOut;
+ }
+}
+
+
+
+
+
+// Try to see if the curves are linear
+static
+cmsBool AllCurvesAreLinear(Curves8Data* data)
+{
+ int i, j;
+
+ for (i=0; i < 3; i++) {
+ for (j = 0; j < 256; j++) {
+ if (data ->Curves[i][j] != j) return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+
+static
+Curves8Data* ComputeCompositeCurves(cmsContext ContextID, cmsUInt32Number nChan, cmsPipeline* Src)
+{
+ cmsUInt32Number i, j;
+ cmsFloat32Number InFloat[3], OutFloat[3];
+
+ Curves8Data* Data = (Curves8Data*) _cmsMallocZero(ContextID, sizeof(Curves8Data));
+ if (Data == NULL) return NULL;
+
+ // Create target curves
+ for (i=0; i < 256; i++) {
+
+ for (j=0; j <nChan; j++)
+ InFloat[j] = (cmsFloat32Number) ((cmsFloat64Number) i / 255.0);
+
+ cmsPipelineEvalFloat(ContextID, InFloat, OutFloat, Src);
+
+ for (j=0; j < nChan; j++)
+ Data -> Curves[j][i] = FROM_16_TO_8(_cmsSaturateWord(OutFloat[j] * 65535.0));
+ }
+
+ return Data;
+}
+
+
+// If the target LUT holds only curves, the optimization procedure is to join all those
+// curves together. That only works on curves and does not work on matrices.
+// Any number of channels up to 16
+cmsBool Optimize8ByJoiningCurves(cmsContext ContextID,
+ _cmsTransformFn* TransformFn,
+ void** UserData,
+ _cmsFreeUserDataFn* FreeUserData,
+ cmsPipeline** Lut,
+ cmsUInt32Number* InputFormat,
+ cmsUInt32Number* OutputFormat,
+ cmsUInt32Number* dwFlags)
+{
+
+ cmsPipeline* Src = *Lut;
+ cmsStage* mpe;
+ Curves8Data* Data;
+ cmsUInt32Number nChans;
+
+ // This is a loosy optimization! does not apply in floating-point cases
+ if (T_FLOAT(*InputFormat) || T_FLOAT(*OutputFormat)) return FALSE;
+
+ // Only on 8-bit
+ if (T_BYTES(*InputFormat) != 1 || T_BYTES(*OutputFormat) != 1) return FALSE;
+
+ // Curves need same channels on input and output (despite extra channels may differ)
+ nChans = T_CHANNELS(*InputFormat);
+ if (nChans != T_CHANNELS(*OutputFormat)) return FALSE;
+
+ // gray and RGB
+ if (nChans != 1 && nChans != 3) return FALSE;
+
+ // Only curves in this LUT?
+ for (mpe = cmsPipelineGetPtrToFirstStage(ContextID, Src);
+ mpe != NULL;
+ mpe = cmsStageNext(ContextID, mpe)) {
+
+ if (cmsStageType(ContextID, mpe) != cmsSigCurveSetElemType) return FALSE;
+ }
+
+ Data = ComputeCompositeCurves(ContextID, nChans, Src);
+
+ *dwFlags |= cmsFLAGS_NOCACHE;
+ *dwFlags &= ~cmsFLAGS_CAN_CHANGE_FORMATTER;
+ *UserData = Data;
+ *FreeUserData = _cmsFree;
+
+ // Maybe the curves are linear at the end
+ if (nChans == 1)
+ *TransformFn = (_cmsTransformFn) (AllCurvesAreLinear(Data) ? FastGrayIdentity8 : FastEvaluateGrayCurves8);
+ else
+ *TransformFn = (_cmsTransformFn) (AllCurvesAreLinear(Data) ? FastRGBIdentity8 : FastEvaluateRGBCurves8);
+
+ return TRUE;
+
+}
diff --git a/lcms2mt/plugins/fast_float/src/fast_8_matsh.c b/lcms2mt/plugins/fast_float/src/fast_8_matsh.c
new file mode 100644
index 00000000..26dc12a1
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/src/fast_8_matsh.c
@@ -0,0 +1,399 @@
+//---------------------------------------------------------------------------------
+//
+// Little Color Management System, fast floating point extensions
+// Copyright (c) 1998-2020 Marti Maria Saguer, all rights reserved
+//
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+//---------------------------------------------------------------------------------
+
+// Optimization for matrix-shaper in 8 bits. Numbers are operated in n.14 signed, tables are stored in 1.14 fixed
+
+#include "fast_float_internal.h"
+
+typedef cmsInt32Number cmsS1Fixed14Number; // Note that this may hold more than 16 bits!
+
+#define DOUBLE_TO_1FIXED14(x) ((cmsS1Fixed14Number) floor((x) * 16384.0 + 0.5))
+
+// This is the private data container used by this optimization
+typedef struct {
+
+ // This is for SSE2, MUST be aligned at 16 bit boundary
+
+ cmsFloat32Number fMatrix[4][4];
+ cmsFloat32Number fShaper1[256 * 3];
+
+ void * real_ptr;
+
+ cmsS1Fixed14Number Shaper1R[256]; // from 0..255 to 1.14 (0.0...1.0)
+ cmsS1Fixed14Number Shaper1G[256];
+ cmsS1Fixed14Number Shaper1B[256];
+
+ cmsS1Fixed14Number Mat[3][3]; // n.14 to n.14 (needs a saturation after that)
+ cmsS1Fixed14Number Off[3];
+
+ cmsUInt8Number Shaper2R[0x4001]; // 1.14 to 0..255
+ cmsUInt8Number Shaper2G[0x4001];
+ cmsUInt8Number Shaper2B[0x4001];
+
+} XMatShaper8Data;
+
+
+static
+XMatShaper8Data* malloc_aligned(cmsContext ContextID)
+{
+ cmsUInt8Number* real_ptr = (cmsUInt8Number*) _cmsMallocZero(ContextID, sizeof(XMatShaper8Data) + 32);
+ cmsUInt8Number* aligned = (cmsUInt8Number*) (((uintptr_t)real_ptr + 16) & ~0xf);
+ XMatShaper8Data* p = (XMatShaper8Data*) aligned;
+
+ p ->real_ptr = real_ptr;
+ return p;
+}
+
+static
+void free_aligned(cmsContext ContextID, XMatShaper8Data* a)
+{
+ _cmsFree(ContextID, a->real_ptr);
+}
+
+
+// Free the private data container
+static
+void FreeMatShaper(cmsContext ContextID, void* Data)
+{
+ UNUSED_PARAMETER(ContextID);
+
+ if (Data != NULL) free_aligned(ContextID, (XMatShaper8Data*) Data);
+}
+
+
+// This table converts from 8 bits to 1.14 after applying the curve
+static
+void FillFirstShaper(cmsContext ContextID, cmsS1Fixed14Number* Table, cmsToneCurve* Curve)
+{
+ int i;
+ cmsFloat32Number R, y;
+
+ for (i=0; i < 256; i++) {
+
+ R = (cmsFloat32Number) (i / 255.0);
+ y = cmsEvalToneCurveFloat(ContextID, Curve, R);
+
+ Table[i] = DOUBLE_TO_1FIXED14(y);
+ }
+}
+
+static
+void FillFirstShaperFloat(cmsContext ContextID, cmsFloat32Number* Table, cmsToneCurve* Curve)
+{
+ int i;
+ cmsFloat32Number R;
+
+ for (i=0; i < 256; i++) {
+
+ R = (cmsFloat32Number) (i / 255.0);
+
+ Table[i] = cmsEvalToneCurveFloat(ContextID, Curve, R);
+ }
+}
+
+
+// This table converts form 1.14 (being 0x4000 the last entry) to 8 bits after applying the curve
+static
+void FillSecondShaper(cmsContext ContextID, cmsUInt8Number* Table, cmsToneCurve* Curve)
+{
+ int i;
+ cmsFloat32Number R, Val;
+ cmsUInt16Number w;
+
+ for (i=0; i < 0x4001; i++) {
+
+ R = (cmsFloat32Number) (i / 16384.0);
+ Val = cmsEvalToneCurveFloat(ContextID, Curve, R);
+ w = _cmsSaturateWord(Val * 65535.0 + 0.5);
+
+ Table[i] = FROM_16_TO_8(w);
+
+ }
+}
+
+// Compute the matrix-shaper structure
+static
+XMatShaper8Data* SetMatShaper(cmsContext ContextID, cmsToneCurve* Curve1[3], cmsMAT3* Mat, cmsVEC3* Off, cmsToneCurve* Curve2[3])
+{
+ XMatShaper8Data* p;
+ int i, j;
+
+ // Allocate a big chuck of memory to store precomputed tables
+ p = malloc_aligned(ContextID);
+ if (p == NULL) return FALSE;
+
+ // Precompute tables
+ FillFirstShaper(ContextID, p ->Shaper1R, Curve1[0]);
+ FillFirstShaper(ContextID, p ->Shaper1G, Curve1[1]);
+ FillFirstShaper(ContextID, p ->Shaper1B, Curve1[2]);
+
+ FillSecondShaper(ContextID, p ->Shaper2R, Curve2[0]);
+ FillSecondShaper(ContextID, p ->Shaper2G, Curve2[1]);
+ FillSecondShaper(ContextID, p ->Shaper2B, Curve2[2]);
+
+
+ FillFirstShaperFloat(ContextID, p ->fShaper1, Curve1[0]);
+ FillFirstShaperFloat(ContextID, p ->fShaper1 + 256, Curve1[1]);
+ FillFirstShaperFloat(ContextID, p ->fShaper1 + 256*2, Curve1[2]);
+
+ // Convert matrix to nFixed14. Note that those values may take more than 16 bits as
+ for (i=0; i < 3; i++) {
+ for (j=0; j < 3; j++) {
+ p ->Mat[i][j] = DOUBLE_TO_1FIXED14(Mat->v[i].n[j]);
+ p ->fMatrix[j][i] = (cmsFloat32Number) Mat ->v[i].n[j];
+ }
+ }
+
+
+ for (i=0; i < 3; i++) {
+
+ if (Off == NULL) {
+
+ p ->Off[i] = 0x2000;
+ p ->fMatrix[3][i] = 0.0f;
+ }
+ else {
+ p ->Off[i] = DOUBLE_TO_1FIXED14(Off->n[i]) + 0x2000;
+ p ->fMatrix[3][i] = (cmsFloat32Number) Off->n[i];
+ }
+ }
+
+
+ return p;
+}
+
+// A fast matrix-shaper evaluator for 8 bits. This is a bit ticky since I'm using 1.14 signed fixed point
+// to accomplish some performance. Actually it takes 256x3 16 bits tables and 16385 x 3 tables of 8 bits,
+// in total about 50K, and the performance boost is huge!
+
+static
+void MatShaperXform8(cmsContext ContextID,
+ struct _cmstransform_struct *CMMcargo,
+ const void* Input,
+ void* Output,
+ cmsUInt32Number PixelsPerLine,
+ cmsUInt32Number LineCount,
+ const cmsStride* Stride)
+{
+ XMatShaper8Data* p = (XMatShaper8Data*) _cmsGetTransformUserData(CMMcargo);
+
+ register cmsS1Fixed14Number l1, l2, l3;
+ cmsS1Fixed14Number r, g, b;
+ cmsUInt32Number ri, gi, bi;
+ cmsUInt32Number i, ii;
+
+ cmsUInt32Number SourceStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number SourceIncrements[cmsMAXCHANNELS];
+ cmsUInt32Number DestStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number DestIncrements[cmsMAXCHANNELS];
+
+ const cmsUInt8Number* rin;
+ const cmsUInt8Number* gin;
+ const cmsUInt8Number* bin;
+ const cmsUInt8Number* ain = NULL;
+
+ cmsUInt8Number* rout;
+ cmsUInt8Number* gout;
+ cmsUInt8Number* bout;
+ cmsUInt8Number* aout = NULL;
+
+ cmsUInt32Number nalpha, strideIn, strideOut;
+
+ _cmsComputeComponentIncrements(cmsGetTransformInputFormat(ContextID, (cmsHTRANSFORM)CMMcargo), Stride->BytesPerPlaneIn, NULL, &nalpha, SourceStartingOrder, SourceIncrements);
+ _cmsComputeComponentIncrements(cmsGetTransformOutputFormat(ContextID, (cmsHTRANSFORM)CMMcargo), Stride->BytesPerPlaneOut, NULL, &nalpha, DestStartingOrder, DestIncrements);
+
+ strideIn = strideOut = 0;
+ for (i = 0; i < LineCount; i++) {
+
+ rin = (const cmsUInt8Number*)Input + SourceStartingOrder[0] + strideIn;
+ gin = (const cmsUInt8Number*)Input + SourceStartingOrder[1] + strideIn;
+ bin = (const cmsUInt8Number*)Input + SourceStartingOrder[2] + strideIn;
+ if (nalpha)
+ ain = (const cmsUInt8Number*)Input + SourceStartingOrder[3] + strideIn;
+
+
+ rout = (cmsUInt8Number*)Output + DestStartingOrder[0] + strideOut;
+ gout = (cmsUInt8Number*)Output + DestStartingOrder[1] + strideOut;
+ bout = (cmsUInt8Number*)Output + DestStartingOrder[2] + strideOut;
+ if (nalpha)
+ aout = (cmsUInt8Number*)Output + DestStartingOrder[3] + strideOut;
+
+
+ for (ii = 0; ii < PixelsPerLine; ii++) {
+
+ // Across first shaper, which also converts to 1.14 fixed point. 16 bits guaranteed.
+ r = p->Shaper1R[*rin];
+ g = p->Shaper1G[*gin];
+ b = p->Shaper1B[*bin];
+
+ // Evaluate the matrix in 1.14 fixed point
+ l1 = (p->Mat[0][0] * r + p->Mat[0][1] * g + p->Mat[0][2] * b + p->Off[0]) >> 14;
+ l2 = (p->Mat[1][0] * r + p->Mat[1][1] * g + p->Mat[1][2] * b + p->Off[1]) >> 14;
+ l3 = (p->Mat[2][0] * r + p->Mat[2][1] * g + p->Mat[2][2] * b + p->Off[2]) >> 14;
+
+
+ // Now we have to clip to 0..1.0 range
+ ri = (l1 < 0) ? 0 : ((l1 > 0x4000) ? 0x4000 : l1);
+ gi = (l2 < 0) ? 0 : ((l2 > 0x4000) ? 0x4000 : l2);
+ bi = (l3 < 0) ? 0 : ((l3 > 0x4000) ? 0x4000 : l3);
+
+
+ // And across second shaper,
+ *rout = p->Shaper2R[ri];
+ *gout = p->Shaper2G[gi];
+ *bout = p->Shaper2B[bi];
+
+ // Handle alpha
+ if (ain) {
+ *aout = *ain;
+ }
+
+ rin += SourceIncrements[0];
+ gin += SourceIncrements[1];
+ bin += SourceIncrements[2];
+ if (ain) ain += SourceIncrements[3];
+
+ rout += DestIncrements[0];
+ gout += DestIncrements[1];
+ bout += DestIncrements[2];
+ if (aout) aout += DestIncrements[3];
+ }
+
+ strideIn += Stride->BytesPerLineIn;
+ strideOut += Stride->BytesPerLineOut;
+ }
+}
+
+
+// 8 bits on input allows matrix-shaper boost up a little bit
+cmsBool Optimize8MatrixShaper( cmsContext ContextID,
+ _cmsTransformFn* TransformFn,
+ void** UserData,
+ _cmsFreeUserDataFn* FreeUserData,
+ cmsPipeline** Lut,
+ cmsUInt32Number* InputFormat,
+ cmsUInt32Number* OutputFormat,
+ cmsUInt32Number* dwFlags)
+{
+ cmsStage* Curve1, *Curve2;
+ cmsStage* Matrix1, *Matrix2;
+ _cmsStageMatrixData* Data1;
+ _cmsStageMatrixData* Data2;
+ cmsMAT3 res;
+ cmsBool IdentityMat = FALSE;
+ cmsPipeline* Dest, *Src;
+ cmsUInt32Number nChans;
+ cmsFloat64Number factor = 1.0;
+
+ // Only works on RGB to RGB and gray to gray
+
+ if ( !( (T_CHANNELS(*InputFormat) == 3 && T_CHANNELS(*OutputFormat) == 3) ||
+ (T_CHANNELS(*InputFormat) == 1 && T_CHANNELS(*OutputFormat) == 1) )) return FALSE;
+
+ // Only works on 8 bit input
+ if (T_BYTES(*InputFormat) != 1 || T_BYTES(*OutputFormat) != 1) return FALSE;
+
+ // Seems suitable, proceed
+ Src = *Lut;
+
+ // Check for shaper-matrix-matrix-shaper structure, that is what this optimizer stands for
+ if (!cmsPipelineCheckAndRetreiveStages(ContextID, Src, 4,
+ cmsSigCurveSetElemType, cmsSigMatrixElemType, cmsSigMatrixElemType, cmsSigCurveSetElemType,
+ &Curve1, &Matrix1, &Matrix2, &Curve2)) return FALSE;
+
+ nChans = T_CHANNELS(*InputFormat);
+
+ // Get both matrices, which are 3x3
+ Data1 = (_cmsStageMatrixData*) cmsStageData(ContextID, Matrix1);
+ Data2 = (_cmsStageMatrixData*) cmsStageData(ContextID, Matrix2);
+
+ // Input offset should be zero
+ if (Data1 ->Offset != NULL) return FALSE;
+
+ if (cmsStageInputChannels(ContextID, Matrix1) == 1 && cmsStageOutputChannels(ContextID, Matrix2) == 1)
+ {
+ // This is a gray to gray. Just multiply
+ factor = Data1->Double[0]*Data2->Double[0] +
+ Data1->Double[1]*Data2->Double[1] +
+ Data1->Double[2]*Data2->Double[2];
+
+ if (fabs(1 - factor) < (1.0 / 65535.0)) IdentityMat = TRUE;
+ }
+ else
+ {
+ // Multiply both matrices to get the result
+ _cmsMAT3per(ContextID, &res, (cmsMAT3*) Data2 ->Double, (cmsMAT3*) Data1 ->Double);
+
+ // Now the result is in res + Data2 -> Offset. Maybe is a plain identity?
+ IdentityMat = FALSE;
+ if (_cmsMAT3isIdentity(ContextID, &res) && Data2 ->Offset == NULL) {
+
+ // We can get rid of full matrix
+ IdentityMat = TRUE;
+ }
+ }
+
+ // Allocate an empty LUT
+ Dest = cmsPipelineAlloc(ContextID, nChans, nChans);
+ if (!Dest) return FALSE;
+
+ // Assamble the new LUT
+ cmsPipelineInsertStage(ContextID, Dest, cmsAT_BEGIN, cmsStageDup(ContextID, Curve1));
+
+ if (!IdentityMat) {
+
+ if (nChans == 1)
+ cmsPipelineInsertStage(ContextID, Dest, cmsAT_END,
+ cmsStageAllocMatrix(ContextID, 1, 1, (const cmsFloat64Number*) &factor, Data2->Offset));
+ else
+ cmsPipelineInsertStage(ContextID, Dest, cmsAT_END,
+ cmsStageAllocMatrix(ContextID, 3, 3, (const cmsFloat64Number*) &res, Data2 ->Offset));
+ }
+
+
+ cmsPipelineInsertStage(ContextID, Dest, cmsAT_END, cmsStageDup(ContextID, Curve2));
+
+ // If identity on matrix, we can further optimize the curves, so call the join curves routine
+ if (IdentityMat) {
+
+ Optimize8ByJoiningCurves(ContextID, TransformFn, UserData, FreeUserData, &Dest, InputFormat, OutputFormat, dwFlags);
+ }
+ else {
+ _cmsStageToneCurvesData* mpeC1 = (_cmsStageToneCurvesData*) cmsStageData(ContextID, Curve1);
+ _cmsStageToneCurvesData* mpeC2 = (_cmsStageToneCurvesData*) cmsStageData(ContextID, Curve2);
+
+ // In this particular optimization, caché does not help as it takes more time to deal with
+ // the caché that with the pixel handling
+ *dwFlags |= cmsFLAGS_NOCACHE;
+
+
+ // Setup the optimizarion routines
+ *UserData = SetMatShaper(ContextID, mpeC1 ->TheCurves, &res, (cmsVEC3*) Data2 ->Offset, mpeC2->TheCurves);
+ *FreeUserData = FreeMatShaper;
+
+ *TransformFn = (_cmsTransformFn) MatShaperXform8;
+ }
+
+ *dwFlags &= ~cmsFLAGS_CAN_CHANGE_FORMATTER;
+ cmsPipelineFree(ContextID, Src);
+ *Lut = Dest;
+ return TRUE;
+}
diff --git a/lcms2mt/plugins/fast_float/src/fast_8_tethra.c b/lcms2mt/plugins/fast_float/src/fast_8_tethra.c
new file mode 100644
index 00000000..bde4649d
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/src/fast_8_tethra.c
@@ -0,0 +1,501 @@
+//---------------------------------------------------------------------------------
+//
+// Little Color Management System, fast floating point extensions
+// Copyright (c) 1998-2020 Marti Maria Saguer, all rights reserved
+//
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+//---------------------------------------------------------------------------------
+
+#include "fast_float_internal.h"
+
+#define PRELINEARIZATION_POINTS 4096
+
+// Optimization for 8 bits, 3 inputs only
+typedef struct {
+
+ const cmsInterpParams* p; // Tetrahedrical interpolation parameters. This is a not-owned pointer.
+
+ cmsUInt16Number rx[256], ry[256], rz[256];
+ cmsUInt32Number X0[256], Y0[256], Z0[256]; // Precomputed nodes and offsets for 8-bit input data
+
+
+} Performance8Data;
+
+
+// Precomputes tables for 8-bit on input devicelink.
+static
+Performance8Data* Performance8alloc(cmsContext ContextID, const cmsInterpParams* p, cmsToneCurve* G[3])
+{
+ int i;
+ cmsUInt16Number Input[3];
+ cmsS15Fixed16Number v1, v2, v3;
+ Performance8Data* p8;
+
+ p8 = (Performance8Data*) _cmsMallocZero(ContextID, sizeof(Performance8Data));
+ if (p8 == NULL) return NULL;
+
+ // Since this only works for 8 bit input, values comes always as x * 257,
+ // we can safely take msb byte (x << 8 + x)
+ for (i=0; i < 256; i++) {
+
+ if (G != NULL) {
+
+ // Get 16-bit representation
+ Input[0] = cmsEvalToneCurve16(ContextID, G[0], FROM_8_TO_16(i));
+ Input[1] = cmsEvalToneCurve16(ContextID, G[1], FROM_8_TO_16(i));
+ Input[2] = cmsEvalToneCurve16(ContextID, G[2], FROM_8_TO_16(i));
+ }
+ else {
+ Input[0] = FROM_8_TO_16(i);
+ Input[1] = FROM_8_TO_16(i);
+ Input[2] = FROM_8_TO_16(i);
+ }
+
+ // Move to 0..1.0 in fixed domain
+ v1 = _cmsToFixedDomain(Input[0] * p -> Domain[0]);
+ v2 = _cmsToFixedDomain(Input[1] * p -> Domain[1]);
+ v3 = _cmsToFixedDomain(Input[2] * p -> Domain[2]);
+
+ // Store the precalculated table of nodes
+ p8 ->X0[i] = (p->opta[2] * FIXED_TO_INT(v1));
+ p8 ->Y0[i] = (p->opta[1] * FIXED_TO_INT(v2));
+ p8 ->Z0[i] = (p->opta[0] * FIXED_TO_INT(v3));
+
+ // Store the precalculated table of offsets
+ p8 ->rx[i] = (cmsUInt16Number) FIXED_REST_TO_INT(v1);
+ p8 ->ry[i] = (cmsUInt16Number) FIXED_REST_TO_INT(v2);
+ p8 ->rz[i] = (cmsUInt16Number) FIXED_REST_TO_INT(v3);
+ }
+
+
+ p8 ->p = p;
+
+ return p8;
+}
+
+static
+void Performance8free(cmsContext ContextID, void* ptr)
+{
+ _cmsFree(ContextID, ptr);
+}
+
+
+// Sampler implemented by another LUT. This is a clean way to precalculate the devicelink 3D CLUT for
+// almost any transform. We use floating point precision and then convert from floating point to 16 bits.
+static
+int XFormSampler16(cmsContext ContextID, CMSREGISTER const cmsUInt16Number In[], CMSREGISTER cmsUInt16Number Out[], CMSREGISTER void* Cargo)
+{
+ // Evaluate in 16 bits
+ cmsPipelineEval16(ContextID, In, Out, (cmsPipeline*) Cargo);
+
+ // Always succeed
+ return TRUE;
+}
+
+
+// A optimized interpolation for 8-bit input.
+#define DENS(i,j,k) (LutTable[(i)+(j)+(k)+OutChan])
+
+static
+void PerformanceEval8(cmsContext ContextID,
+ struct _cmstransform_struct *CMMcargo,
+ const void* Input,
+ void* Output,
+ cmsUInt32Number PixelsPerLine,
+ cmsUInt32Number LineCount,
+ const cmsStride* Stride)
+{
+
+ cmsUInt8Number r, g, b;
+ cmsS15Fixed16Number rx, ry, rz;
+ cmsS15Fixed16Number c0, c1, c2, c3, Rest;
+ cmsUInt32Number OutChan, TotalPlusAlpha;
+ cmsS15Fixed16Number X0, X1, Y0, Y1, Z0, Z1;
+ Performance8Data* p8 = (Performance8Data*)_cmsGetTransformUserData(CMMcargo);
+ const cmsInterpParams* p = p8->p;
+ cmsUInt32Number TotalOut = p->nOutputs;
+ const cmsUInt16Number* LutTable = (const cmsUInt16Number*)p->Table;
+
+ cmsUInt8Number* out[cmsMAXCHANNELS];
+ cmsUInt16Number res16;
+
+ cmsUInt32Number i, ii;
+
+ cmsUInt32Number SourceStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number SourceIncrements[cmsMAXCHANNELS];
+ cmsUInt32Number DestStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number DestIncrements[cmsMAXCHANNELS];
+
+ const cmsUInt8Number* rin;
+ const cmsUInt8Number* gin;
+ const cmsUInt8Number* bin;
+ const cmsUInt8Number* ain = NULL;
+
+ cmsUInt32Number nalpha, strideIn, strideOut;
+
+
+ _cmsComputeComponentIncrements(cmsGetTransformInputFormat(ContextID, (cmsHTRANSFORM)CMMcargo), Stride->BytesPerPlaneIn, NULL, &nalpha, SourceStartingOrder, SourceIncrements);
+ _cmsComputeComponentIncrements(cmsGetTransformOutputFormat(ContextID, (cmsHTRANSFORM)CMMcargo), Stride->BytesPerPlaneOut, NULL, &nalpha, DestStartingOrder, DestIncrements);
+
+ strideIn = strideOut = 0;
+ for (i = 0; i < LineCount; i++) {
+
+ rin = (const cmsUInt8Number*)Input + SourceStartingOrder[0] + strideIn;
+ gin = (const cmsUInt8Number*)Input + SourceStartingOrder[1] + strideIn;
+ bin = (const cmsUInt8Number*)Input + SourceStartingOrder[2] + strideIn;
+ if (nalpha)
+ ain = (const cmsUInt8Number*)Input + SourceStartingOrder[3] + strideIn;
+
+ TotalPlusAlpha = TotalOut;
+ if (ain) TotalPlusAlpha++;
+
+ for (OutChan = 0; OutChan < TotalPlusAlpha; OutChan++) {
+ out[OutChan] = (cmsUInt8Number*)Output + DestStartingOrder[OutChan] + strideOut;
+ }
+
+
+ for (ii = 0; ii < PixelsPerLine; ii++) {
+
+ r = *rin; g = *gin; b = *bin;
+
+ rin += SourceIncrements[0];
+ gin += SourceIncrements[1];
+ bin += SourceIncrements[2];
+
+ X0 = X1 = p8->X0[r];
+ Y0 = Y1 = p8->Y0[g];
+ Z0 = Z1 = p8->Z0[b];
+
+ rx = p8->rx[r];
+ ry = p8->ry[g];
+ rz = p8->rz[b];
+
+ X1 = X0 + ((rx == 0) ? 0 : p->opta[2]);
+ Y1 = Y0 + ((ry == 0) ? 0 : p->opta[1]);
+ Z1 = Z0 + ((rz == 0) ? 0 : p->opta[0]);
+
+
+ // These are the 6 Tetrahedral
+ for (OutChan = 0; OutChan < TotalOut; OutChan++) {
+
+ c0 = DENS(X0, Y0, Z0);
+
+ if (rx >= ry && ry >= rz)
+ {
+ c1 = DENS(X1, Y0, Z0) - c0;
+ c2 = DENS(X1, Y1, Z0) - DENS(X1, Y0, Z0);
+ c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);
+ }
+ else
+ if (rx >= rz && rz >= ry)
+ {
+ c1 = DENS(X1, Y0, Z0) - c0;
+ c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);
+ c3 = DENS(X1, Y0, Z1) - DENS(X1, Y0, Z0);
+ }
+ else
+ if (rz >= rx && rx >= ry)
+ {
+ c1 = DENS(X1, Y0, Z1) - DENS(X0, Y0, Z1);
+ c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);
+ c3 = DENS(X0, Y0, Z1) - c0;
+ }
+ else
+ if (ry >= rx && rx >= rz)
+ {
+ c1 = DENS(X1, Y1, Z0) - DENS(X0, Y1, Z0);
+ c2 = DENS(X0, Y1, Z0) - c0;
+ c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);
+ }
+ else
+ if (ry >= rz && rz >= rx)
+ {
+ c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);
+ c2 = DENS(X0, Y1, Z0) - c0;
+ c3 = DENS(X0, Y1, Z1) - DENS(X0, Y1, Z0);
+ }
+ else
+ if (rz >= ry && ry >= rx)
+ {
+ c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);
+ c2 = DENS(X0, Y1, Z1) - DENS(X0, Y0, Z1);
+ c3 = DENS(X0, Y0, Z1) - c0;
+ }
+ else {
+ c1 = c2 = c3 = 0;
+ }
+
+
+ Rest = c1 * rx + c2 * ry + c3 * rz + 0x8001;
+ res16 = (cmsUInt16Number)c0 + ((Rest + (Rest >> 16)) >> 16);
+
+ *out[OutChan] = FROM_16_TO_8(res16);
+ out[OutChan] += DestIncrements[OutChan];
+
+ if (ain)
+ *out[TotalOut] = *ain;
+
+ }
+
+
+ }
+
+ strideIn += Stride->BytesPerLineIn;
+ strideOut += Stride->BytesPerLineOut;
+ }
+}
+
+#undef DENS
+
+
+// Curves that contain wide empty areas are not optimizeable
+static
+cmsBool IsDegenerated(cmsContext ContextID, const cmsToneCurve* g)
+{
+ int i, Zeros = 0, Poles = 0;
+ int nEntries = cmsGetToneCurveEstimatedTableEntries(ContextID, g);
+ const cmsUInt16Number* Table16 = cmsGetToneCurveEstimatedTable(ContextID, g);
+
+ for (i=0; i < nEntries; i++) {
+
+ if (Table16[i] == 0x0000) Zeros++;
+ if (Table16[i] == 0xffff) Poles++;
+ }
+
+ if (Zeros == 1 && Poles == 1) return FALSE; // For linear tables
+ if (Zeros > (nEntries / 4)) return TRUE; // Degenerated, mostly zeros
+ if (Poles > (nEntries / 4)) return TRUE; // Degenerated, mostly poles
+
+ return FALSE;
+}
+
+
+
+// Normalize endpoints by slope limiting max and min. This assures endpoints as well.
+// Descending curves are handled as well.
+static
+void SlopeLimiting(cmsUInt16Number* Table16, int nEntries)
+{
+ int BeginVal, EndVal;
+
+ int AtBegin = (int) floor((cmsFloat64Number)nEntries * 0.02 + 0.5); // Cutoff at 2%
+ int AtEnd = nEntries - AtBegin - 1; // And 98%
+ cmsFloat64Number Val, Slope, beta;
+ int i;
+
+
+ if (Table16[0] > Table16[nEntries-1]) {
+ BeginVal = 0xffff; EndVal = 0;
+ }
+ else {
+ BeginVal = 0; EndVal = 0xffff;
+ }
+
+ // Compute slope and offset for begin of curve
+ Val = Table16[AtBegin];
+ Slope = (Val - BeginVal) / AtBegin;
+ beta = Val - Slope * AtBegin;
+
+ for (i=0; i < AtBegin; i++)
+ Table16[i] = _cmsSaturateWord(i * Slope + beta);
+
+ // Compute slope and offset for the end
+ Val = Table16[AtEnd];
+ Slope = (EndVal - Val) / AtBegin; // AtBegin holds the X interval, which is same in both cases
+ beta = Val - Slope * AtEnd;
+
+ for (i = AtEnd; i < (int) nEntries; i++)
+ Table16[i] = _cmsSaturateWord(i * Slope + beta);
+}
+
+
+// --------------------------------------------------------------------------------------------------------------
+
+cmsBool Optimize8BitRGBTransform( cmsContext ContextID,
+ _cmsTransformFn* TransformFn,
+ void** UserData,
+ _cmsFreeUserDataFn* FreeDataFn,
+ cmsPipeline** Lut,
+ cmsUInt32Number* InputFormat,
+ cmsUInt32Number* OutputFormat,
+ cmsUInt32Number* dwFlags)
+{
+ cmsPipeline* OriginalLut;
+ int nGridPoints;
+ cmsToneCurve *Trans[cmsMAXCHANNELS], *TransReverse[cmsMAXCHANNELS];
+ cmsUInt32Number t, i, j;
+ cmsFloat32Number v, In[cmsMAXCHANNELS], Out[cmsMAXCHANNELS];
+ cmsBool lIsSuitable, lIsLinear;
+ cmsPipeline* OptimizedLUT = NULL, *LutPlusCurves = NULL;
+ cmsStage* OptimizedCLUTmpe;
+ cmsColorSpaceSignature OutputColorSpace;
+ cmsStage* OptimizedPrelinMpe;
+ cmsStage* mpe;
+ Performance8Data* p8;
+ cmsUInt16Number* MyTable[3];
+ _cmsStageCLutData* data;
+
+ // For empty transforms, do nothing
+ if (*Lut == NULL) return FALSE;
+
+ // This is a loosy optimization! does not apply in floating-point cases
+ if (T_FLOAT(*InputFormat) || T_FLOAT(*OutputFormat)) return FALSE;
+
+ // Only on 8-bit
+ if (T_BYTES(*InputFormat) != 1 || T_BYTES(*OutputFormat) != 1) return FALSE;
+
+ // Only on RGB
+ if (T_COLORSPACE(*InputFormat) != PT_RGB) return FALSE;
+
+ OriginalLut = *Lut;
+
+ // Named color pipelines cannot be optimized either
+ for (mpe = cmsPipelineGetPtrToFirstStage(ContextID, OriginalLut);
+ mpe != NULL;
+ mpe = cmsStageNext(ContextID, mpe)) {
+ if (cmsStageType(ContextID, mpe) == cmsSigNamedColorElemType) return FALSE;
+ }
+
+ OutputColorSpace = _cmsICCcolorSpace(ContextID, T_COLORSPACE(*OutputFormat));
+ nGridPoints = _cmsReasonableGridpointsByColorspace(cmsSigRgbData, *dwFlags);
+
+ // Empty gamma containers
+ memset(Trans, 0, sizeof(Trans));
+ memset(TransReverse, 0, sizeof(TransReverse));
+
+ MyTable[0] = (cmsUInt16Number*) _cmsMallocZero(ContextID, sizeof(cmsUInt16Number) * PRELINEARIZATION_POINTS);
+ MyTable[1] = (cmsUInt16Number*) _cmsMallocZero(ContextID, sizeof(cmsUInt16Number) * PRELINEARIZATION_POINTS);
+ MyTable[2] = (cmsUInt16Number*) _cmsMallocZero(ContextID, sizeof(cmsUInt16Number) * PRELINEARIZATION_POINTS);
+
+ if (MyTable[0] == NULL || MyTable[1] == NULL || MyTable[2] == NULL) goto Error;
+
+ // Populate the curves
+
+ for (i=0; i < PRELINEARIZATION_POINTS; i++) {
+
+ v = (cmsFloat32Number) ((cmsFloat64Number) i / (PRELINEARIZATION_POINTS - 1));
+
+ // Feed input with a gray ramp
+ for (j=0; j < 3; j++)
+ In[j] = v;
+
+ // Evaluate the gray value
+ cmsPipelineEvalFloat(ContextID, In, Out, OriginalLut);
+
+ // Store result in curve
+ for (j=0; j < 3; j++)
+ MyTable[j][i] = _cmsSaturateWord(Out[j] * 65535.0);
+ }
+
+ for (t=0; t < 3; t++) {
+
+ SlopeLimiting(MyTable[t], PRELINEARIZATION_POINTS);
+
+ Trans[t] = cmsBuildTabulatedToneCurve16(ContextID, PRELINEARIZATION_POINTS, MyTable[t]);
+ if (Trans[t] == NULL) goto Error;
+
+ _cmsFree(ContextID, MyTable[t]);
+ }
+
+ // Check for validity
+ lIsSuitable = TRUE;
+ lIsLinear = TRUE;
+ for (t=0; (lIsSuitable && (t < 3)); t++) {
+
+ // Exclude if already linear
+ if (!cmsIsToneCurveLinear(ContextID, Trans[t]))
+ lIsLinear = FALSE;
+
+ // Exclude if non-monotonic
+ if (!cmsIsToneCurveMonotonic(ContextID, Trans[t]))
+ lIsSuitable = FALSE;
+
+ if (IsDegenerated(ContextID, Trans[t]))
+ lIsSuitable = FALSE;
+ }
+
+ // If it is not suitable, just quit
+ if (!lIsSuitable) goto Error;
+
+ // Invert curves if possible
+ for (t = 0; t < cmsPipelineInputChannels(ContextID, OriginalLut); t++) {
+ TransReverse[t] = cmsReverseToneCurveEx(ContextID, PRELINEARIZATION_POINTS, Trans[t]);
+ if (TransReverse[t] == NULL) goto Error;
+ }
+
+ // Now inset the reversed curves at the begin of transform
+ LutPlusCurves = cmsPipelineDup(ContextID, OriginalLut);
+ if (LutPlusCurves == NULL) goto Error;
+
+ cmsPipelineInsertStage(ContextID, LutPlusCurves, cmsAT_BEGIN, cmsStageAllocToneCurves(ContextID, 3, TransReverse));
+
+ // Create the result LUT
+ OptimizedLUT = cmsPipelineAlloc(ContextID, 3, cmsPipelineOutputChannels(ContextID, OriginalLut));
+ if (OptimizedLUT == NULL) goto Error;
+
+ OptimizedPrelinMpe = cmsStageAllocToneCurves(ContextID, 3, Trans);
+
+ // Create and insert the curves at the beginning
+ cmsPipelineInsertStage(ContextID, OptimizedLUT, cmsAT_BEGIN, OptimizedPrelinMpe);
+
+ // Allocate the CLUT for result
+ OptimizedCLUTmpe = cmsStageAllocCLut16bit(ContextID, nGridPoints, 3, cmsPipelineOutputChannels(ContextID, OriginalLut), NULL);
+
+ // Add the CLUT to the destination LUT
+ cmsPipelineInsertStage(ContextID, OptimizedLUT, cmsAT_END, OptimizedCLUTmpe);
+
+ // Resample the LUT
+ if (!cmsStageSampleCLut16bit(ContextID, OptimizedCLUTmpe, XFormSampler16, (void*) LutPlusCurves, 0)) goto Error;
+
+ // Set the evaluator
+ data = (_cmsStageCLutData*) cmsStageData(ContextID, OptimizedCLUTmpe);
+
+ p8 = Performance8alloc(ContextID, data ->Params, Trans);
+ if (p8 == NULL) return FALSE;
+
+ // Free resources
+ for (t = 0; t <3; t++) {
+
+ if (Trans[t]) cmsFreeToneCurve(ContextID, Trans[t]);
+ if (TransReverse[t]) cmsFreeToneCurve(ContextID, TransReverse[t]);
+ }
+
+ cmsPipelineFree(ContextID, LutPlusCurves);
+
+ // And return the obtained LUT
+ cmsPipelineFree(ContextID, OriginalLut);
+
+ *dwFlags &= ~cmsFLAGS_CAN_CHANGE_FORMATTER;
+ *Lut = OptimizedLUT;
+ *TransformFn = (_cmsTransformFn) PerformanceEval8;
+ *UserData = p8;
+ *FreeDataFn = Performance8free;
+
+ return TRUE;
+
+Error:
+
+ for (t = 0; t < 3; t++) {
+
+ if (Trans[t]) cmsFreeToneCurve(ContextID, Trans[t]);
+ if (TransReverse[t]) cmsFreeToneCurve(ContextID, TransReverse[t]);
+ }
+
+ if (LutPlusCurves != NULL) cmsPipelineFree(ContextID, LutPlusCurves);
+ if (OptimizedLUT != NULL) cmsPipelineFree(ContextID, OptimizedLUT);
+
+ return FALSE;
+}
diff --git a/lcms2mt/plugins/fast_float/src/fast_float_15bits.c b/lcms2mt/plugins/fast_float/src/fast_float_15bits.c
new file mode 100644
index 00000000..3dbfe036
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/src/fast_float_15bits.c
@@ -0,0 +1,603 @@
+//---------------------------------------------------------------------------------
+//
+// Little Color Management System, fast floating point extensions
+// Copyright (c) 1998-2020 Marti Maria Saguer, all rights reserved
+//
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+//---------------------------------------------------------------------------------
+
+#include "fast_float_internal.h"
+
+
+//---------------------------------------------------------------------------------
+
+// The internal photoshop 16 bit format range is 1.15 fixed point, which goes 0..32768
+// (NOT 32767) that means:
+//
+// 16 bits encoding 15 bit Photoshop encoding
+// ================ =========================
+//
+// 0x0000 0x0000
+// 0xFFFF 0x8000
+//
+// A nice (and fast) way to implement conversions is by using 64 bit values, which are
+// native CPU word size in most today architectures.
+// In CMYK, internal Photoshop format comes inverted, and this inversion happens after
+// the resizing, so values 32769 to 65535 are never used in PhotoShop.
+
+//---------------------------------------------------------------------------------
+
+// This macro converts 16 bits to 15 bits by using a 64 bits value
+cmsINLINE cmsUInt16Number From16To15(cmsUInt16Number x16)
+{
+ cmsUInt64Number r64 = (((cmsUInt64Number)x16 << 15)) / 0xFFFFL;
+ return (cmsUInt16Number)r64;
+}
+
+// This macro converts 15 bits to 16 bits by using a 64 bit value. It is based in fixed 1.15 math
+cmsINLINE cmsUInt16Number From15To16(cmsUInt16Number x15)
+{
+ cmsUInt64Number r64 = ((cmsUInt64Number) x15 * 0xFFFF + 0x4000L) >> 15;
+ return (cmsUInt16Number)r64;
+}
+
+// Specialized 1-channel formatters
+static
+cmsUInt8Number* Unroll15bitsGray(cmsContext ContextID,
+ CMSREGISTER struct _cmstransform_struct* CMMcargo,
+ CMSREGISTER cmsUInt16Number Values[],
+ CMSREGISTER cmsUInt8Number* Buffer,
+ CMSREGISTER cmsUInt32Number Stride)
+{
+ UNUSED_PARAMETER(ContextID);
+ UNUSED_PARAMETER(CMMcargo);
+ UNUSED_PARAMETER(Stride);
+ UNUSED_PARAMETER(ContextID);
+
+ Values[0] = From15To16(*(cmsUInt16Number*)Buffer);
+
+ return Buffer + 2;
+}
+
+
+static
+cmsUInt8Number* Pack15bitsGray(cmsContext ContextID,
+ CMSREGISTER struct _cmstransform_struct* CMMcargo,
+ CMSREGISTER cmsUInt16Number Values[],
+ CMSREGISTER cmsUInt8Number* Buffer,
+ CMSREGISTER cmsUInt32Number Stride)
+{
+ UNUSED_PARAMETER(ContextID);
+ UNUSED_PARAMETER(CMMcargo);
+ UNUSED_PARAMETER(Stride);
+
+ *(cmsUInt16Number*)Buffer = From16To15(Values[0]);
+ return Buffer + 2;
+}
+
+// Specialized 3-channels formatters
+static
+cmsUInt8Number* Unroll15bitsRGB(cmsContext ContextID,
+ CMSREGISTER struct _cmstransform_struct* CMMcargo,
+ CMSREGISTER cmsUInt16Number Values[],
+ CMSREGISTER cmsUInt8Number* Buffer,
+ CMSREGISTER cmsUInt32Number Stride)
+{
+ UNUSED_PARAMETER(ContextID);
+ UNUSED_PARAMETER(CMMcargo);
+ UNUSED_PARAMETER(Stride);
+
+ Values[0] = From15To16(*(cmsUInt16Number*)Buffer);
+ Buffer += 2;
+ Values[1] = From15To16(*(cmsUInt16Number*)Buffer);
+ Buffer += 2;
+ Values[2] = From15To16(*(cmsUInt16Number*)Buffer);
+
+ return Buffer + 2;
+}
+
+
+static
+cmsUInt8Number* Pack15bitsRGB(cmsContext ContextID,
+ CMSREGISTER struct _cmstransform_struct* CMMcargo,
+ CMSREGISTER cmsUInt16Number Values[],
+ CMSREGISTER cmsUInt8Number* Buffer,
+ CMSREGISTER cmsUInt32Number Stride)
+{
+ UNUSED_PARAMETER(ContextID);
+ UNUSED_PARAMETER(CMMcargo);
+ UNUSED_PARAMETER(Stride);
+
+ *(cmsUInt16Number*)Buffer = From16To15(Values[0]);
+ Buffer += 2;
+ *(cmsUInt16Number*)Buffer = From16To15(Values[1]);
+ Buffer += 2;
+ *(cmsUInt16Number*)Buffer = From16To15(Values[2]);
+
+ return Buffer + 2;
+}
+
+
+static
+cmsUInt8Number* Unroll15bitsRGBA(cmsContext ContextID,
+ CMSREGISTER struct _cmstransform_struct* CMMcargo,
+ CMSREGISTER cmsUInt16Number Values[],
+ CMSREGISTER cmsUInt8Number* Buffer,
+ CMSREGISTER cmsUInt32Number Stride)
+{
+ UNUSED_PARAMETER(ContextID);
+ UNUSED_PARAMETER(CMMcargo);
+ UNUSED_PARAMETER(Stride);
+
+ Values[0] = From15To16(*(cmsUInt16Number*)Buffer);
+ Buffer += 2;
+ Values[1] = From15To16(*(cmsUInt16Number*)Buffer);
+ Buffer += 2;
+ Values[2] = From15To16(*(cmsUInt16Number*)Buffer);
+
+ return Buffer + 4;
+}
+
+
+static
+cmsUInt8Number* Pack15bitsRGBA(cmsContext ContextID,
+ CMSREGISTER struct _cmstransform_struct* CMMcargo,
+ CMSREGISTER cmsUInt16Number Values[],
+ CMSREGISTER cmsUInt8Number* Buffer,
+ CMSREGISTER cmsUInt32Number Stride)
+{
+ UNUSED_PARAMETER(ContextID);
+ UNUSED_PARAMETER(CMMcargo);
+ UNUSED_PARAMETER(Stride);
+
+ *(cmsUInt16Number*)Buffer = From16To15(Values[0]);
+ Buffer += 2;
+ *(cmsUInt16Number*)Buffer = From16To15(Values[1]);
+ Buffer += 2;
+ *(cmsUInt16Number*)Buffer = From16To15(Values[2]);
+
+ return Buffer + 4;
+}
+
+
+// Specialized 3 channels reversed formatters
+static
+cmsUInt8Number* Unroll15bitsBGR(cmsContext ContextID,
+ CMSREGISTER struct _cmstransform_struct* CMMcargo,
+ CMSREGISTER cmsUInt16Number Values[],
+ CMSREGISTER cmsUInt8Number* Buffer,
+ CMSREGISTER cmsUInt32Number Stride)
+{
+ UNUSED_PARAMETER(ContextID);
+ UNUSED_PARAMETER(CMMcargo);
+ UNUSED_PARAMETER(Stride);
+
+ Values[2] = From15To16(*(cmsUInt16Number*)Buffer);
+ Buffer += 2;
+ Values[1] = From15To16(*(cmsUInt16Number*)Buffer);
+ Buffer += 2;
+ Values[0] = From15To16(*(cmsUInt16Number*)Buffer);
+
+ return Buffer + 2;
+}
+
+
+static
+cmsUInt8Number* Pack15bitsBGR(cmsContext ContextID,
+ CMSREGISTER struct _cmstransform_struct* CMMcargo,
+ CMSREGISTER cmsUInt16Number Values[],
+ CMSREGISTER cmsUInt8Number* Buffer,
+ CMSREGISTER cmsUInt32Number Stride)
+{
+ UNUSED_PARAMETER(ContextID);
+ UNUSED_PARAMETER(CMMcargo);
+ UNUSED_PARAMETER(Stride);
+
+ *(cmsUInt16Number*)Buffer = From16To15(Values[2]);
+ Buffer += 2;
+ *(cmsUInt16Number*)Buffer = From16To15(Values[1]);
+ Buffer += 2;
+ *(cmsUInt16Number*)Buffer = From16To15(Values[0]);
+
+ return Buffer+2;
+}
+
+// Specialized 4 channels CMYK formatters. Note Photoshop stores CMYK reversed
+static
+cmsUInt8Number* Unroll15bitsCMYK(cmsContext ContextID,
+ CMSREGISTER struct _cmstransform_struct* CMMcargo,
+ CMSREGISTER cmsUInt16Number Values[],
+ CMSREGISTER cmsUInt8Number* Buffer,
+ CMSREGISTER cmsUInt32Number Stride)
+{
+ UNUSED_PARAMETER(ContextID);
+ UNUSED_PARAMETER(CMMcargo);
+ UNUSED_PARAMETER(Stride);
+
+ Values[0] = From15To16(0x8000 - *(cmsUInt16Number*)Buffer);
+ Buffer += 2;
+ Values[1] = From15To16(0x8000 - *(cmsUInt16Number*)Buffer);
+ Buffer += 2;
+ Values[2] = From15To16(0x8000 - *(cmsUInt16Number*)Buffer);
+ Buffer += 2;
+ Values[3] = From15To16(0x8000 - *(cmsUInt16Number*)Buffer);
+
+ return Buffer + 2;
+}
+
+static
+cmsUInt8Number* Pack15bitsCMYK(cmsContext ContextID,
+ CMSREGISTER struct _cmstransform_struct* CMMcargo,
+ CMSREGISTER cmsUInt16Number Values[],
+ CMSREGISTER cmsUInt8Number* Buffer,
+ CMSREGISTER cmsUInt32Number Stride)
+{
+ UNUSED_PARAMETER(ContextID);
+ UNUSED_PARAMETER(CMMcargo);
+ UNUSED_PARAMETER(Stride);
+
+ *(cmsUInt16Number*)Buffer = 0x8000U - From16To15(Values[0]);
+ Buffer += 2;
+ *(cmsUInt16Number*)Buffer = 0x8000U - From16To15(Values[1]);
+ Buffer += 2;
+ *(cmsUInt16Number*)Buffer = 0x8000U - From16To15(Values[2]);
+ Buffer += 2;
+ *(cmsUInt16Number*)Buffer = 0x8000U - From16To15(Values[3]);
+
+ return Buffer + 2;
+}
+
+
+// This macros does all handling for fallthrough cases
+cmsINLINE cmsUInt16Number UnrollOne(cmsUInt16Number x, cmsBool Reverse, cmsBool SwapEndian)
+{
+ if (SwapEndian)
+ x = (x << 8) | (x >> 8);
+
+ if (Reverse)
+ x = 0xffff - x;
+
+ return From15To16(x);
+}
+
+cmsINLINE cmsUInt16Number PackOne(cmsUInt16Number x, cmsBool Reverse, cmsBool SwapEndian)
+{
+ x = From16To15(x);
+
+ if (Reverse)
+ x = 0xffff - x;
+
+ if (SwapEndian)
+ x = (x << 8) | (x >> 8);
+
+ return x;
+}
+
+// Generic planar support
+static
+cmsUInt8Number* Unroll15bitsPlanar(cmsContext ContextID,
+ CMSREGISTER struct _cmstransform_struct* CMMcargo,
+ CMSREGISTER cmsUInt16Number wIn[],
+ CMSREGISTER cmsUInt8Number* accum,
+ CMSREGISTER cmsUInt32Number Stride)
+{
+ _xform_head* head = (_xform_head*) CMMcargo;
+ int nChan = T_CHANNELS(head->InputFormat);
+ int DoSwap = T_DOSWAP(head->InputFormat);
+ int Reverse = T_FLAVOR(head->InputFormat);
+ int SwapEndian = T_ENDIAN16(head->InputFormat);
+ int i;
+ cmsUInt8Number* Init = accum;
+
+ UNUSED_PARAMETER(ContextID);
+ UNUSED_PARAMETER(Stride);
+
+ if (DoSwap) {
+ accum += T_EXTRA(head->InputFormat) * Stride * 2;
+ }
+
+ for (i = 0; i < nChan; i++) {
+
+ int index = DoSwap ? (nChan - i - 1) : i;
+
+ wIn[index] = UnrollOne(*(cmsUInt16Number*)accum, Reverse, SwapEndian);
+
+ accum += Stride * 2;
+ }
+
+ return (Init + 2);
+}
+
+
+static
+cmsUInt8Number* Pack15bitsPlanar(cmsContext ContextID,
+ CMSREGISTER struct _cmstransform_struct* CMMcargo,
+ CMSREGISTER cmsUInt16Number wOut[],
+ CMSREGISTER cmsUInt8Number* output,
+ CMSREGISTER cmsUInt32Number Stride)
+{
+ _xform_head* head = (_xform_head*)CMMcargo;
+ int nChan = T_CHANNELS(head->OutputFormat);
+ int DoSwap = T_DOSWAP(head->OutputFormat);
+ int Reverse = T_FLAVOR(head->OutputFormat);
+ int SwapEndian = T_ENDIAN16(head->OutputFormat);
+ CMSREGISTER int i;
+ cmsUInt8Number* Init = output;
+
+ UNUSED_PARAMETER(ContextID);
+
+ if (DoSwap) {
+ output += T_EXTRA(head->OutputFormat) * Stride * 2;
+ }
+
+ for (i = 0; i < nChan; i++) {
+
+ int index = DoSwap ? (nChan - i - 1) : i;
+
+ *(cmsUInt16Number*)output = PackOne(wOut[index], Reverse, SwapEndian);
+ output += (Stride * sizeof(cmsUInt16Number));
+ }
+
+ return (Init + sizeof(cmsUInt16Number));
+}
+
+
+
+// Generic falltrough
+static
+cmsUInt8Number* Unroll15bitsChunky(cmsContext ContextID,
+ CMSREGISTER struct _cmstransform_struct* CMMcargo,
+ CMSREGISTER cmsUInt16Number Values[],
+ CMSREGISTER cmsUInt8Number* Buffer,
+ CMSREGISTER cmsUInt32Number Stride)
+{
+ _xform_head* head = (_xform_head*) CMMcargo;
+
+ int nChan = T_CHANNELS(head->InputFormat);
+ int DoSwap = T_DOSWAP(head->InputFormat);
+ int Reverse = T_FLAVOR(head->InputFormat);
+ int SwapEndian = T_ENDIAN16(head->InputFormat);
+
+ CMSREGISTER int i;
+
+ UNUSED_PARAMETER(ContextID);
+ UNUSED_PARAMETER(Stride);
+
+ if (DoSwap) {
+ Buffer += T_EXTRA(head->OutputFormat) * 2;
+ }
+
+ for (i = 0; i < nChan; i++) {
+
+ int index = DoSwap ? (nChan - i - 1) : i;
+
+ Values[index] = UnrollOne(*(cmsUInt16Number*)Buffer, Reverse, SwapEndian);
+
+ Buffer += 2;
+ }
+
+
+ return Buffer;
+}
+
+
+static
+cmsUInt8Number* Pack15bitsChunky(cmsContext ContextID,
+ CMSREGISTER struct _cmstransform_struct* CMMcargo,
+ CMSREGISTER cmsUInt16Number Values[],
+ CMSREGISTER cmsUInt8Number* Buffer,
+ CMSREGISTER cmsUInt32Number Stride)
+{
+ _xform_head* head = (_xform_head*)CMMcargo;
+
+ int nChan = T_CHANNELS(head->OutputFormat);
+ int DoSwap = T_DOSWAP(head->OutputFormat);
+ int Reverse = T_FLAVOR(head->OutputFormat);
+ int SwapEndian = T_ENDIAN16(head->OutputFormat);
+
+ CMSREGISTER int i;
+
+ UNUSED_PARAMETER(ContextID);
+ UNUSED_PARAMETER(Stride);
+
+ if (DoSwap) {
+ Buffer += T_EXTRA(head->OutputFormat) * 2;
+ }
+
+ for (i = 0; i < nChan; i++) {
+
+ int index = DoSwap ? (nChan - i - 1) : i;
+
+ *(cmsUInt16Number*)Buffer = PackOne(Values[index], Reverse, SwapEndian);
+
+ Buffer += 2;
+ }
+
+ return Buffer;
+}
+
+
+
+// Generic N-bytes plus dither 16-to-8 conversion.
+static int err[cmsMAXCHANNELS];
+
+static
+cmsUInt8Number* PackNBytesDither(cmsContext ContextID,
+ CMSREGISTER struct _cmstransform_struct* CMMcargo,
+ CMSREGISTER cmsUInt16Number Values[],
+ CMSREGISTER cmsUInt8Number* Buffer,
+ CMSREGISTER cmsUInt32Number Stride)
+{
+ _xform_head* info = (_xform_head*)CMMcargo;
+
+ int nChan = T_CHANNELS(info->OutputFormat);
+ CMSREGISTER int i;
+ unsigned int n, pe, pf;
+
+ UNUSED_PARAMETER(ContextID);
+ UNUSED_PARAMETER(Stride);
+
+ for (i = 0; i < nChan; i++) {
+
+ n = Values[i] + err[i]; // Value
+
+ pe = (n / 257); // Whole part
+ pf = (n % 257); // Fractional part
+
+ err[i] = pf; // Store it for next pixel
+
+ *Buffer++ = (cmsUInt8Number) pe;
+ }
+
+ return Buffer + T_EXTRA(info->OutputFormat);
+}
+
+
+static
+cmsUInt8Number* PackNBytesSwapDither(cmsContext ContextID,
+ CMSREGISTER struct _cmstransform_struct* CMMcargo,
+ CMSREGISTER cmsUInt16Number Values[],
+ CMSREGISTER cmsUInt8Number* Buffer,
+ CMSREGISTER cmsUInt32Number Stride)
+{
+ _xform_head* info = (_xform_head*)CMMcargo;
+
+ int nChan = T_CHANNELS(info->OutputFormat);
+ CMSREGISTER int i;
+ unsigned int n, pe, pf;
+
+ UNUSED_PARAMETER(ContextID);
+ UNUSED_PARAMETER(Stride);
+
+ for (i = nChan - 1; i >= 0; --i) {
+
+ n = Values[i] + err[i]; // Value
+
+ pe = (n / 257); // Whole part
+ pf = (n % 257); // Fractional part
+
+ err[i] = pf; // Store it for next pixel
+
+ *Buffer++ = (cmsUInt8Number)pe;
+ }
+
+
+ return Buffer + T_EXTRA(info->OutputFormat);
+}
+
+
+// The factory for 15 bits. This function returns a pointer to specialized function
+// that would deal with the asked format. It return a pointer to NULL if the format
+// is not supported. This is tha basis of formatter plug-in for 15 bit formats.
+cmsFormatter Formatter_15Bit_Factory(cmsContext ContextID,
+ cmsUInt32Number Type,
+ cmsFormatterDirection Dir,
+ cmsUInt32Number dwFlags)
+{
+ cmsFormatter Result = { NULL };
+
+ UNUSED_PARAMETER(ContextID);
+ UNUSED_PARAMETER(dwFlags);
+
+ switch (Type) {
+
+ // Simple Gray
+ case TYPE_GRAY_15:
+ Result.Fmt16 = (Dir == cmsFormatterInput) ? Unroll15bitsGray : Pack15bitsGray;
+ break;
+
+ // 3 channels
+ case TYPE_CMY_15:
+ case TYPE_RGB_15:
+ Result.Fmt16 = (Dir == cmsFormatterInput) ? Unroll15bitsRGB : Pack15bitsRGB;
+ break;
+
+ // 3 channels reversed
+ case TYPE_YMC_15:
+ case TYPE_BGR_15:
+ Result.Fmt16 = (Dir == cmsFormatterInput) ? Unroll15bitsBGR : Pack15bitsBGR;
+ break;
+
+ // 3 Channels plus one alpha
+ case TYPE_RGBA_15:
+ Result.Fmt16 = (Dir == cmsFormatterInput) ? Unroll15bitsRGBA : Pack15bitsRGBA;
+ break;
+
+ // 4 channels
+ case TYPE_CMYK_15:
+ Result.Fmt16 = (Dir == cmsFormatterInput) ? Unroll15bitsCMYK : Pack15bitsCMYK;
+ break;
+
+ // Planar versions
+ case TYPE_GRAYA_15_PLANAR:
+ case TYPE_RGB_15_PLANAR:
+ case TYPE_BGR_15_PLANAR:
+ case TYPE_RGBA_15_PLANAR:
+ case TYPE_ABGR_15_PLANAR:
+ case TYPE_CMY_15_PLANAR:
+ case TYPE_CMYK_15_PLANAR:
+ Result.Fmt16 = (Dir == cmsFormatterInput) ? Unroll15bitsPlanar : Pack15bitsPlanar;
+ break;
+
+ // Falltrough for remaining (corner) cases
+ case TYPE_GRAY_15_REV:
+ case TYPE_GRAY_15_SE:
+ case TYPE_GRAYA_15:
+ case TYPE_GRAYA_15_SE:
+ case TYPE_RGB_15_SE:
+ case TYPE_BGR_15_SE:
+ case TYPE_RGBA_15_SE:
+ case TYPE_ARGB_15:
+ case TYPE_ABGR_15:
+ case TYPE_ABGR_15_SE:
+ case TYPE_BGRA_15:
+ case TYPE_BGRA_15_SE:
+ case TYPE_CMY_15_SE:
+ case TYPE_CMYK_15_REV:
+ case TYPE_CMYK_15_SE:
+ case TYPE_KYMC_15:
+ case TYPE_KYMC_15_SE:
+ case TYPE_KCMY_15:
+ case TYPE_KCMY_15_REV:
+ case TYPE_KCMY_15_SE:
+ Result.Fmt16 = (Dir == cmsFormatterInput) ? Unroll15bitsChunky : Pack15bitsChunky;
+ break;
+
+ case TYPE_GRAY_8_DITHER:
+ case TYPE_RGB_8_DITHER:
+ case TYPE_RGBA_8_DITHER:
+ case TYPE_CMYK_8_DITHER:
+ if (Dir == cmsFormatterOutput) {
+ Result.Fmt16 = PackNBytesDither;
+ }
+ break;
+
+ case TYPE_ABGR_8_DITHER:
+ case TYPE_BGR_8_DITHER:
+ case TYPE_KYMC_8_DITHER:
+ if (Dir == cmsFormatterOutput) {
+ Result.Fmt16 = PackNBytesSwapDither;
+ }
+ break;
+
+ default:;
+ }
+
+ return Result;
+}
+
+
+
diff --git a/lcms2mt/plugins/fast_float/src/fast_float_15mats.c b/lcms2mt/plugins/fast_float/src/fast_float_15mats.c
new file mode 100644
index 00000000..e2a7da68
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/src/fast_float_15mats.c
@@ -0,0 +1,347 @@
+//---------------------------------------------------------------------------------
+//
+// Little Color Management System, fast floating point extensions
+// Copyright (c) 1998-2020 Marti Maria Saguer, all rights reserved
+//
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+//---------------------------------------------------------------------------------
+
+// Optimization for matrix-shaper in 15 bits. Numbers are operated in 1.15 usigned,
+
+#include "fast_float_internal.h"
+
+// An storage capable to keep 1.15 signed and some extra precission.
+// Actually I use 32 bits integer (signed)
+typedef cmsInt32Number cmsS1Fixed15Number;
+
+// Conversion to fixed. Note we don't use floor to get proper sign roundoff
+#define DOUBLE_TO_1FIXED15(x) ((cmsS1Fixed15Number) ((double) (x) * 0x8000 + 0.5))
+
+// This is the private data container used by this optimization
+typedef struct {
+
+ cmsS1Fixed15Number Mat[3][3];
+ cmsS1Fixed15Number Off[3];
+
+ // Precalculated tables for first shaper (375 Kb in total of both shapers)
+ cmsUInt16Number Shaper1R[MAX_NODES_IN_CURVE];
+ cmsUInt16Number Shaper1G[MAX_NODES_IN_CURVE];
+ cmsUInt16Number Shaper1B[MAX_NODES_IN_CURVE];
+
+ // Second shaper
+ cmsUInt16Number Shaper2R[MAX_NODES_IN_CURVE];
+ cmsUInt16Number Shaper2G[MAX_NODES_IN_CURVE];
+ cmsUInt16Number Shaper2B[MAX_NODES_IN_CURVE];
+
+ // A flag for fast operation if identity
+ cmsBool IdentityMat;
+
+ // Poits to the raw, unaligned memory
+ void * real_ptr;
+
+
+} XMatShaperData;
+
+// A special malloc that returns memory aligned to DWORD boundary. Aligned memory access is way faster than unaligned
+// reference to the real block is kept for later free
+static XMatShaperData* malloc_aligned(cmsContext ContextID)
+{
+ cmsUInt8Number* real_ptr = (cmsUInt8Number*)_cmsMallocZero(ContextID, sizeof(XMatShaperData) + 32);
+ cmsUInt8Number* aligned = (cmsUInt8Number*)(((uintptr_t)real_ptr + 16) & ~0xf);
+ XMatShaperData* p = (XMatShaperData*)aligned;
+
+ p->real_ptr = real_ptr;
+ return p;
+}
+
+
+// Free the private data container
+static
+void FreeMatShaper(cmsContext ContextID, void* Data)
+{
+
+ XMatShaperData* p = (XMatShaperData*)Data;
+ if (p != NULL)
+ _cmsFree(ContextID, p->real_ptr);
+}
+
+
+// This table converts from 8 bits to 1.14 after applying the curve
+static
+void FillShaper(cmsContext ContextID, cmsUInt16Number* Table, cmsToneCurve* Curve)
+{
+ int i;
+ cmsFloat32Number R, y;
+
+ for (i = 0; i < MAX_NODES_IN_CURVE; i++) {
+
+ R = (cmsFloat32Number)i / (cmsFloat32Number) (MAX_NODES_IN_CURVE - 1);
+ y = cmsEvalToneCurveFloat(ContextID, Curve, R);
+
+ Table[i] = (cmsUInt16Number) DOUBLE_TO_1FIXED15(y);
+ }
+}
+
+
+// Compute the matrix-shaper structure
+static
+XMatShaperData* SetMatShaper(cmsContext ContextID, cmsToneCurve* Curve1[3], cmsMAT3* Mat, cmsVEC3* Off, cmsToneCurve* Curve2[3], cmsBool IdentityMat)
+{
+ XMatShaperData* p;
+ int i, j;
+
+ // Allocate a big chuck of memory to store precomputed tables
+ p = malloc_aligned(ContextID);
+ if (p == NULL) return FALSE;
+
+ p->IdentityMat = IdentityMat;
+
+ // Precompute tables
+ FillShaper(ContextID, p->Shaper1R, Curve1[0]);
+ FillShaper(ContextID, p->Shaper1G, Curve1[1]);
+ FillShaper(ContextID, p->Shaper1B, Curve1[2]);
+
+ FillShaper(ContextID, p->Shaper2R, Curve2[0]);
+ FillShaper(ContextID, p->Shaper2G, Curve2[1]);
+ FillShaper(ContextID, p->Shaper2B, Curve2[2]);
+
+ // Convert matrix to nFixed14. Note that those values may take more than 16 bits if negative
+ for (i = 0; i < 3; i++) {
+ for (j = 0; j < 3; j++) {
+
+ p->Mat[i][j] = DOUBLE_TO_1FIXED15(Mat->v[i].n[j]);
+ }
+ }
+
+
+ for (i = 0; i < 3; i++) {
+
+ if (Off == NULL) {
+
+ p->Off[i] = 0x4000;
+
+ }
+ else {
+ p->Off[i] = DOUBLE_TO_1FIXED15(Off->n[i]) + 0x4000;
+
+ }
+ }
+
+
+ return p;
+}
+
+// A fast matrix-shaper evaluator for 15 bits. This is a bit ticky since I'm using 1.15 signed fixed point.
+static
+void MatShaperXform(cmsContext ContextID,
+ struct _cmstransform_struct *CMMcargo,
+ const void* Input,
+ void* Output,
+ cmsUInt32Number PixelsPerLine,
+ cmsUInt32Number LineCount,
+ const cmsStride* Stride)
+{
+ XMatShaperData* p = (XMatShaperData*)_cmsGetTransformUserData(CMMcargo);
+
+ cmsS1Fixed15Number l1, l2, l3;
+
+ cmsS1Fixed15Number r, g, b;
+ cmsUInt32Number ri, gi, bi;
+ cmsUInt32Number i, ii;
+ cmsUInt32Number SourceStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number SourceIncrements[cmsMAXCHANNELS];
+ cmsUInt32Number DestStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number DestIncrements[cmsMAXCHANNELS];
+
+ const cmsUInt8Number* rin;
+ const cmsUInt8Number* gin;
+ const cmsUInt8Number* bin;
+ const cmsUInt8Number* ain = NULL;
+
+ cmsUInt8Number* rout;
+ cmsUInt8Number* gout;
+ cmsUInt8Number* bout;
+ cmsUInt8Number* aout = NULL;
+
+ cmsUInt32Number nalpha, strideIn, strideOut;
+
+ _cmsComputeComponentIncrements(cmsGetTransformInputFormat(ContextID, (cmsHTRANSFORM)CMMcargo), Stride->BytesPerPlaneIn, NULL, &nalpha, SourceStartingOrder, SourceIncrements);
+ _cmsComputeComponentIncrements(cmsGetTransformOutputFormat(ContextID, (cmsHTRANSFORM)CMMcargo), Stride->BytesPerPlaneOut, NULL, &nalpha, DestStartingOrder, DestIncrements);
+
+ strideIn = strideOut = 0;
+ for (i = 0; i < LineCount; i++) {
+
+ rin = (const cmsUInt8Number*)Input + SourceStartingOrder[0] + strideIn;
+ gin = (const cmsUInt8Number*)Input + SourceStartingOrder[1] + strideIn;
+ bin = (const cmsUInt8Number*)Input + SourceStartingOrder[2] + strideIn;
+ if (nalpha)
+ ain = (const cmsUInt8Number*)Input + SourceStartingOrder[3] + strideIn;
+
+
+ rout = (cmsUInt8Number*)Output + DestStartingOrder[0] + strideOut;
+ gout = (cmsUInt8Number*)Output + DestStartingOrder[1] + strideOut;
+ bout = (cmsUInt8Number*)Output + DestStartingOrder[2] + strideOut;
+ if (nalpha)
+ aout = (cmsUInt8Number*)Output + DestStartingOrder[3] + strideOut;
+
+
+ for (ii = 0; ii < PixelsPerLine; ii++) {
+
+ // Across first shaper, which also converts to 1.15 fixed point.
+ r = p->Shaper1R[*(cmsUInt16Number*)rin];
+ g = p->Shaper1G[*(cmsUInt16Number*)gin];
+ b = p->Shaper1B[*(cmsUInt16Number*)bin];
+
+ if (p->IdentityMat)
+ {
+ l1 = r; l2 = g; l3 = b;
+ }
+ else
+ {
+ // Evaluate the matrix in 1.14 fixed point
+ l1 = (p->Mat[0][0] * r + p->Mat[0][1] * g + p->Mat[0][2] * b + p->Off[0]) >> 15;
+ l2 = (p->Mat[1][0] * r + p->Mat[1][1] * g + p->Mat[1][2] * b + p->Off[1]) >> 15;
+ l3 = (p->Mat[2][0] * r + p->Mat[2][1] * g + p->Mat[2][2] * b + p->Off[2]) >> 15;
+ }
+
+ // Now we have to clip to 0..1.0 range
+ ri = (l1 < 0) ? 0 : ((l1 > 0x8000) ? 0x8000 : l1);
+ gi = (l2 < 0) ? 0 : ((l2 > 0x8000) ? 0x8000 : l2);
+ bi = (l3 < 0) ? 0 : ((l3 > 0x8000) ? 0x8000 : l3);
+
+
+ // And across second shaper,
+ *(cmsUInt16Number*)rout = p->Shaper2R[ri];
+ *(cmsUInt16Number*)gout = p->Shaper2G[gi];
+ *(cmsUInt16Number*)bout = p->Shaper2B[bi];
+
+
+ // Handle alpha
+ if (ain) {
+ memmove(aout, ain, 2);
+ }
+
+ rin += SourceIncrements[0];
+ gin += SourceIncrements[1];
+ bin += SourceIncrements[2];
+ if (ain) ain += SourceIncrements[3];
+
+ rout += DestIncrements[0];
+ gout += DestIncrements[1];
+ bout += DestIncrements[2];
+ if (aout) aout += DestIncrements[3];
+ }
+
+ strideIn += Stride->BytesPerLineIn;
+ strideOut += Stride->BytesPerLineOut;
+ }
+}
+
+
+
+// 15 bits on input allows matrix-shaper boost up a little bit
+cmsBool OptimizeMatrixShaper15(cmsContext ContextID,
+ _cmsTransformFn* TransformFn,
+ void** UserData,
+ _cmsFreeUserDataFn* FreeUserData,
+ cmsPipeline** Lut,
+ cmsUInt32Number* InputFormat,
+ cmsUInt32Number* OutputFormat,
+ cmsUInt32Number* dwFlags)
+{
+ cmsStage* Curve1, *Curve2;
+ cmsStage* Matrix1, *Matrix2;
+ _cmsStageMatrixData* Data1;
+ _cmsStageMatrixData* Data2;
+ cmsMAT3 res;
+ cmsBool IdentityMat = FALSE;
+ cmsPipeline* Dest, *Src;
+
+ cmsUInt32Number nChans;
+
+ // Only works on RGB to RGB and gray
+
+ if (!(T_CHANNELS(*InputFormat) == 3 && T_CHANNELS(*OutputFormat) == 3)) return FALSE;
+
+ // Only works on 15 bit to 15 bit
+ if (T_BYTES(*InputFormat) != 2 || T_BYTES(*OutputFormat) != 2 ||
+ T_BIT15(*InputFormat) == 0 || T_BIT15(*OutputFormat) == 0) return FALSE;
+
+ // Seems suitable, proceed
+ Src = *Lut;
+
+ // Check for shaper-matrix-matrix-shaper structure, that is what this optimizer stands for
+ if (!cmsPipelineCheckAndRetreiveStages(ContextID, Src, 4,
+ cmsSigCurveSetElemType, cmsSigMatrixElemType, cmsSigMatrixElemType, cmsSigCurveSetElemType,
+ &Curve1, &Matrix1, &Matrix2, &Curve2)) return FALSE;
+
+ nChans = T_CHANNELS(*InputFormat);
+
+ // Get both matrices, which are 3x3
+ Data1 = (_cmsStageMatrixData*)cmsStageData(ContextID, Matrix1);
+ Data2 = (_cmsStageMatrixData*)cmsStageData(ContextID, Matrix2);
+
+ // Input offset should be zero
+ if (Data1->Offset != NULL) return FALSE;
+
+ // Multiply both matrices to get the result
+ _cmsMAT3per(ContextID, &res, (cmsMAT3*)Data2->Double, (cmsMAT3*)Data1->Double);
+
+ // Now the result is in res + Data2 -> Offset. Maybe is a plain identity?
+ IdentityMat = FALSE;
+ if (_cmsMAT3isIdentity(ContextID, &res) && Data2->Offset == NULL) {
+
+ // We can get rid of full matrix
+ IdentityMat = TRUE;
+ }
+
+
+ // Allocate an empty LUT
+ Dest = cmsPipelineAlloc(ContextID, nChans, nChans);
+ if (!Dest) return FALSE;
+
+ // Assamble the new LUT
+ cmsPipelineInsertStage(ContextID, Dest, cmsAT_BEGIN, cmsStageDup(ContextID, Curve1));
+
+ if (!IdentityMat) {
+
+ cmsPipelineInsertStage(ContextID, Dest, cmsAT_END,
+ cmsStageAllocMatrix(ContextID, 3, 3, (const cmsFloat64Number*)&res, Data2->Offset));
+ }
+
+ cmsPipelineInsertStage(ContextID, Dest, cmsAT_END, cmsStageDup(ContextID, Curve2));
+
+ {
+ _cmsStageToneCurvesData* mpeC1 = (_cmsStageToneCurvesData*)cmsStageData(ContextID, Curve1);
+ _cmsStageToneCurvesData* mpeC2 = (_cmsStageToneCurvesData*)cmsStageData(ContextID, Curve2);
+
+ // In this particular optimization, caché does not help as it takes more time to deal with
+ // the caché that with the pixel handling
+ *dwFlags |= cmsFLAGS_NOCACHE;
+
+ // Setup the optimizarion routines
+ *UserData = SetMatShaper(ContextID, mpeC1->TheCurves, &res, (cmsVEC3*)Data2->Offset, mpeC2->TheCurves, IdentityMat);
+ *FreeUserData = FreeMatShaper;
+
+ *TransformFn = (_cmsTransformFn)MatShaperXform;
+ }
+
+
+ cmsPipelineFree(ContextID, Src);
+ *dwFlags &= ~cmsFLAGS_CAN_CHANGE_FORMATTER;
+ *Lut = Dest;
+ return TRUE;
+}
diff --git a/lcms2mt/plugins/fast_float/src/fast_float_cmyk.c b/lcms2mt/plugins/fast_float/src/fast_float_cmyk.c
new file mode 100644
index 00000000..1886b966
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/src/fast_float_cmyk.c
@@ -0,0 +1,379 @@
+//---------------------------------------------------------------------------------
+//
+// Little Color Management System, fast floating point extensions
+// Copyright (c) 1998-2020 Marti Maria Saguer, all rights reserved
+//
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+//---------------------------------------------------------------------------------
+
+#include "fast_float_internal.h"
+
+// Optimization for floating point tetrahedral interpolation
+typedef struct {
+
+ const cmsInterpParams* p; // Tetrahedrical interpolation parameters. This is a not-owned pointer.
+
+} FloatCMYKData;
+
+
+
+// Precomputes tables on input devicelink.
+static
+FloatCMYKData* FloatCMYKAlloc(cmsContext ContextID, const cmsInterpParams* p)
+{
+ FloatCMYKData* fd;
+
+ fd = (FloatCMYKData*) _cmsMallocZero(ContextID, sizeof(FloatCMYKData));
+ if (fd == NULL) return NULL;
+
+ fd ->p = p;
+ return fd;
+}
+
+
+static
+int XFormSampler(cmsContext ContextID, CMSREGISTER const cmsFloat32Number In[], CMSREGISTER cmsFloat32Number Out[], CMSREGISTER void* Cargo)
+{
+ // Evaluate in 16 bits
+ cmsPipelineEvalFloat(ContextID, In, Out, (cmsPipeline*) Cargo);
+
+ // Always succeed
+ return TRUE;
+}
+
+cmsINLINE cmsFloat32Number LinearInterpInt(cmsFloat32Number a, cmsFloat32Number l, cmsFloat32Number h)
+{
+ return (h - l) * a + l;
+}
+
+// To prevent out of bounds indexing
+cmsINLINE cmsFloat32Number fclamp100(cmsFloat32Number v)
+{
+ return v < 0.0f ? 0.0f : (v > 100.0f ? 100.0f : v);
+}
+
+
+// A optimized interpolation for 8-bit input.
+#define DENS(i,j,k) (LutTable[(i)+(j)+(k)+OutChan])
+
+static
+void FloatCMYKCLUTEval(cmsContext ContextID,
+ struct _cmstransform_struct *CMMcargo,
+ const cmsFloat32Number* Input,
+ cmsFloat32Number* Output,
+ cmsUInt32Number len,
+ cmsUInt32Number Stride)
+{
+
+ cmsFloat32Number c, m, y, k;
+ cmsFloat32Number px, py, pz, pk;
+ int x0, y0, z0, k0;
+ int X0, Y0, Z0, K0, X1, Y1, Z1, K1;
+ cmsFloat32Number rx, ry, rz, rk;
+ cmsFloat32Number c0, c1 = 0, c2 = 0, c3 = 0;
+
+ cmsUInt32Number OutChan;
+ FloatCMYKData* p8 = (FloatCMYKData*) _cmsGetTransformUserData(CMMcargo);
+
+ const cmsInterpParams* p = p8 ->p;
+ cmsUInt32Number TotalOut = p -> nOutputs;
+ const cmsFloat32Number* LutTable = (const cmsFloat32Number*)p->Table;
+ cmsUInt32Number ii;
+ const cmsUInt8Number* cin;
+ const cmsUInt8Number* min;
+ const cmsUInt8Number* yin;
+ const cmsUInt8Number* kin;
+
+ cmsFloat32Number Tmp1[cmsMAXCHANNELS], Tmp2[cmsMAXCHANNELS];
+
+ cmsUInt8Number* out[cmsMAXCHANNELS];
+ cmsUInt32Number SourceStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number SourceIncrements[cmsMAXCHANNELS];
+ cmsUInt32Number DestStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number DestIncrements[cmsMAXCHANNELS];
+
+ cmsUInt32Number InputFormat = cmsGetTransformInputFormat(ContextID, (cmsHTRANSFORM) CMMcargo);
+ cmsUInt32Number OutputFormat = cmsGetTransformOutputFormat(ContextID, (cmsHTRANSFORM) CMMcargo);
+
+ cmsUInt32Number nchans, nalpha;
+
+ _cmsComputeComponentIncrements(InputFormat, Stride, &nchans, &nalpha, SourceStartingOrder, SourceIncrements);
+ _cmsComputeComponentIncrements(OutputFormat, Stride, &nchans, &nalpha, DestStartingOrder, DestIncrements);
+
+ // SeparateCMYK(InputFormat, Stride, SourceStartingOrder, SourceIncrements);
+ // SeparateCMYK(OutputFormat, Stride, DestStartingOrder, DestIncrements);
+
+ cin = (const cmsUInt8Number*)Input + SourceStartingOrder[0];
+ min = (const cmsUInt8Number*)Input + SourceStartingOrder[1];
+ yin = (const cmsUInt8Number*)Input + SourceStartingOrder[2];
+ kin = (const cmsUInt8Number*)Input + SourceStartingOrder[3];
+
+ for (ii=0; ii < TotalOut; ii++)
+ out[ii] = (cmsUInt8Number*)Output + DestStartingOrder[ii];
+
+ for (ii=0; ii < len; ii++) {
+
+ c = fclamp100(*(cmsFloat32Number*)cin) / 100.0f;
+ m = fclamp100(*(cmsFloat32Number*)min) / 100.0f;
+ y = fclamp100(*(cmsFloat32Number*)yin) / 100.0f;
+ k = fclamp100(*(cmsFloat32Number*)kin) / 100.0f;
+
+ cin += SourceIncrements[0];
+ min += SourceIncrements[1];
+ yin += SourceIncrements[2];
+ kin += SourceIncrements[3];
+
+ pk = c * p->Domain[0]; // C
+ px = m * p->Domain[1]; // M
+ py = y * p->Domain[2]; // Y
+ pz = k * p->Domain[3]; // K
+
+
+ k0 = (int)_cmsQuickFloor(pk); rk = (pk - (cmsFloat32Number)k0);
+ x0 = (int)_cmsQuickFloor(px); rx = (px - (cmsFloat32Number)x0);
+ y0 = (int)_cmsQuickFloor(py); ry = (py - (cmsFloat32Number)y0);
+ z0 = (int)_cmsQuickFloor(pz); rz = (pz - (cmsFloat32Number)z0);
+
+
+ K0 = p->opta[3] * k0;
+ K1 = K0 + (c >= 1.0 ? 0 : p->opta[3]);
+
+ X0 = p->opta[2] * x0;
+ X1 = X0 + (m >= 1.0 ? 0 : p->opta[2]);
+
+ Y0 = p->opta[1] * y0;
+ Y1 = Y0 + (y >= 1.0 ? 0 : p->opta[1]);
+
+ Z0 = p->opta[0] * z0;
+ Z1 = Z0 + (k >= 1.0 ? 0 : p->opta[0]);
+
+ for (OutChan = 0; OutChan < TotalOut; OutChan++) {
+
+ c0 = DENS(X0, Y0, Z0);
+
+ if (rx >= ry && ry >= rz) {
+
+ c1 = DENS(X1, Y0, Z0) - c0;
+ c2 = DENS(X1, Y1, Z0) - DENS(X1, Y0, Z0);
+ c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);
+
+ }
+ else
+ if (rx >= rz && rz >= ry) {
+
+ c1 = DENS(X1, Y0, Z0) - c0;
+ c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);
+ c3 = DENS(X1, Y0, Z1) - DENS(X1, Y0, Z0);
+
+ }
+ else
+ if (rz >= rx && rx >= ry) {
+
+ c1 = DENS(X1, Y0, Z1) - DENS(X0, Y0, Z1);
+ c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);
+ c3 = DENS(X0, Y0, Z1) - c0;
+
+ }
+ else
+ if (ry >= rx && rx >= rz) {
+
+ c1 = DENS(X1, Y1, Z0) - DENS(X0, Y1, Z0);
+ c2 = DENS(X0, Y1, Z0) - c0;
+ c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);
+
+ }
+ else
+ if (ry >= rz && rz >= rx) {
+
+ c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);
+ c2 = DENS(X0, Y1, Z0) - c0;
+ c3 = DENS(X0, Y1, Z1) - DENS(X0, Y1, Z0);
+
+ }
+ else
+ if (rz >= ry && ry >= rx) {
+
+ c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);
+ c2 = DENS(X0, Y1, Z1) - DENS(X0, Y0, Z1);
+ c3 = DENS(X0, Y0, Z1) - c0;
+
+ }
+ else {
+ c1 = c2 = c3 = 0;
+ }
+
+
+ Tmp1[OutChan] = c0 + c1 * rx + c2 * ry + c3 * rz;
+
+ }
+
+
+ LutTable = (cmsFloat32Number*)p->Table;
+ LutTable += K1;
+
+ for (OutChan = 0; OutChan < p->nOutputs; OutChan++) {
+
+ c0 = DENS(X0, Y0, Z0);
+
+ if (rx >= ry && ry >= rz) {
+
+ c1 = DENS(X1, Y0, Z0) - c0;
+ c2 = DENS(X1, Y1, Z0) - DENS(X1, Y0, Z0);
+ c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);
+
+ }
+ else
+ if (rx >= rz && rz >= ry) {
+
+ c1 = DENS(X1, Y0, Z0) - c0;
+ c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);
+ c3 = DENS(X1, Y0, Z1) - DENS(X1, Y0, Z0);
+
+ }
+ else
+ if (rz >= rx && rx >= ry) {
+
+ c1 = DENS(X1, Y0, Z1) - DENS(X0, Y0, Z1);
+ c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);
+ c3 = DENS(X0, Y0, Z1) - c0;
+
+ }
+ else
+ if (ry >= rx && rx >= rz) {
+
+ c1 = DENS(X1, Y1, Z0) - DENS(X0, Y1, Z0);
+ c2 = DENS(X0, Y1, Z0) - c0;
+ c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);
+
+ }
+ else
+ if (ry >= rz && rz >= rx) {
+
+ c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);
+ c2 = DENS(X0, Y1, Z0) - c0;
+ c3 = DENS(X0, Y1, Z1) - DENS(X0, Y1, Z0);
+
+ }
+ else
+ if (rz >= ry && ry >= rx) {
+
+ c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);
+ c2 = DENS(X0, Y1, Z1) - DENS(X0, Y0, Z1);
+ c3 = DENS(X0, Y0, Z1) - c0;
+
+ }
+ else {
+ c1 = c2 = c3 = 0;
+ }
+
+ Tmp2[OutChan] = c0 + c1 * rx + c2 * ry + c3 * rz;
+ }
+
+
+ for (OutChan = 0; OutChan < p->nOutputs; OutChan++) {
+
+ *(cmsFloat32Number*)(out[OutChan]) = LinearInterpInt(rk, Tmp1[OutChan], Tmp2[OutChan]);
+ out[OutChan] += DestIncrements[OutChan];
+ }
+
+
+ }
+}
+
+#undef DENS
+
+
+
+// --------------------------------------------------------------------------------------------------------------
+
+cmsBool OptimizeCLUTCMYKTransform(cmsContext ContextID,
+ _cmsTransformFn* TransformFn,
+ void** UserData,
+ _cmsFreeUserDataFn* FreeDataFn,
+ cmsPipeline** Lut,
+ cmsUInt32Number* InputFormat,
+ cmsUInt32Number* OutputFormat,
+ cmsUInt32Number* dwFlags)
+{
+ cmsPipeline* OriginalLut;
+ int nGridPoints;
+ cmsPipeline* OptimizedLUT = NULL;
+ cmsStage* OptimizedCLUTmpe;
+ cmsColorSpaceSignature OutputColorSpace;
+ cmsStage* mpe;
+ FloatCMYKData* p8;
+ _cmsStageCLutData* data;
+
+ // For empty transforms, do nothing
+ if (*Lut == NULL) return FALSE;
+
+ // This is a loosy optimization! does not apply in floating-point cases
+ if (!T_FLOAT(*InputFormat) || !T_FLOAT(*OutputFormat)) return FALSE;
+
+ // Only on 8-bit
+ if (T_BYTES(*InputFormat) != 4 || T_BYTES(*OutputFormat) != 4) return FALSE;
+
+ // Only on CMYK
+ if (T_COLORSPACE(*InputFormat) != PT_CMYK) return FALSE;
+
+ OriginalLut = *Lut;
+
+ // Named color pipelines cannot be optimized either
+ for (mpe = cmsPipelineGetPtrToFirstStage(ContextID, OriginalLut);
+ mpe != NULL;
+ mpe = cmsStageNext(ContextID, mpe)) {
+ if (cmsStageType(ContextID, mpe) == cmsSigNamedColorElemType) return FALSE;
+ }
+
+ OutputColorSpace = _cmsICCcolorSpace(ContextID, T_COLORSPACE(*OutputFormat));
+ nGridPoints = _cmsReasonableGridpointsByColorspace(cmsSigRgbData, *dwFlags);
+
+ // Create the result LUT
+ OptimizedLUT = cmsPipelineAlloc(ContextID, 4, cmsPipelineOutputChannels(ContextID, OriginalLut));
+ if (OptimizedLUT == NULL) goto Error;
+
+
+ // Allocate the CLUT for result
+ OptimizedCLUTmpe = cmsStageAllocCLutFloat(ContextID, nGridPoints, 4, cmsPipelineOutputChannels(ContextID, OriginalLut), NULL);
+
+ // Add the CLUT to the destination LUT
+ cmsPipelineInsertStage(ContextID, OptimizedLUT, cmsAT_BEGIN, OptimizedCLUTmpe);
+
+ // Resample the LUT
+ if (!cmsStageSampleCLutFloat(ContextID, OptimizedCLUTmpe, XFormSampler, (void*)OriginalLut, 0)) goto Error;
+
+ // Set the evaluator, copy parameters
+ data = (_cmsStageCLutData*) cmsStageData(ContextID, OptimizedCLUTmpe);
+
+ p8 = FloatCMYKAlloc(ContextID, data ->Params);
+ if (p8 == NULL) return FALSE;
+
+ // And return the obtained LUT
+ cmsPipelineFree(ContextID, OriginalLut);
+
+ *Lut = OptimizedLUT;
+ *TransformFn = (_cmsTransformFn) FloatCMYKCLUTEval;
+ *UserData = p8;
+ *FreeDataFn = _cmsFree;
+ *dwFlags &= ~cmsFLAGS_CAN_CHANGE_FORMATTER;
+ return TRUE;
+
+Error:
+
+ if (OptimizedLUT != NULL) cmsPipelineFree(ContextID, OptimizedLUT);
+
+ return FALSE;
+}
diff --git a/lcms2mt/plugins/fast_float/src/fast_float_curves.c b/lcms2mt/plugins/fast_float/src/fast_float_curves.c
new file mode 100644
index 00000000..e6e42fb6
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/src/fast_float_curves.c
@@ -0,0 +1,384 @@
+//---------------------------------------------------------------------------------
+//
+// Little Color Management System, fast floating point extensions
+// Copyright (c) 1998-2020 Marti Maria Saguer, all rights reserved
+//
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+//---------------------------------------------------------------------------------
+
+#include "fast_float_internal.h"
+
+// Curves, optimization is valid for floating point curves
+typedef struct {
+
+ cmsFloat32Number CurveR[MAX_NODES_IN_CURVE];
+ cmsFloat32Number CurveG[MAX_NODES_IN_CURVE];
+ cmsFloat32Number CurveB[MAX_NODES_IN_CURVE];
+
+ void* real_ptr;
+
+} CurvesFloatData;
+
+
+
+// A special malloc that returns memory aligned to DWORD boundary. Aligned memory access is way faster than unaligned
+// reference to the real block is kept for later free
+static CurvesFloatData* malloc_aligned(cmsContext ContextID)
+{
+ cmsUInt8Number* real_ptr = (cmsUInt8Number*)_cmsMallocZero(ContextID, sizeof(CurvesFloatData) + 32);
+ cmsUInt8Number* aligned = (cmsUInt8Number*)(((uintptr_t)real_ptr + 16) & ~0xf);
+ CurvesFloatData* p = (CurvesFloatData*)aligned;
+
+ p->real_ptr = real_ptr;
+
+ return p;
+}
+
+// Free the private data container
+static void free_aligned(cmsContext ContextID, void* Data)
+{
+ CurvesFloatData* p = (CurvesFloatData*)Data;
+ if (p != NULL)
+ _cmsFree(ContextID, p->real_ptr);
+}
+
+// Evaluator for float curves. This are just 1D tables
+
+static void FastEvaluateFloatRGBCurves(cmsContext ContextID,
+ struct _cmstransform_struct *CMMcargo,
+ const cmsFloat32Number* Input,
+ cmsFloat32Number* Output,
+ cmsUInt32Number len,
+ cmsUInt32Number Stride)
+{
+ cmsUInt32Number ii;
+ cmsUInt32Number SourceStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number SourceIncrements[cmsMAXCHANNELS];
+ cmsUInt32Number DestStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number DestIncrements[cmsMAXCHANNELS];
+
+ const cmsUInt8Number* rin;
+ const cmsUInt8Number* gin;
+ const cmsUInt8Number* bin;
+
+ cmsUInt8Number* rout;
+ cmsUInt8Number* gout;
+ cmsUInt8Number* bout;
+
+ cmsUInt32Number InputFormat = cmsGetTransformInputFormat(ContextID, (cmsHTRANSFORM) CMMcargo);
+ cmsUInt32Number OutputFormat = cmsGetTransformOutputFormat(ContextID, (cmsHTRANSFORM) CMMcargo);
+
+ CurvesFloatData* Data = (CurvesFloatData*) _cmsGetTransformUserData(CMMcargo);
+
+ cmsUInt32Number nchans, nalpha;
+
+ _cmsComputeComponentIncrements(InputFormat, Stride, &nchans, &nalpha, SourceStartingOrder, SourceIncrements);
+ _cmsComputeComponentIncrements(OutputFormat, Stride, &nchans, &nalpha, DestStartingOrder, DestIncrements);
+
+ // SeparateRGB(InputFormat, Stride, SourceStartingOrder, SourceIncrements);
+ // SeparateRGB(OutputFormat, Stride, DestStartingOrder, DestIncrements);
+
+ rin = (const cmsUInt8Number*)Input + SourceStartingOrder[0];
+ gin = (const cmsUInt8Number*)Input + SourceStartingOrder[1];
+ bin = (const cmsUInt8Number*)Input + SourceStartingOrder[2];
+
+ rout = (cmsUInt8Number*)Output + DestStartingOrder[0];
+ gout = (cmsUInt8Number*)Output + DestStartingOrder[1];
+ bout = (cmsUInt8Number*)Output + DestStartingOrder[2];
+
+ for (ii = 0; ii < len; ii++) {
+
+ *(cmsFloat32Number*)rout = flerp(Data->CurveR, *(cmsFloat32Number*)rin);
+ *(cmsFloat32Number*)gout = flerp(Data->CurveG, *(cmsFloat32Number*)gin);
+ *(cmsFloat32Number*)bout = flerp(Data->CurveB, *(cmsFloat32Number*)bin);
+
+ rin += SourceIncrements[0];
+ gin += SourceIncrements[1];
+ bin += SourceIncrements[2];
+
+ rout += DestIncrements[0];
+ gout += DestIncrements[1];
+ bout += DestIncrements[2];
+ }
+}
+
+// Do nothing but arrange the RGB format.
+static void FastFloatRGBIdentity(cmsContext ContextID,
+ struct _cmstransform_struct *CMMcargo,
+ const cmsFloat32Number* Input,
+ cmsFloat32Number* Output,
+ cmsUInt32Number len,
+ cmsUInt32Number Stride)
+{
+ cmsUInt32Number ii;
+ cmsUInt32Number SourceStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number SourceIncrements[cmsMAXCHANNELS];
+ cmsUInt32Number DestStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number DestIncrements[cmsMAXCHANNELS];
+ const cmsUInt8Number* rin;
+ const cmsUInt8Number* gin;
+ const cmsUInt8Number* bin;
+ cmsUInt8Number* rout;
+ cmsUInt8Number* gout;
+ cmsUInt8Number* bout;
+
+
+ cmsUInt32Number InputFormat = cmsGetTransformInputFormat(ContextID, (cmsHTRANSFORM) CMMcargo);
+ cmsUInt32Number OutputFormat = cmsGetTransformOutputFormat(ContextID, (cmsHTRANSFORM) CMMcargo);
+
+
+ cmsUInt32Number nchans, nalpha;
+
+ _cmsComputeComponentIncrements(InputFormat, Stride, &nchans, &nalpha, SourceStartingOrder, SourceIncrements);
+ _cmsComputeComponentIncrements(OutputFormat, Stride, &nchans, &nalpha, DestStartingOrder, DestIncrements);
+
+ // SeparateRGB(InputFormat, Stride, SourceStartingOrder, SourceIncrements);
+ // SeparateRGB(OutputFormat, Stride, DestStartingOrder, DestIncrements);
+
+ rin = (const cmsUInt8Number*)Input + SourceStartingOrder[0];
+ gin = (const cmsUInt8Number*)Input + SourceStartingOrder[1];
+ bin = (const cmsUInt8Number*)Input + SourceStartingOrder[2];
+
+ rout = (cmsUInt8Number*)Output + DestStartingOrder[0];
+ gout = (cmsUInt8Number*)Output + DestStartingOrder[1];
+ bout = (cmsUInt8Number*)Output + DestStartingOrder[2];
+
+ for (ii=0; ii < len; ii++) {
+
+ memmove(rout, rin, 4);
+ memmove(gout, gin, 4);
+ memmove(bout, bin, 4);
+
+ rin += SourceIncrements[0];
+ gin += SourceIncrements[1];
+ bin += SourceIncrements[2];
+
+ rout += DestIncrements[0];
+ gout += DestIncrements[1];
+ bout += DestIncrements[2];
+ }
+}
+
+// Evaluate 1 channel only
+static void FastEvaluateFloatGrayCurves(cmsContext ContextID,
+ struct _cmstransform_struct *CMMcargo,
+ const cmsFloat32Number* Input,
+ cmsFloat32Number* Output,
+ cmsUInt32Number len,
+ cmsUInt32Number Stride)
+{
+ cmsUInt32Number ii;
+ cmsUInt32Number SourceStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number SourceIncrements[cmsMAXCHANNELS];
+ cmsUInt32Number DestStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number DestIncrements[cmsMAXCHANNELS];
+ const cmsUInt8Number* kin;
+ cmsUInt8Number* kout;
+
+ cmsUInt32Number InputFormat = cmsGetTransformInputFormat(ContextID, (cmsHTRANSFORM) CMMcargo);
+ cmsUInt32Number OutputFormat = cmsGetTransformOutputFormat(ContextID, (cmsHTRANSFORM) CMMcargo);
+
+ CurvesFloatData* Data = (CurvesFloatData*) _cmsGetTransformUserData(CMMcargo);
+
+ cmsUInt32Number nchans, nalpha;
+
+ _cmsComputeComponentIncrements(InputFormat, Stride, &nchans, &nalpha, SourceStartingOrder, SourceIncrements);
+ _cmsComputeComponentIncrements(OutputFormat, Stride, &nchans, &nalpha, DestStartingOrder, DestIncrements);
+
+ // SeparateGray(InputFormat, Stride, &SourceStartingOrder, &SourceIncrement);
+ // SeparateGray(OutputFormat, Stride, &DestStartingOrder, &DestIncrement);
+
+ kin = (const cmsUInt8Number*)Input + SourceStartingOrder[0];
+ kout = (cmsUInt8Number*)Output + DestStartingOrder[0];
+
+ for (ii = 0; ii < len; ii++) {
+
+ *(cmsFloat32Number*)kout = flerp(Data->CurveR, *(cmsFloat32Number*)kin);
+
+ kin += SourceIncrements[0];
+ kout += DestIncrements[0];
+ }
+}
+
+
+static void FastFloatGrayIdentity(cmsContext ContextID,
+ struct _cmstransform_struct *CMMcargo,
+ const cmsFloat32Number* Input,
+ cmsFloat32Number* Output,
+ cmsUInt32Number len,
+ cmsUInt32Number Stride)
+{
+ cmsUInt32Number ii;
+ cmsUInt32Number SourceStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number SourceIncrements[cmsMAXCHANNELS];
+ cmsUInt32Number DestStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number DestIncrements[cmsMAXCHANNELS];
+ const cmsUInt8Number* kin;
+ cmsUInt8Number* kout;
+
+ cmsUInt32Number InputFormat = cmsGetTransformInputFormat(ContextID, (cmsHTRANSFORM) CMMcargo);
+ cmsUInt32Number OutputFormat = cmsGetTransformOutputFormat(ContextID, (cmsHTRANSFORM) CMMcargo);
+
+ cmsUInt32Number nchans, nalpha;
+
+ _cmsComputeComponentIncrements(InputFormat, Stride, &nchans, &nalpha, SourceStartingOrder, SourceIncrements);
+ _cmsComputeComponentIncrements(OutputFormat, Stride, &nchans, &nalpha, DestStartingOrder, DestIncrements);
+
+ // SeparateGray(InputFormat, Stride, &SourceStartingOrder, &SourceIncrement);
+ // SeparateGray(OutputFormat, Stride, &DestStartingOrder, &DestIncrement);
+
+ kin = (const cmsUInt8Number*) Input + SourceStartingOrder[0];
+ kout = (cmsUInt8Number*)Output + DestStartingOrder[0];
+
+ for (ii=0; ii < len; ii++) {
+
+ memmove(kout, kin, 4);
+
+ kin += SourceIncrements[0];
+ kout += DestIncrements[0];
+ }
+}
+
+
+#define LINEAR_CURVES_EPSILON 0.00001
+
+// Try to see if the curves are linear
+static
+cmsBool AllRGBCurvesAreLinear(CurvesFloatData* data)
+{
+ int j;
+ cmsFloat32Number expected;
+
+ for (j = 0; j < MAX_NODES_IN_CURVE; j++) {
+
+ expected = (cmsFloat32Number)j / (cmsFloat32Number)(MAX_NODES_IN_CURVE - 1);
+
+ if (fabsf(data->CurveR[j] - expected) > LINEAR_CURVES_EPSILON ||
+ fabsf(data->CurveG[j] - expected) > LINEAR_CURVES_EPSILON ||
+ fabsf(data->CurveB[j] - expected) > LINEAR_CURVES_EPSILON) {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+static
+cmsBool KCurveIsLinear(CurvesFloatData* data)
+{
+ int j;
+ cmsFloat32Number expected;
+
+ for (j = 0; j < MAX_NODES_IN_CURVE; j++) {
+ expected = (cmsFloat32Number)j / (cmsFloat32Number)(MAX_NODES_IN_CURVE - 1);
+
+ if (fabs(data->CurveR[j] - expected) > LINEAR_CURVES_EPSILON) return FALSE;
+ }
+
+
+ return TRUE;
+}
+
+
+// Create linearization tables with a reasonable number of entries. Precission is about 32 bits.
+static
+CurvesFloatData* ComputeCompositeCurves(cmsContext ContextID, cmsUInt32Number nChan, cmsPipeline* Src)
+{
+ cmsUInt32Number i, j;
+ cmsFloat32Number InFloat[3], OutFloat[3];
+
+ CurvesFloatData* Data = malloc_aligned(ContextID);
+ if (Data == NULL) return NULL;
+
+ // Create target curves
+ for (i = 0; i < MAX_NODES_IN_CURVE; i++) {
+
+ for (j=0; j <nChan; j++)
+ InFloat[j] = (cmsFloat32Number)i / (cmsFloat32Number)(MAX_NODES_IN_CURVE-1);
+
+ cmsPipelineEvalFloat(ContextID, InFloat, OutFloat, Src);
+
+ if (nChan == 1) {
+
+ Data->CurveR[i] = OutFloat[0];
+ }
+ else {
+ Data->CurveR[i] = OutFloat[0];
+ Data->CurveG[i] = OutFloat[1];
+ Data->CurveB[i] = OutFloat[2];
+ }
+
+ }
+
+ return Data;
+}
+
+
+// If the target LUT holds only curves, the optimization procedure is to join all those
+// curves together. That only works on curves and does not work on matrices.
+cmsBool OptimizeFloatByJoiningCurves(cmsContext ContextID,
+ _cmsTransformFn* TransformFn,
+ void** UserData,
+ _cmsFreeUserDataFn* FreeUserData,
+ cmsPipeline** Lut,
+ cmsUInt32Number* InputFormat,
+ cmsUInt32Number* OutputFormat,
+ cmsUInt32Number* dwFlags)
+{
+
+ cmsPipeline* Src = *Lut;
+ cmsStage* mpe;
+ CurvesFloatData* Data;
+ cmsUInt32Number nChans;
+
+ // Apply only to floating-point cases
+ if (!T_FLOAT(*InputFormat) || !T_FLOAT(*OutputFormat)) return FALSE;
+
+ // Only on 8-bit
+ if (T_BYTES(*InputFormat) != 4 || T_BYTES(*OutputFormat) != 4) return FALSE;
+
+ // Curves need same channels on input and output (despite extra channels may differ)
+ nChans = T_CHANNELS(*InputFormat);
+ if (nChans != T_CHANNELS(*OutputFormat)) return FALSE;
+
+ // gray and RGB
+ if (nChans != 1 && nChans != 3) return FALSE;
+
+ // Only curves in this LUT?
+ for (mpe = cmsPipelineGetPtrToFirstStage(ContextID, Src);
+ mpe != NULL;
+ mpe = cmsStageNext(ContextID, mpe)) {
+
+ if (cmsStageType(ContextID, mpe) != cmsSigCurveSetElemType) return FALSE;
+ }
+
+ Data = ComputeCompositeCurves(ContextID, nChans, Src);
+
+ *dwFlags |= cmsFLAGS_NOCACHE;
+ *dwFlags &= ~cmsFLAGS_CAN_CHANGE_FORMATTER;
+ *UserData = Data;
+ *FreeUserData = free_aligned;
+
+ // Maybe the curves are linear at the end
+ if (nChans == 1)
+ *TransformFn = (_cmsTransformFn) (KCurveIsLinear(Data) ? FastFloatGrayIdentity : FastEvaluateFloatGrayCurves);
+ else
+ *TransformFn = (_cmsTransformFn) (AllRGBCurvesAreLinear(Data) ? FastFloatRGBIdentity : FastEvaluateFloatRGBCurves);
+
+ return TRUE;
+
+}
+
diff --git a/lcms2mt/plugins/fast_float/src/fast_float_internal.h b/lcms2mt/plugins/fast_float/src/fast_float_internal.h
new file mode 100644
index 00000000..0f153cb8
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/src/fast_float_internal.h
@@ -0,0 +1,249 @@
+//---------------------------------------------------------------------------------
+//
+// Little Color Management System, fast floating point extensions
+// Copyright (c) 1998-2020 Marti Maria Saguer, all rights reserved
+//
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+//---------------------------------------------------------------------------------
+
+#ifndef _FAST_INTERNAL_H
+#define _FAST_INTERNAL_H
+
+#include "lcms2mt_fast_float.h"
+#include <stdint.h>
+
+#define REQUIRED_LCMS_VERSION (2100-2000)
+
+// Unused parameter warning supression
+#define UNUSED_PARAMETER(x) ((void)x)
+
+// The specification for "inline" is section 6.7.4 of the C99 standard (ISO/IEC 9899:1999).
+// unfortunately VisualC++ does not conform that
+#if defined(_MSC_VER) || defined(__BORLANDC__)
+# define cmsINLINE __inline
+#else
+# define cmsINLINE static inline
+#endif
+
+// A fast way to convert from/to 16 <-> 8 bits
+#define FROM_8_TO_16(rgb) (cmsUInt16Number) ((((cmsUInt16Number) (rgb)) << 8)|(rgb))
+#define FROM_16_TO_8(rgb) (cmsUInt8Number) ((((rgb) * 65281 + 8388608) >> 24) & 0xFF)
+
+
+// This macro return words stored as big endian
+#define CHANGE_ENDIAN(w) (cmsUInt16Number) ((cmsUInt16Number) ((w)<<8)|((w)>>8))
+
+// This macro changes the polarity of a word
+#define REVERSE_FLAVOR_16(x) ((cmsUInt16Number)(0xffff-(x)))
+
+// Fixed point
+#define FIXED_TO_INT(x) ((x)>>16)
+#define FIXED_REST_TO_INT(x) ((x)&0xFFFFU)
+
+#define cmsFLAGS_CAN_CHANGE_FORMATTER 0x02000000 // Allow change buffer format
+
+// Utility macros to convert from to 0...1.0 in 15.16 fixed domain to 0..0xffff as integer
+cmsINLINE cmsS15Fixed16Number _cmsToFixedDomain(int a) { return a + ((a + 0x7fff) / 0xffff); }
+cmsINLINE int _cmsFromFixedDomain(cmsS15Fixed16Number a) { return a - ((a + 0x7fff) >> 16); }
+
+// This is the upper part of internal transform structure. Only format specifiers are used
+typedef struct {
+
+ cmsUInt32Number InputFormat, OutputFormat; // Keep formats for further reference
+
+} _xform_head;
+
+
+#define MAX_NODES_IN_CURVE 0x8001
+
+
+// To prevent out of bounds indexing
+cmsINLINE cmsFloat32Number fclamp(cmsFloat32Number v)
+{
+ return v < 0.0f ? 0.0f : (v > 1.0f ? 1.0f : v);
+}
+
+// Fast floor conversion logic.
+cmsINLINE int _cmsQuickFloor(cmsFloat64Number val)
+{
+#ifdef CMS_DONT_USE_FAST_FLOOR
+ return (int)floor(val);
+#else
+#define _lcms_double2fixmagic (68719476736.0 * 1.5)
+
+ union {
+ cmsFloat64Number val;
+ int halves[2];
+ } temp;
+
+ temp.val = val + _lcms_double2fixmagic;
+
+#ifdef CMS_USE_BIG_ENDIAN
+ return temp.halves[1] >> 16;
+#else
+ return temp.halves[0] >> 16;
+#endif
+#endif
+}
+
+// Floor to word, taking care of saturation. This is not critical in terms of performance
+cmsINLINE cmsUInt16Number _cmsSaturateWord(cmsFloat64Number d)
+{
+ d += 0.5;
+
+ if (d <= 0) return 0;
+ if (d >= 65535.0) return 0xffff;
+
+ return (cmsUInt16Number)floor(d);
+}
+
+
+cmsINLINE cmsFloat32Number flerp(const cmsFloat32Number LutTable[], cmsFloat32Number v)
+{
+ cmsFloat32Number y1, y0;
+ cmsFloat32Number rest;
+ int cell0, cell1;
+
+ if (v <= 0.0) {
+ return LutTable[0];
+ }
+ else
+ if (v >= 1.0) {
+ return LutTable[MAX_NODES_IN_CURVE - 1];
+ }
+
+ v *= (MAX_NODES_IN_CURVE - 1);
+
+ cell0 = _cmsQuickFloor(v);
+ cell1 = (int)ceilf(v);
+
+ // Rest is 16 LSB bits
+ rest = v - cell0;
+
+ y0 = LutTable[cell0];
+ y1 = LutTable[cell1];
+
+ return y0 + (y1 - y0) * rest;
+}
+
+
+
+
+// Some secret sauce from lcms
+int _cmsReasonableGridpointsByColorspace(cmsColorSpaceSignature Colorspace, cmsUInt32Number dwFlags);
+
+
+
+// Compute the increments to be used by the transform functions
+void _cmsComputeComponentIncrements(cmsUInt32Number Format,
+ cmsUInt32Number BytesPerPlane,
+ cmsUInt32Number* nChannels,
+ cmsUInt32Number* nAlpha,
+ cmsUInt32Number ComponentStartingOrder[],
+ cmsUInt32Number ComponentPointerIncrements[]);
+
+// 15 bits formatters
+cmsFormatter Formatter_15Bit_Factory(cmsContext ContextID,
+ cmsUInt32Number Type,
+ cmsFormatterDirection Dir,
+ cmsUInt32Number dwFlags);
+
+// Optimizers
+
+// 8 bits on input allows matrix-shaper boost up a little bit
+cmsBool Optimize8MatrixShaper(cmsContext ContextID,
+ _cmsTransformFn* TransformFn,
+ void** UserData,
+ _cmsFreeUserDataFn* FreeUserData,
+ cmsPipeline** Lut,
+ cmsUInt32Number* InputFormat,
+ cmsUInt32Number* OutputFormat,
+ cmsUInt32Number* dwFlags);
+
+cmsBool OptimizeMatrixShaper15(cmsContext ContextID,
+ _cmsTransformFn* TransformFn,
+ void** UserData,
+ _cmsFreeUserDataFn* FreeUserData,
+ cmsPipeline** Lut,
+ cmsUInt32Number* InputFormat,
+ cmsUInt32Number* OutputFormat,
+ cmsUInt32Number* dwFlags);
+
+
+cmsBool Optimize8ByJoiningCurves(cmsContext ContextID,
+ _cmsTransformFn* TransformFn,
+ void** UserData,
+ _cmsFreeUserDataFn* FreeUserData,
+ cmsPipeline** Lut,
+ cmsUInt32Number* InputFormat,
+ cmsUInt32Number* OutputFormat,
+ cmsUInt32Number* dwFlags);
+
+cmsBool OptimizeFloatByJoiningCurves(cmsContext ContextID,
+ _cmsTransformFn* TransformFn,
+ void** UserData,
+ _cmsFreeUserDataFn* FreeUserData,
+ cmsPipeline** Lut,
+ cmsUInt32Number* InputFormat,
+ cmsUInt32Number* OutputFormat,
+ cmsUInt32Number* dwFlags);
+
+cmsBool OptimizeFloatMatrixShaper(cmsContext ContextID,
+ _cmsTransformFn* TransformFn,
+ void** UserData,
+ _cmsFreeUserDataFn* FreeUserData,
+ cmsPipeline** Lut,
+ cmsUInt32Number* InputFormat,
+ cmsUInt32Number* OutputFormat,
+ cmsUInt32Number* dwFlags);
+
+cmsBool Optimize8BitRGBTransform(cmsContext ContextID,
+ _cmsTransformFn* TransformFn,
+ void** UserData,
+ _cmsFreeUserDataFn* FreeDataFn,
+ cmsPipeline** Lut,
+ cmsUInt32Number* InputFormat,
+ cmsUInt32Number* OutputFormat,
+ cmsUInt32Number* dwFlags);
+
+cmsBool Optimize16BitRGBTransform(cmsContext ContextID,
+ _cmsTransformFn* TransformFn,
+ void** UserData,
+ _cmsFreeUserDataFn* FreeDataFn,
+ cmsPipeline** Lut,
+ cmsUInt32Number* InputFormat,
+ cmsUInt32Number* OutputFormat,
+ cmsUInt32Number* dwFlags);
+
+cmsBool OptimizeCLUTRGBTransform(cmsContext ContextID,
+ _cmsTransformFn* TransformFn,
+ void** UserData,
+ _cmsFreeUserDataFn* FreeDataFn,
+ cmsPipeline** Lut,
+ cmsUInt32Number* InputFormat,
+ cmsUInt32Number* OutputFormat,
+ cmsUInt32Number* dwFlags);
+
+cmsBool OptimizeCLUTCMYKTransform(cmsContext ContextID,
+ _cmsTransformFn* TransformFn,
+ void** UserData,
+ _cmsFreeUserDataFn* FreeDataFn,
+ cmsPipeline** Lut,
+ cmsUInt32Number* InputFormat,
+ cmsUInt32Number* OutputFormat,
+ cmsUInt32Number* dwFlags);
+
+#endif
diff --git a/lcms2mt/plugins/fast_float/src/fast_float_matsh.c b/lcms2mt/plugins/fast_float/src/fast_float_matsh.c
new file mode 100644
index 00000000..07396e59
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/src/fast_float_matsh.c
@@ -0,0 +1,323 @@
+//---------------------------------------------------------------------------------
+//
+// Little Color Management System, fast floating point extensions
+// Copyright (c) 1998-2020 Marti Maria Saguer, all rights reserved
+//
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+//---------------------------------------------------------------------------------
+
+// Optimization for matrix-shaper in float
+
+#include "fast_float_internal.h"
+
+
+// This is the private data container used by this optimization
+typedef struct {
+
+
+ cmsFloat32Number Mat[3][3];
+ cmsFloat32Number Off[3];
+
+ cmsFloat32Number Shaper1R[MAX_NODES_IN_CURVE];
+ cmsFloat32Number Shaper1G[MAX_NODES_IN_CURVE];
+ cmsFloat32Number Shaper1B[MAX_NODES_IN_CURVE];
+
+ cmsFloat32Number Shaper2R[MAX_NODES_IN_CURVE];
+ cmsFloat32Number Shaper2G[MAX_NODES_IN_CURVE];
+ cmsFloat32Number Shaper2B[MAX_NODES_IN_CURVE];
+
+ cmsBool UseOff;
+
+ void * real_ptr;
+
+} VXMatShaperFloatData;
+
+
+static
+VXMatShaperFloatData* malloc_aligned(cmsContext ContextID)
+{
+ cmsUInt8Number* real_ptr = (cmsUInt8Number*) _cmsMallocZero(ContextID, sizeof(VXMatShaperFloatData) + 32);
+ cmsUInt8Number* aligned = (cmsUInt8Number*) (((uintptr_t)real_ptr + 16) & ~0xf);
+ VXMatShaperFloatData* p = (VXMatShaperFloatData*) aligned;
+
+ p ->real_ptr = real_ptr;
+ return p;
+}
+
+
+
+// Free the private data container
+static
+void FreeMatShaper(cmsContext ContextID, void* Data)
+{
+ VXMatShaperFloatData* d = (VXMatShaperFloatData*)Data;
+
+ if (d != NULL)
+ _cmsFree(ContextID, d->real_ptr);
+}
+
+
+static
+void FillShaper(cmsContext ContextID, cmsFloat32Number* Table, cmsToneCurve* Curve)
+{
+ int i;
+ cmsFloat32Number R;
+
+ for (i = 0; i < MAX_NODES_IN_CURVE; i++) {
+
+ R = (cmsFloat32Number) i / (cmsFloat32Number) (MAX_NODES_IN_CURVE - 1);
+
+ Table[i] = cmsEvalToneCurveFloat(ContextID, Curve, R);
+ }
+}
+
+
+// Compute the matrix-shaper structure
+static
+VXMatShaperFloatData* SetMatShaper(cmsContext ContextID, cmsToneCurve* Curve1[3], cmsMAT3* Mat, cmsVEC3* Off, cmsToneCurve* Curve2[3])
+{
+ VXMatShaperFloatData* p;
+ int i, j;
+
+ // Allocate a big chuck of memory to store precomputed tables
+ p = malloc_aligned(ContextID);
+ if (p == NULL) return FALSE;
+
+
+ // Precompute tables
+ FillShaper(ContextID, p->Shaper1R, Curve1[0]);
+ FillShaper(ContextID, p->Shaper1G, Curve1[1]);
+ FillShaper(ContextID, p->Shaper1B, Curve1[2]);
+
+ FillShaper(ContextID, p->Shaper2R, Curve2[0]);
+ FillShaper(ContextID, p->Shaper2G, Curve2[1]);
+ FillShaper(ContextID, p->Shaper2B, Curve2[2]);
+
+
+ for (i=0; i < 3; i++) {
+ for (j=0; j < 3; j++) {
+ p->Mat[i][j] = (cmsFloat32Number) Mat->v[i].n[j];
+ }
+ }
+
+
+ for (i = 0; i < 3; i++) {
+
+ if (Off == NULL) {
+
+ p->UseOff = FALSE;
+ p->Off[i] = 0.0;
+ }
+ else {
+ p->UseOff = TRUE;
+ p->Off[i] = (cmsFloat32Number)Off->n[i];
+
+ }
+ }
+
+
+ return p;
+}
+
+
+
+// A fast matrix-shaper evaluator for floating point
+static
+void MatShaperFloat(cmsContext ContextID, struct _cmstransform_struct *CMMcargo,
+ const cmsFloat32Number* Input,
+ cmsFloat32Number* Output,
+ cmsUInt32Number len,
+ cmsUInt32Number Stride)
+{
+ VXMatShaperFloatData* p = (VXMatShaperFloatData*) _cmsGetTransformUserData(CMMcargo);
+ cmsFloat32Number l1, l2, l3;
+ cmsFloat32Number r, g, b;
+ cmsUInt32Number ii;
+ cmsUInt32Number SourceStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number SourceIncrements[cmsMAXCHANNELS];
+ cmsUInt32Number DestStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number DestIncrements[cmsMAXCHANNELS];
+
+ const cmsUInt8Number* rin;
+ const cmsUInt8Number* gin;
+ const cmsUInt8Number* bin;
+
+ cmsUInt8Number* rout;
+ cmsUInt8Number* gout;
+ cmsUInt8Number* bout;
+
+ cmsUInt32Number nchans, nalpha;
+
+ _cmsComputeComponentIncrements(cmsGetTransformInputFormat(ContextID, (cmsHTRANSFORM)CMMcargo), Stride, &nchans, &nalpha, SourceStartingOrder, SourceIncrements);
+ _cmsComputeComponentIncrements(cmsGetTransformOutputFormat(ContextID, (cmsHTRANSFORM)CMMcargo), Stride, &nchans, &nalpha, DestStartingOrder, DestIncrements);
+
+ rin = (const cmsUInt8Number*)Input + SourceStartingOrder[0];
+ gin = (const cmsUInt8Number*)Input + SourceStartingOrder[1];
+ bin = (const cmsUInt8Number*)Input + SourceStartingOrder[2];
+
+ rout = (cmsUInt8Number*)Output + DestStartingOrder[0];
+ gout = (cmsUInt8Number*)Output + DestStartingOrder[1];
+ bout = (cmsUInt8Number*)Output + DestStartingOrder[2];
+
+ for (ii=0; ii < len; ii++) {
+
+ r = flerp(p->Shaper1R, *(cmsFloat32Number*)rin);
+ g = flerp(p->Shaper1G, *(cmsFloat32Number*)gin);
+ b = flerp(p->Shaper1B, *(cmsFloat32Number*)bin);
+
+ l1 = p->Mat[0][0] * r + p->Mat[0][1] * g + p->Mat[0][2] * b ;
+ l2 = p->Mat[1][0] * r + p->Mat[1][1] * g + p->Mat[1][2] * b ;
+ l3 = p->Mat[2][0] * r + p->Mat[2][1] * g + p->Mat[2][2] * b ;
+
+ if (p->UseOff) {
+
+ l1 += p->Off[0];
+ l2 += p->Off[1];
+ l3 += p->Off[2];
+ }
+
+ *(cmsFloat32Number*)rout = flerp(p->Shaper2R, l1);
+ *(cmsFloat32Number*)gout = flerp(p->Shaper2G, l2);
+ *(cmsFloat32Number*)bout = flerp(p->Shaper2B, l3);
+
+ rin += SourceIncrements[0];
+ gin += SourceIncrements[1];
+ bin += SourceIncrements[2];
+
+ rout += DestIncrements[0];
+ gout += DestIncrements[1];
+ bout += DestIncrements[2];
+ }
+
+}
+
+
+
+cmsBool OptimizeFloatMatrixShaper(cmsContext ContextID,
+ _cmsTransformFn* TransformFn,
+ void** UserData,
+ _cmsFreeUserDataFn* FreeUserData,
+ cmsPipeline** Lut,
+ cmsUInt32Number* InputFormat,
+ cmsUInt32Number* OutputFormat,
+ cmsUInt32Number* dwFlags)
+{
+ cmsStage* Curve1, *Curve2;
+ cmsStage* Matrix1, *Matrix2;
+ _cmsStageMatrixData* Data1;
+ _cmsStageMatrixData* Data2;
+ cmsMAT3 res;
+ cmsBool IdentityMat = FALSE;
+ cmsPipeline* Dest, *Src;
+ cmsUInt32Number nChans;
+ cmsFloat64Number factor = 1.0;
+
+
+ // Apply only to floating-point cases
+ if (!T_FLOAT(*InputFormat) || !T_FLOAT(*OutputFormat)) return FALSE;
+
+ // Only works on RGB to RGB and gray to gray
+ if ( !( (T_CHANNELS(*InputFormat) == 3 && T_CHANNELS(*OutputFormat) == 3)) &&
+ !( (T_CHANNELS(*InputFormat) == 1 && T_CHANNELS(*OutputFormat) == 1))) return FALSE;
+
+ // Only works on float
+ if (T_BYTES(*InputFormat) != 4 || T_BYTES(*OutputFormat) != 4) return FALSE;
+
+ // Seems suitable, proceed
+ Src = *Lut;
+
+ // Check for shaper-matrix-matrix-shaper structure, that is what this optimizer stands for
+ if (!cmsPipelineCheckAndRetreiveStages(ContextID, Src, 4,
+ cmsSigCurveSetElemType, cmsSigMatrixElemType, cmsSigMatrixElemType, cmsSigCurveSetElemType,
+ &Curve1, &Matrix1, &Matrix2, &Curve2)) return FALSE;
+
+ nChans = T_CHANNELS(*InputFormat);
+
+ // Get both matrices, which are 3x3
+ Data1 = (_cmsStageMatrixData*) cmsStageData(ContextID, Matrix1);
+ Data2 = (_cmsStageMatrixData*) cmsStageData(ContextID, Matrix2);
+
+ // Input offset should be zero
+ if (Data1 ->Offset != NULL) return FALSE;
+
+ if (cmsStageInputChannels(ContextID, Matrix1) == 1 && cmsStageOutputChannels(ContextID, Matrix2) == 1)
+ {
+ // This is a gray to gray. Just multiply
+ factor = Data1->Double[0]*Data2->Double[0] +
+ Data1->Double[1]*Data2->Double[1] +
+ Data1->Double[2]*Data2->Double[2];
+
+ if (fabs(1 - factor) < (1.0 / 65535.0)) IdentityMat = TRUE;
+ }
+ else
+ {
+ // Multiply both matrices to get the result
+ _cmsMAT3per(ContextID, &res, (cmsMAT3*) Data2 ->Double, (cmsMAT3*) Data1 ->Double);
+
+ // Now the result is in res + Data2 -> Offset. Maybe is a plain identity?
+ IdentityMat = FALSE;
+ if (_cmsMAT3isIdentity(ContextID, &res) && Data2 ->Offset == NULL) {
+
+ // We can get rid of full matrix
+ IdentityMat = TRUE;
+ }
+ }
+
+ // Allocate an empty LUT
+ Dest = cmsPipelineAlloc(ContextID, nChans, nChans);
+ if (!Dest) return FALSE;
+
+ // Assamble the new LUT
+ cmsPipelineInsertStage(ContextID, Dest, cmsAT_BEGIN, cmsStageDup(ContextID, Curve1));
+
+ if (!IdentityMat) {
+
+ if (nChans == 1)
+ cmsPipelineInsertStage(ContextID, Dest, cmsAT_END,
+ cmsStageAllocMatrix(ContextID, 1, 1, (const cmsFloat64Number*) &factor, Data2->Offset));
+ else
+ cmsPipelineInsertStage(ContextID, Dest, cmsAT_END,
+ cmsStageAllocMatrix(ContextID, 3, 3, (const cmsFloat64Number*) &res, Data2 ->Offset));
+ }
+
+
+ cmsPipelineInsertStage(ContextID, Dest, cmsAT_END, cmsStageDup(ContextID, Curve2));
+
+ // If identity on matrix, we can further optimize the curves, so call the join curves routine
+ if (IdentityMat) {
+
+ OptimizeFloatByJoiningCurves(ContextID, TransformFn, UserData, FreeUserData, &Dest, InputFormat, OutputFormat, dwFlags);
+ }
+ else {
+ _cmsStageToneCurvesData* mpeC1 = (_cmsStageToneCurvesData*) cmsStageData(ContextID, Curve1);
+ _cmsStageToneCurvesData* mpeC2 = (_cmsStageToneCurvesData*) cmsStageData(ContextID, Curve2);
+
+ // In this particular optimization, caché does not help as it takes more time to deal with
+ // the cachthat with the pixel handling
+ *dwFlags |= cmsFLAGS_NOCACHE;
+
+ // Setup the optimizarion routines
+ *UserData = SetMatShaper(ContextID, mpeC1 ->TheCurves, &res, (cmsVEC3*) Data2 ->Offset, mpeC2->TheCurves);
+ *FreeUserData = FreeMatShaper;
+
+ *TransformFn = (_cmsTransformFn) MatShaperFloat;
+ }
+
+ *dwFlags &= ~cmsFLAGS_CAN_CHANGE_FORMATTER;
+ cmsPipelineFree(ContextID, Src);
+ *Lut = Dest;
+ return TRUE;
+}
diff --git a/lcms2mt/plugins/fast_float/src/fast_float_separate.c b/lcms2mt/plugins/fast_float/src/fast_float_separate.c
new file mode 100644
index 00000000..c4186a92
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/src/fast_float_separate.c
@@ -0,0 +1,199 @@
+//---------------------------------------------------------------------------------
+//
+// Little Color Management System, fast floating point extensions
+// Copyright (c) 1998-2020 Marti Maria Saguer, all rights reserved
+//
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+//---------------------------------------------------------------------------------
+
+#include "fast_float_internal.h"
+
+// Separable input. It just computes the distance from
+// each component to the next one in bytes. It gives components RGB in this order
+//
+// Encoding Starting Increment DoSwap Swapfirst Extra
+// RGB, 012 333 0 0 0
+// RGBA, 012 444 0 0 1
+// ARGB, 123 444 0 1 1
+// BGR, 210 333 1 0 0
+// BGRA, 210 444 1 1 1
+// ABGR 321 444 1 0 1
+//
+//
+// On planar configurations, the distance is the stride added to any non-negative
+//
+// RGB 0, S, 2*S 111
+// RGBA 0, S, 2*S 111 (fourth plane is safely ignored)
+// ARGB S, 2*S, 3*S 111
+// BGR 2*S, S, 0 111
+// BGRA 2*S, S, 0, 111 (fourth plane is safely ignored)
+// ABGR 3*S, 2*S, S 111
+//
+//----------------------------------------------------------------------------------------
+
+
+// Return the size in bytes of a given formatter
+static
+int trueBytesSize(cmsUInt32Number Format)
+{
+ int fmt_bytes = T_BYTES(Format);
+
+ // For double, the T_BYTES field returns zero
+ if (fmt_bytes == 0)
+ return sizeof(double);
+
+ // Otherwise, it is already correct for all formats
+ return fmt_bytes;
+}
+
+// RGBA -> normal
+// ARGB -> swap first
+// ABGR -> doSwap
+// BGRA -> doSwap swapFirst
+
+// This function computes the distance from each component to the next one in bytes.
+static
+void ComputeIncrementsForChunky(cmsUInt32Number Format,
+ cmsUInt32Number BytesPerPlane,
+ cmsUInt32Number* nChannels,
+ cmsUInt32Number* nAlpha,
+ cmsUInt32Number ComponentStartingOrder[],
+ cmsUInt32Number ComponentPointerIncrements[])
+{
+ int extra = T_EXTRA(Format);
+ int channels = T_CHANNELS(Format);
+ int total_chans = channels + extra;
+ int i;
+ int channelSize = trueBytesSize(Format);
+ int pixelSize = channelSize * total_chans;
+
+ UNUSED_PARAMETER(BytesPerPlane);
+
+ // Setup the counts
+ if (nChannels != NULL)
+ *nChannels = channels;
+
+ if (nAlpha != NULL)
+ *nAlpha = extra;
+
+ // Separation is independent of starting point and only depends on channel size
+ for (i = 0; i < total_chans; i++)
+ ComponentPointerIncrements[i] = pixelSize;
+
+ // Handle do swap
+ for (i = 0; i < total_chans; i++)
+ {
+ if (T_DOSWAP(Format)) {
+ ComponentStartingOrder[i] = total_chans - i - 1;
+ }
+ else {
+ ComponentStartingOrder[i] = i;
+ }
+ }
+
+ // Handle swap first (ROL of positions), example CMYK -> KCMY | 0123 -> 3012
+ if (T_SWAPFIRST(Format)) {
+
+ cmsUInt32Number tmp = ComponentStartingOrder[0];
+ for (i = 0; i < total_chans-1; i++)
+ ComponentStartingOrder[i] = ComponentStartingOrder[i + 1];
+
+ ComponentStartingOrder[total_chans - 1] = tmp;
+ }
+
+ // Handle size
+ if (channelSize > 1)
+ for (i = 0; i < total_chans; i++) {
+ ComponentStartingOrder[i] *= channelSize;
+ }
+}
+
+
+
+// On planar configurations, the distance is the stride added to any non-negative
+static
+void ComputeIncrementsForPlanar(cmsUInt32Number Format,
+ cmsUInt32Number BytesPerPlane,
+ cmsUInt32Number* nChannels,
+ cmsUInt32Number* nAlpha,
+ cmsUInt32Number ComponentStartingOrder[],
+ cmsUInt32Number ComponentPointerIncrements[])
+{
+ int extra = T_EXTRA(Format);
+ int channels = T_CHANNELS(Format);
+ int total_chans = channels + extra;
+ int i;
+ int channelSize = trueBytesSize(Format);
+
+ // Setup the counts
+ if (nChannels != NULL)
+ *nChannels = channels;
+
+ if (nAlpha != NULL)
+ *nAlpha = extra;
+
+ // Separation is independent of starting point and only depends on channel size
+ for (i = 0; i < total_chans; i++)
+ ComponentPointerIncrements[i] = channelSize;
+
+ // Handle do swap
+ for (i = 0; i < total_chans; i++)
+ {
+ if (T_DOSWAP(Format)) {
+ ComponentStartingOrder[i] = total_chans - i - 1;
+ }
+ else {
+ ComponentStartingOrder[i] = i;
+ }
+ }
+
+ // Handle swap first (ROL of positions), example CMYK -> KCMY | 0123 -> 3012
+ if (T_SWAPFIRST(Format)) {
+
+ cmsUInt32Number tmp = ComponentStartingOrder[0];
+ for (i = 0; i < total_chans - 1; i++)
+ ComponentStartingOrder[i] = ComponentStartingOrder[i + 1];
+
+ ComponentStartingOrder[total_chans - 1] = tmp;
+ }
+
+ // Handle size
+ for (i = 0; i < total_chans; i++) {
+ ComponentStartingOrder[i] *= BytesPerPlane;
+ }
+}
+
+
+
+// Dispatcher por chunky and planar RGB
+void _cmsComputeComponentIncrements(cmsUInt32Number Format,
+ cmsUInt32Number BytesPerPlane,
+ cmsUInt32Number* nChannels,
+ cmsUInt32Number* nAlpha,
+ cmsUInt32Number ComponentStartingOrder[],
+ cmsUInt32Number ComponentPointerIncrements[])
+{
+ if (T_PLANAR(Format)) {
+
+ ComputeIncrementsForPlanar(Format, BytesPerPlane, nChannels, nAlpha, ComponentStartingOrder, ComponentPointerIncrements);
+ }
+ else {
+ ComputeIncrementsForChunky(Format, BytesPerPlane, nChannels, nAlpha, ComponentStartingOrder, ComponentPointerIncrements);
+ }
+
+}
+
+
diff --git a/lcms2mt/plugins/fast_float/src/fast_float_sup.c b/lcms2mt/plugins/fast_float/src/fast_float_sup.c
new file mode 100644
index 00000000..9a375a4b
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/src/fast_float_sup.c
@@ -0,0 +1,90 @@
+//---------------------------------------------------------------------------------
+//
+// Little Color Management System, fast floating point extensions
+// Copyright (c) 1998-2020 Marti Maria Saguer, all rights reserved
+//
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+//---------------------------------------------------------------------------------
+
+
+#include "fast_float_internal.h"
+
+
+// This is the main dispatcher
+static
+cmsBool Floating_Point_Transforms_Dispatcher(cmsContext ContextID,
+ _cmsTransformFn* TransformFn,
+ void** UserData,
+ _cmsFreeUserDataFn* FreeUserData,
+ cmsPipeline** Lut,
+ cmsUInt32Number* InputFormat,
+ cmsUInt32Number* OutputFormat,
+ cmsUInt32Number* dwFlags)
+{
+
+ // Try to optimize as a set of curves plus a matrix plus a set of curves
+ if (OptimizeMatrixShaper15(ContextID, TransformFn, UserData, FreeUserData, Lut, InputFormat, OutputFormat, dwFlags)) return TRUE;
+
+ // Try to optimize by joining curves
+ if (Optimize8ByJoiningCurves(ContextID, TransformFn, UserData, FreeUserData, Lut, InputFormat, OutputFormat, dwFlags)) return TRUE;
+
+ // Try to optimize as a set of curves plus a matrix plus a set of curves
+ if (Optimize8MatrixShaper(ContextID, TransformFn, UserData, FreeUserData, Lut, InputFormat, OutputFormat, dwFlags)) return TRUE;
+
+ // Try to optimize by joining curves
+ if (OptimizeFloatByJoiningCurves(ContextID, TransformFn, UserData, FreeUserData, Lut, InputFormat, OutputFormat, dwFlags)) return TRUE;
+
+ // Try to optimize as a set of curves plus a matrix plus a set of curves
+ if (OptimizeFloatMatrixShaper(ContextID, TransformFn, UserData, FreeUserData, Lut, InputFormat, OutputFormat, dwFlags)) return TRUE;
+
+ // Try to optimize using prelinearization plus tetrahedral
+ if (Optimize8BitRGBTransform(ContextID, TransformFn, UserData, FreeUserData, Lut, InputFormat, OutputFormat, dwFlags)) return TRUE;
+
+ // Try to optimize using prelinearization plus tetrahedral
+ if (Optimize16BitRGBTransform(ContextID, TransformFn, UserData, FreeUserData, Lut, InputFormat, OutputFormat, dwFlags)) return TRUE;
+
+ // Try to optimize using prelinearization plus tetrahedral
+ if (OptimizeCLUTRGBTransform(ContextID, TransformFn, UserData, FreeUserData, Lut, InputFormat, OutputFormat, dwFlags)) return TRUE;
+
+ // Try to optimize using prelinearization plus tetrahedral
+ if (OptimizeCLUTCMYKTransform(ContextID, TransformFn, UserData, FreeUserData, Lut, InputFormat, OutputFormat, dwFlags)) return TRUE;
+
+
+ // Cannot optimize, use lcms normal process
+ return FALSE;
+}
+
+// The Plug-in entry points
+static cmsPluginFormatters PluginFastFloat = {
+ { cmsPluginMagicNumber, REQUIRED_LCMS_VERSION, cmsPluginFormattersSig, NULL },
+
+ Formatter_15Bit_Factory
+};
+
+static cmsPluginTransform PluginList = {
+
+ { cmsPluginMagicNumber, REQUIRED_LCMS_VERSION, cmsPluginTransformSig, (cmsPluginBase *) &PluginFastFloat },
+
+ Floating_Point_Transforms_Dispatcher
+};
+
+// This is the main plug-in installer.
+// Using a function to retrieve the plug-in entry point allows us to execute initialization data.
+void* cmsFastFloatExtensions(void)
+{
+ return (void*)&PluginList;
+}
+
diff --git a/lcms2mt/plugins/fast_float/src/fast_float_tethra.c b/lcms2mt/plugins/fast_float/src/fast_float_tethra.c
new file mode 100644
index 00000000..6bb688f7
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/src/fast_float_tethra.c
@@ -0,0 +1,292 @@
+//---------------------------------------------------------------------------------
+//
+// Little Color Management System, fast floating point extensions
+// Copyright (c) 1998-2020 Marti Maria Saguer, all rights reserved
+//
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+//---------------------------------------------------------------------------------
+
+#include "fast_float_internal.h"
+
+// Optimization for floating point tetrahedral interpolation
+typedef struct {
+
+ const cmsInterpParams* p; // Tetrahedrical interpolation parameters. This is a not-owned pointer.
+
+} FloatCLUTData;
+
+// Precomputes tables for 8-bit on input devicelink.
+static
+FloatCLUTData* FloatCLUTAlloc(cmsContext ContextID, const cmsInterpParams* p)
+{
+ FloatCLUTData* fd;
+
+ fd = (FloatCLUTData*) _cmsMallocZero(ContextID, sizeof(FloatCLUTData));
+ if (fd == NULL) return NULL;
+
+ fd ->p = p;
+ return fd;
+}
+
+
+// Sampler implemented by another LUT. This is a clean way to precalculate the devicelink 3D CLUT for
+// almost any transform. We use floating point precision and then convert from floating point to 16 bits.
+static
+int XFormSampler(cmsContext ContextID, CMSREGISTER const cmsFloat32Number In[], CMSREGISTER cmsFloat32Number Out[], CMSREGISTER void* Cargo)
+{
+ // Evaluate in 16 bits
+ cmsPipelineEvalFloat(ContextID, In, Out, (cmsPipeline*) Cargo);
+
+ // Always succeed
+ return TRUE;
+}
+
+
+
+// A optimized interpolation for 8-bit input.
+#define DENS(i,j,k) (LutTable[(i)+(j)+(k)+OutChan])
+
+static
+void FloatCLUTEval(cmsContext ContextID,
+ struct _cmstransform_struct *CMMcargo,
+ const cmsFloat32Number* Input,
+ cmsFloat32Number* Output,
+ cmsUInt32Number len,
+ cmsUInt32Number Stride)
+{
+
+ cmsFloat32Number r, g, b;
+ cmsFloat32Number px, py, pz;
+ int x0, y0, z0;
+ int X0, Y0, Z0, X1, Y1, Z1;
+ cmsFloat32Number rx, ry, rz;
+ cmsFloat32Number c0, c1 = 0, c2 = 0, c3 = 0;
+
+ cmsUInt32Number OutChan;
+ FloatCLUTData* p8 = (FloatCLUTData*) _cmsGetTransformUserData(CMMcargo);
+
+ const cmsInterpParams* p = p8 ->p;
+ cmsUInt32Number TotalOut = p -> nOutputs;
+ const cmsFloat32Number* LutTable = (const cmsFloat32Number*)p->Table;
+ cmsUInt32Number ii;
+ const cmsUInt8Number* rin;
+ const cmsUInt8Number* gin;
+ const cmsUInt8Number* bin;
+
+ cmsUInt8Number* out[cmsMAXCHANNELS];
+ cmsUInt32Number SourceStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number SourceIncrements[cmsMAXCHANNELS];
+ cmsUInt32Number DestStartingOrder[cmsMAXCHANNELS];
+ cmsUInt32Number DestIncrements[cmsMAXCHANNELS];
+
+ cmsUInt32Number InputFormat = cmsGetTransformInputFormat(ContextID, (cmsHTRANSFORM) CMMcargo);
+ cmsUInt32Number OutputFormat = cmsGetTransformOutputFormat(ContextID, (cmsHTRANSFORM) CMMcargo);
+
+ cmsUInt32Number nchans, nalpha;
+
+ _cmsComputeComponentIncrements(InputFormat, Stride, &nchans, &nalpha, SourceStartingOrder, SourceIncrements);
+ _cmsComputeComponentIncrements(OutputFormat, Stride, &nchans, &nalpha, DestStartingOrder, DestIncrements);
+
+ // SeparateRGB(InputFormat, Stride, SourceStartingOrder, SourceIncrements);
+ // SeparateRGB(OutputFormat, Stride, DestStartingOrder, DestIncrements);
+
+ rin = (const cmsUInt8Number*)Input + SourceStartingOrder[0];
+ gin = (const cmsUInt8Number*)Input + SourceStartingOrder[1];
+ bin = (const cmsUInt8Number*)Input + SourceStartingOrder[2];
+
+ for (ii=0; ii < TotalOut; ii++)
+ out[ii] = (cmsUInt8Number*) Output + DestStartingOrder[ii];
+
+ for (ii=0; ii < len; ii++) {
+
+ r = fclamp(*(cmsFloat32Number*)rin);
+ g = fclamp(*(cmsFloat32Number*)gin);
+ b = fclamp(*(cmsFloat32Number*)bin);
+
+ rin += SourceIncrements[0];
+ gin += SourceIncrements[1];
+ bin += SourceIncrements[2];
+
+ px = r * p->Domain[0];
+ py = g * p->Domain[1];
+ pz = b * p->Domain[2];
+
+
+ x0 = (int)_cmsQuickFloor(px); rx = (px - (cmsFloat32Number)x0);
+ y0 = (int)_cmsQuickFloor(py); ry = (py - (cmsFloat32Number)y0);
+ z0 = (int)_cmsQuickFloor(pz); rz = (pz - (cmsFloat32Number)z0);
+
+ X0 = p->opta[2] * x0;
+ X1 = X0 + (r >= 1.0 ? 0 : p->opta[2]);
+
+ Y0 = p->opta[1] * y0;
+ Y1 = Y0 + (g >= 1.0 ? 0 : p->opta[1]);
+
+ Z0 = p->opta[0] * z0;
+ Z1 = Z0 + (b >= 1.0 ? 0 : p->opta[0]);
+
+ for (OutChan = 0; OutChan < TotalOut; OutChan++) {
+
+ // These are the 6 Tetrahedral
+
+ c0 = DENS(X0, Y0, Z0);
+
+ if (rx >= ry && ry >= rz) {
+
+ c1 = DENS(X1, Y0, Z0) - c0;
+ c2 = DENS(X1, Y1, Z0) - DENS(X1, Y0, Z0);
+ c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);
+
+ }
+ else
+ if (rx >= rz && rz >= ry) {
+
+ c1 = DENS(X1, Y0, Z0) - c0;
+ c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);
+ c3 = DENS(X1, Y0, Z1) - DENS(X1, Y0, Z0);
+
+ }
+ else
+ if (rz >= rx && rx >= ry) {
+
+ c1 = DENS(X1, Y0, Z1) - DENS(X0, Y0, Z1);
+ c2 = DENS(X1, Y1, Z1) - DENS(X1, Y0, Z1);
+ c3 = DENS(X0, Y0, Z1) - c0;
+
+ }
+ else
+ if (ry >= rx && rx >= rz) {
+
+ c1 = DENS(X1, Y1, Z0) - DENS(X0, Y1, Z0);
+ c2 = DENS(X0, Y1, Z0) - c0;
+ c3 = DENS(X1, Y1, Z1) - DENS(X1, Y1, Z0);
+
+ }
+ else
+ if (ry >= rz && rz >= rx) {
+
+ c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);
+ c2 = DENS(X0, Y1, Z0) - c0;
+ c3 = DENS(X0, Y1, Z1) - DENS(X0, Y1, Z0);
+
+ }
+ else
+ if (rz >= ry && ry >= rx) {
+
+ c1 = DENS(X1, Y1, Z1) - DENS(X0, Y1, Z1);
+ c2 = DENS(X0, Y1, Z1) - DENS(X0, Y0, Z1);
+ c3 = DENS(X0, Y0, Z1) - c0;
+
+ }
+ else {
+ c1 = c2 = c3 = 0;
+ }
+
+ *(cmsFloat32Number*) (out[OutChan]) = c0 + c1 * rx + c2 * ry + c3 * rz;
+
+ out[OutChan] += DestIncrements[OutChan];
+
+ }
+
+
+ }
+}
+
+#undef DENS
+
+
+
+// --------------------------------------------------------------------------------------------------------------
+
+cmsBool OptimizeCLUTRGBTransform(cmsContext ContextID,
+ _cmsTransformFn* TransformFn,
+ void** UserData,
+ _cmsFreeUserDataFn* FreeDataFn,
+ cmsPipeline** Lut,
+ cmsUInt32Number* InputFormat,
+ cmsUInt32Number* OutputFormat,
+ cmsUInt32Number* dwFlags)
+{
+ cmsPipeline* OriginalLut;
+ int nGridPoints;
+ cmsPipeline* OptimizedLUT = NULL;
+ cmsStage* OptimizedCLUTmpe;
+ cmsColorSpaceSignature OutputColorSpace;
+ cmsStage* mpe;
+ FloatCLUTData* p8;
+ _cmsStageCLutData* data;
+
+ // For empty transforms, do nothing
+ if (*Lut == NULL) return FALSE;
+
+ // This is a loosy optimization! does not apply in floating-point cases
+ if (!T_FLOAT(*InputFormat) || !T_FLOAT(*OutputFormat)) return FALSE;
+
+ // Only on 8-bit
+ if (T_BYTES(*InputFormat) != 4 || T_BYTES(*OutputFormat) != 4) return FALSE;
+
+ // Only on RGB
+ if (T_COLORSPACE(*InputFormat) != PT_RGB) return FALSE;
+ if (T_COLORSPACE(*OutputFormat) != PT_RGB) return FALSE;
+
+ OriginalLut = *Lut;
+
+ // Named color pipelines cannot be optimized either
+ for (mpe = cmsPipelineGetPtrToFirstStage(ContextID, OriginalLut);
+ mpe != NULL;
+ mpe = cmsStageNext(ContextID, mpe)) {
+ if (cmsStageType(ContextID, mpe) == cmsSigNamedColorElemType) return FALSE;
+ }
+
+ OutputColorSpace = _cmsICCcolorSpace(ContextID, T_COLORSPACE(*OutputFormat));
+ nGridPoints = _cmsReasonableGridpointsByColorspace(cmsSigRgbData, *dwFlags);
+
+ // Create the result LUT
+ OptimizedLUT = cmsPipelineAlloc(ContextID, 3, cmsPipelineOutputChannels(ContextID, OriginalLut));
+ if (OptimizedLUT == NULL) goto Error;
+
+
+ // Allocate the CLUT for result
+ OptimizedCLUTmpe = cmsStageAllocCLutFloat(ContextID, nGridPoints, 3, cmsPipelineOutputChannels(ContextID, OriginalLut), NULL);
+
+ // Add the CLUT to the destination LUT
+ cmsPipelineInsertStage(ContextID, OptimizedLUT, cmsAT_BEGIN, OptimizedCLUTmpe);
+
+ // Resample the LUT
+ if (!cmsStageSampleCLutFloat(ContextID, OptimizedCLUTmpe, XFormSampler, (void*)OriginalLut, 0)) goto Error;
+
+ // Set the evaluator, copy parameters
+ data = (_cmsStageCLutData*) cmsStageData(ContextID, OptimizedCLUTmpe);
+
+ p8 = FloatCLUTAlloc(ContextID, data ->Params);
+ if (p8 == NULL) return FALSE;
+
+ // And return the obtained LUT
+ cmsPipelineFree(ContextID, OriginalLut);
+
+ *Lut = OptimizedLUT;
+ *TransformFn = (_cmsTransformFn) FloatCLUTEval;
+ *UserData = p8;
+ *FreeDataFn = _cmsFree;
+ *dwFlags &= ~cmsFLAGS_CAN_CHANGE_FORMATTER;
+ return TRUE;
+
+Error:
+
+ if (OptimizedLUT != NULL) cmsPipelineFree(ContextID, OptimizedLUT);
+
+ return FALSE;
+}
diff --git a/lcms2mt/plugins/fast_float/testbed/Makefile.am b/lcms2mt/plugins/fast_float/testbed/Makefile.am
new file mode 100644
index 00000000..9bd2412a
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/testbed/Makefile.am
@@ -0,0 +1,22 @@
+#
+# Makefile for building fast_float_testbed
+#
+
+# Don't require all the GNU mandated files
+AUTOMAKE_OPTIONS = 1.7 foreign
+
+INCLUDES = -I$(builddir)/../include -I$(srcdir)/../include -I$(srcdir)/../src \
+ -I$(top_builddir)/include
+
+check_PROGRAMS = fast_float_testbed
+
+fast_float_testbed_LDADD = $(top_builddir)/src/liblcms2mt.la $(srcdir)/../src/liblcms2mt_fast_float.la
+fast_float_testbed_LDFLAGS = @LDFLAGS@
+fast_float_testbed_SOURCES = fast_float_testbed.c
+
+EXTRA_DIST = test0.icc test1.icc test2.icc test3.icc test5.icc
+
+check:
+ ./fast_float_testbed
+
+
diff --git a/lcms2mt/plugins/fast_float/testbed/fast_float_testbed.c b/lcms2mt/plugins/fast_float/testbed/fast_float_testbed.c
new file mode 100644
index 00000000..650454bc
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/testbed/fast_float_testbed.c
@@ -0,0 +1,1782 @@
+//---------------------------------------------------------------------------------
+//
+// Little Color Management System, fast floating point extensions
+// Copyright (c) 1998-2020 Marti Maria Saguer, all rights reserved
+//
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+//---------------------------------------------------------------------------------
+
+#include "fast_float_internal.h"
+
+#include <stdlib.h>
+#include <memory.h>
+
+
+// Some pixel representations
+typedef struct { cmsUInt8Number r, g, b; } Scanline_rgb8bits;
+typedef struct { cmsUInt8Number r, g, b, a; } Scanline_rgba8bits;
+typedef struct { cmsUInt16Number r, g, b; } Scanline_rgb16bits;
+typedef struct { cmsUInt16Number r, g, b, a; } Scanline_rgba16bits;
+typedef struct { cmsUInt16Number r, g, b; } Scanline_rgb15bits;
+typedef struct { cmsUInt16Number r, g, b, a; } Scanline_rgba15bits;
+typedef struct { cmsUInt16Number r, g, b, a; } Scanline_cmyk15bits;
+typedef struct { cmsFloat32Number r, g, b; } Scanline_rgbFloat;
+typedef struct { cmsFloat32Number r, g, b, a; } Scanline_rgbaFloat;
+
+// 15 bit mode. <=> 8 bits mode
+#define FROM_8_TO_15(x8) (cmsUInt16Number) ((((cmsUInt64Number)x8 << 15)) / 0xFF)
+#define FROM_15_TO_8(x15) (cmsUInt8Number) (((cmsUInt64Number) x15 * 0xFF + 0x4000) >> 15)
+
+
+// Floating point acuracy for tests
+#define EPSILON_FLOAT_TESTS 0.005
+
+
+// The callback function used by cmsSetLogErrorHandler()
+static
+void FatalErrorQuit(cmsContext ContextID, cmsUInt32Number ErrorCode, const char *Text)
+{
+ UNUSED_PARAMETER(ContextID);
+ UNUSED_PARAMETER(ErrorCode);
+
+ printf("** Fatal error: %s\n", Text);
+ exit(1);
+}
+
+// Rise an error and exit
+static
+void Fail(const char* frm, ...)
+{
+ char ReasonToFailBuffer[1024];
+ va_list args;
+
+ va_start(args, frm);
+ vsprintf(ReasonToFailBuffer, frm, args);
+ FatalErrorQuit(0, 0, ReasonToFailBuffer);
+
+ // unreacheable va_end(args);
+}
+
+
+// Creates a fake profile that only has a curve. Used in several places
+static
+cmsHPROFILE CreateCurves(cmsContext ContextID)
+{
+ cmsToneCurve* Gamma = cmsBuildGamma(ContextID, 1.1);
+ cmsToneCurve* Transfer[3];
+ cmsHPROFILE h;
+
+ Transfer[0] = Transfer[1] = Transfer[2] = Gamma;
+ h = cmsCreateLinearizationDeviceLink(ContextID, cmsSigRgbData, Transfer);
+
+ cmsFreeToneCurve(ContextID, Gamma);
+
+ return h;
+}
+
+
+// Check for a single 15 bit Photoshop-like formatter
+static
+void CheckSingleFormatter15(cmsContext id, cmsUInt32Number Type, const char* Text)
+{
+ cmsUInt16Number Values[cmsMAXCHANNELS];
+ cmsUInt8Number Buffer[1024];
+ cmsFormatter f, b;
+ cmsInt32Number i, j, nChannels, bytes;
+ _xform_head info;
+
+ UNUSED_PARAMETER(id);
+
+ memset(&info, 0, sizeof(info));
+ info.OutputFormat = info.InputFormat = Type;
+
+ // Get functions to go forth and back
+ f = Formatter_15Bit_Factory(id, Type, cmsFormatterInput, CMS_PACK_FLAGS_16BITS);
+ b = Formatter_15Bit_Factory(id, Type, cmsFormatterOutput, CMS_PACK_FLAGS_16BITS);
+
+ if (f.Fmt16 == NULL || b.Fmt16 == NULL) {
+
+ Fail("no formatter for %s", Text);
+ return;
+ }
+
+ nChannels = T_CHANNELS(Type);
+ bytes = T_BYTES(Type);
+
+ for (j = 0; j < 5; j++) {
+
+ for (i = 0; i < nChannels; i++) {
+
+ Values[i] = (cmsUInt16Number)(i + j) << 1;
+ }
+
+ b.Fmt16(id, (struct _cmstransform_struct*) &info, Values, Buffer, 1);
+ memset(Values, 0, sizeof(Values));
+ f.Fmt16(id, (struct _cmstransform_struct*) &info, Values, Buffer, 1);
+
+ for (i = 0; i < nChannels; i++) {
+
+ if (Values[i] != ((i + j) << 1)) {
+
+ Fail("%s failed", Text);
+ return;
+ }
+ }
+ }
+}
+
+#define C(a) CheckSingleFormatter15(0, a, #a)
+
+// Check for all 15 bits formatters
+static
+void CheckFormatters15(void)
+{
+ C(TYPE_GRAY_15);
+ C(TYPE_GRAY_15_REV);
+ C(TYPE_GRAY_15_SE);
+ C(TYPE_GRAYA_15);
+ C(TYPE_GRAYA_15_SE);
+ C(TYPE_GRAYA_15_PLANAR);
+ C(TYPE_RGB_15);
+ C(TYPE_RGB_15_PLANAR);
+ C(TYPE_RGB_15_SE);
+ C(TYPE_BGR_15);
+ C(TYPE_BGR_15_PLANAR);
+ C(TYPE_BGR_15_SE);
+ C(TYPE_RGBA_15);
+ C(TYPE_RGBA_15_PLANAR);
+ C(TYPE_RGBA_15_SE);
+ C(TYPE_ARGB_15);
+ C(TYPE_ABGR_15);
+ C(TYPE_ABGR_15_PLANAR);
+ C(TYPE_ABGR_15_SE);
+ C(TYPE_BGRA_15);
+ C(TYPE_BGRA_15_SE);
+ C(TYPE_YMC_15),
+ C(TYPE_CMY_15);
+ C(TYPE_CMY_15_PLANAR);
+ C(TYPE_CMY_15_SE);
+ C(TYPE_CMYK_15);
+ C(TYPE_CMYK_15_REV);
+ C(TYPE_CMYK_15_PLANAR);
+ C(TYPE_CMYK_15_SE);
+ C(TYPE_KYMC_15);
+ C(TYPE_KYMC_15_SE);
+ C(TYPE_KCMY_15);
+ C(TYPE_KCMY_15_REV);
+ C(TYPE_KCMY_15_SE);
+}
+#undef C
+
+
+static
+cmsInt32Number checkSingleComputeIncrements(cmsUInt32Number Format, cmsUInt32Number planeStride, cmsUInt32Number ExpectedChannels, cmsUInt32Number ExpectedAlpha, ...)
+{
+ cmsUInt32Number nChannels, nAlpha, nTotal, i, rc = 0 ;
+ cmsUInt32Number ComponentStartingOrder[cmsMAXCHANNELS], ComponentPointerIncrements[cmsMAXCHANNELS];
+ va_list args;
+
+
+ va_start(args, ExpectedAlpha);
+
+ _cmsComputeComponentIncrements(Format, planeStride, &nChannels, &nAlpha, ComponentStartingOrder, ComponentPointerIncrements);
+
+ if (nChannels != ExpectedChannels)
+ return 0;
+
+ if (nAlpha != ExpectedAlpha)
+ return 0;
+
+ nTotal = nAlpha + nChannels;
+
+
+
+ for (i = 0; i < nTotal; i++)
+ {
+ cmsUInt32Number so = va_arg(args, cmsUInt32Number);
+ if (so != ComponentStartingOrder[i])
+ goto Error;
+ }
+
+ for (i = 0; i < nTotal; i++)
+ {
+ cmsUInt32Number so = va_arg(args, cmsUInt32Number);
+ if (so != ComponentPointerIncrements[i])
+ goto Error;
+ }
+
+ // Success
+ rc = 1;
+
+Error:
+ va_end(args);
+
+ return rc;
+}
+
+#define CHECK(frm, plane, chans, alpha, ...) if (!checkSingleComputeIncrements(frm, plane, chans, alpha, __VA_ARGS__)) { printf("Format failed!\n"); return 0; }
+
+
+
+// Validate the compute increments function
+cmsInt32Number CheckComputeIncrements(void)
+{
+ CHECK(TYPE_GRAY_8, 0, 1, 0, /**/ 0, /**/ 1);
+ CHECK(TYPE_GRAYA_8, 0, 1, 1, /**/ 0, 1, /**/ 2, 2);
+ CHECK(TYPE_AGRAY_8, 0, 1, 1, /**/ 1, 0, /**/ 2, 2);
+ CHECK(TYPE_GRAY_16, 0, 1, 0, /**/ 0, /**/ 2);
+ CHECK(TYPE_GRAYA_16, 0, 1, 1, /**/ 0, 2, /**/ 4, 4);
+ CHECK(TYPE_AGRAY_16, 0, 1, 1, /**/ 2, 0, /**/ 4, 4);
+
+ CHECK(TYPE_GRAY_FLT, 0, 1, 0, /**/ 0, /**/ 4);
+ CHECK(TYPE_GRAYA_FLT, 0, 1, 1, /**/ 0, 4, /**/ 8, 8);
+ CHECK(TYPE_AGRAY_FLT, 0, 1, 1, /**/ 4, 0, /**/ 8, 8);
+
+ CHECK(TYPE_GRAY_DBL, 0, 1, 0, /**/ 0, /**/ 8);
+ CHECK(TYPE_AGRAY_DBL, 0, 1, 1, /**/ 8, 0, /**/ 16, 16);
+
+ CHECK(TYPE_RGB_8, 0, 3, 0, /**/ 0, 1, 2, /**/ 3, 3, 3);
+ CHECK(TYPE_RGBA_8, 0, 3, 1, /**/ 0, 1, 2, 3, /**/ 4, 4, 4, 4);
+ CHECK(TYPE_ARGB_8, 0, 3, 1, /**/ 1, 2, 3, 0, /**/ 4, 4, 4, 4);
+
+ CHECK(TYPE_RGB_16, 0, 3, 0, /**/ 0, 2, 4, /**/ 6, 6, 6);
+ CHECK(TYPE_RGBA_16, 0, 3, 1, /**/ 0, 2, 4, 6, /**/ 8, 8, 8, 8);
+ CHECK(TYPE_ARGB_16, 0, 3, 1, /**/ 2, 4, 6, 0, /**/ 8, 8, 8, 8);
+
+ CHECK(TYPE_RGB_FLT, 0, 3, 0, /**/ 0, 4, 8, /**/ 12, 12, 12);
+ CHECK(TYPE_RGBA_FLT, 0, 3, 1, /**/ 0, 4, 8, 12, /**/ 16, 16, 16, 16);
+ CHECK(TYPE_ARGB_FLT, 0, 3, 1, /**/ 4, 8, 12, 0, /**/ 16, 16, 16, 16);
+
+ CHECK(TYPE_BGR_8, 0, 3, 0, /**/ 2, 1, 0, /**/ 3, 3, 3);
+ CHECK(TYPE_BGRA_8, 0, 3, 1, /**/ 2, 1, 0, 3, /**/ 4, 4, 4, 4);
+ CHECK(TYPE_ABGR_8, 0, 3, 1, /**/ 3, 2, 1, 0, /**/ 4, 4, 4, 4);
+
+ CHECK(TYPE_BGR_16, 0, 3, 0, /**/ 4, 2, 0, /**/ 6, 6, 6);
+ CHECK(TYPE_BGRA_16, 0, 3, 1, /**/ 4, 2, 0, 6, /**/ 8, 8, 8, 8);
+ CHECK(TYPE_ABGR_16, 0, 3, 1, /**/ 6, 4, 2, 0, /**/ 8, 8, 8, 8);
+
+ CHECK(TYPE_BGR_FLT, 0, 3, 0, /**/ 8, 4, 0, /**/ 12, 12, 12);
+ CHECK(TYPE_BGRA_FLT, 0, 3, 1, /**/ 8, 4, 0, 12, /**/ 16, 16, 16, 16);
+ CHECK(TYPE_ABGR_FLT, 0, 3, 1, /**/ 12, 8, 4, 0, /**/ 16, 16, 16, 16);
+
+
+ CHECK(TYPE_CMYK_8, 0, 4, 0, /**/ 0, 1, 2, 3, /**/ 4, 4, 4, 4);
+ CHECK(TYPE_CMYKA_8, 0, 4, 1, /**/ 0, 1, 2, 3, 4, /**/ 5, 5, 5, 5, 5);
+ CHECK(TYPE_ACMYK_8, 0, 4, 1, /**/ 1, 2, 3, 4, 0, /**/ 5, 5, 5, 5, 5);
+
+ CHECK(TYPE_KYMC_8, 0, 4, 0, /**/ 3, 2, 1, 0, /**/ 4, 4, 4, 4);
+ CHECK(TYPE_KYMCA_8, 0, 4, 1, /**/ 3, 2, 1, 0, 4, /**/ 5, 5, 5, 5, 5);
+ CHECK(TYPE_AKYMC_8, 0, 4, 1, /**/ 4, 3, 2, 1, 0, /**/ 5, 5, 5, 5, 5);
+
+ CHECK(TYPE_KCMY_8, 0, 4, 0, /**/ 1, 2, 3, 0, /**/ 4, 4, 4, 4);
+
+ CHECK(TYPE_CMYK_16, 0, 4, 0, /**/ 0, 2, 4, 6, /**/ 8, 8, 8, 8);
+ CHECK(TYPE_CMYKA_16, 0, 4, 1, /**/ 0, 2, 4, 6, 8, /**/ 10, 10, 10, 10, 10);
+ CHECK(TYPE_ACMYK_16, 0, 4, 1, /**/ 2, 4, 6, 8, 0, /**/ 10, 10, 10, 10, 10);
+
+ CHECK(TYPE_KYMC_16, 0, 4, 0, /**/ 6, 4, 2, 0, /**/ 8, 8, 8, 8);
+ CHECK(TYPE_KYMCA_16, 0, 4, 1, /**/ 6, 4, 2, 0, 8, /**/ 10, 10, 10, 10, 10);
+ CHECK(TYPE_AKYMC_16, 0, 4, 1, /**/ 8, 6, 4, 2, 0, /**/ 10, 10, 10, 10, 10);
+
+ CHECK(TYPE_KCMY_16, 0, 4, 0, /**/ 2, 4, 6, 0, /**/ 8, 8, 8, 8);
+
+ // Planar
+
+ CHECK(TYPE_GRAYA_8_PLANAR, 100, 1, 1, /**/ 0, 100, /**/ 1, 1);
+ CHECK(TYPE_AGRAY_8_PLANAR, 100, 1, 1, /**/ 100, 0, /**/ 1, 1);
+
+ CHECK(TYPE_GRAYA_16_PLANAR, 100, 1, 1, /**/ 0, 100, /**/ 2, 2);
+ CHECK(TYPE_AGRAY_16_PLANAR, 100, 1, 1, /**/ 100, 0, /**/ 2, 2);
+
+ CHECK(TYPE_GRAYA_FLT_PLANAR, 100, 1, 1, /**/ 0, 100, /**/ 4, 4);
+ CHECK(TYPE_AGRAY_FLT_PLANAR, 100, 1, 1, /**/ 100, 0, /**/ 4, 4);
+
+ CHECK(TYPE_GRAYA_DBL_PLANAR, 100, 1, 1, /**/ 0, 100, /**/ 8, 8);
+ CHECK(TYPE_AGRAY_DBL_PLANAR, 100, 1, 1, /**/ 100, 0, /**/ 8, 8);
+
+ CHECK(TYPE_RGB_8_PLANAR, 100, 3, 0, /**/ 0, 100, 200, /**/ 1, 1, 1);
+ CHECK(TYPE_RGBA_8_PLANAR, 100, 3, 1, /**/ 0, 100, 200, 300, /**/ 1, 1, 1, 1);
+ CHECK(TYPE_ARGB_8_PLANAR, 100, 3, 1, /**/ 100, 200, 300, 0, /**/ 1, 1, 1, 1);
+
+ CHECK(TYPE_BGR_8_PLANAR, 100, 3, 0, /**/ 200, 100, 0, /**/ 1, 1, 1);
+ CHECK(TYPE_BGRA_8_PLANAR, 100, 3, 1, /**/ 200, 100, 0, 300, /**/ 1, 1, 1, 1);
+ CHECK(TYPE_ABGR_8_PLANAR, 100, 3, 1, /**/ 300, 200, 100, 0, /**/ 1, 1, 1, 1);
+
+ CHECK(TYPE_RGB_16_PLANAR, 100, 3, 0, /**/ 0, 100, 200, /**/ 2, 2, 2);
+ CHECK(TYPE_RGBA_16_PLANAR, 100, 3, 1, /**/ 0, 100, 200, 300, /**/ 2, 2, 2, 2);
+ CHECK(TYPE_ARGB_16_PLANAR, 100, 3, 1, /**/ 100, 200, 300, 0, /**/ 2, 2, 2, 2);
+
+ CHECK(TYPE_BGR_16_PLANAR, 100, 3, 0, /**/ 200, 100, 0, /**/ 2, 2, 2);
+ CHECK(TYPE_BGRA_16_PLANAR, 100, 3, 1, /**/ 200, 100, 0, 300, /**/ 2, 2, 2, 2);
+ CHECK(TYPE_ABGR_16_PLANAR, 100, 3, 1, /**/ 300, 200, 100, 0, /**/ 2, 2, 2, 2);
+
+ return 1;
+}
+
+
+
+// Check 15 bit mode accuracy
+static
+cmsBool Valid15(cmsUInt16Number a, cmsUInt8Number b)
+{
+ return abs(FROM_15_TO_8(a) - b) <= 2;
+}
+
+// Check the test macros itselves
+static
+void Check15bitMacros(void)
+{
+ int i;
+
+ printf("Checking 15 bit <=> 8 bit macros...");
+
+ for (i = 0; i < 256; i++)
+ {
+ cmsUInt16Number n = FROM_8_TO_15(i);
+ cmsUInt8Number m = FROM_15_TO_8(n);
+
+ if (m != i)
+ Fail("Failed on %d (->%d->%d)", i, n, m);
+ }
+ printf("ok\n");
+}
+
+// Do an in-depth test by checking all RGB cube of 8 bits, going from profilein to profileout.
+// Results should be same except for 2 contone levels allowed for roundoff. Note 15 bits is more
+// precise than 8 bits and this is a source of discrepancies. Cache is disabled
+static
+void TryAllValues15(cmsContext ContextID, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut, cmsInt32Number Intent)
+{
+ Scanline_rgb8bits* buffer8in;
+ Scanline_rgb15bits* buffer15in;
+ Scanline_rgb8bits* buffer8out;
+ Scanline_rgb15bits* buffer15out;
+ int r, g, b, j;
+ cmsUInt32Number npixels = 256 * 256 * 256; // All RGB cube in 8 bits
+
+ cmsHTRANSFORM xform15 = cmsCreateTransform(ContextID, hlcmsProfileIn, TYPE_RGB_15, hlcmsProfileOut, TYPE_RGB_15, Intent, cmsFLAGS_NOCACHE);
+ cmsHTRANSFORM xform8 = cmsCreateTransform(ContextID, hlcmsProfileIn, TYPE_RGB_8, hlcmsProfileOut, TYPE_RGB_8, Intent, cmsFLAGS_NOCACHE); // Transforms already created
+
+ cmsCloseProfile(ContextID, hlcmsProfileIn);
+ cmsCloseProfile(ContextID, hlcmsProfileOut);
+
+ if (xform15 == NULL || xform8 == NULL) {
+
+ Fail("NULL transforms on check for 15 bit conversions");
+ }
+
+ // Since this is just a test, I will not check memory allocation...
+ buffer8in = (Scanline_rgb8bits*)malloc(npixels * sizeof(Scanline_rgb8bits));
+ buffer15in = (Scanline_rgb15bits*)malloc(npixels * sizeof(Scanline_rgb15bits));
+ buffer8out = (Scanline_rgb8bits*)malloc(npixels * sizeof(Scanline_rgb8bits));
+ buffer15out = (Scanline_rgb15bits*)malloc(npixels * sizeof(Scanline_rgb15bits));
+
+ // Fill input values for 8 and 15 bits
+ j = 0;
+ for (r = 0; r < 256; r++)
+ for (g = 0; g < 256; g++)
+ for (b = 0; b < 256; b++) {
+
+ buffer8in[j].r = (cmsUInt8Number)r;
+ buffer8in[j].g = (cmsUInt8Number)g;
+ buffer8in[j].b = (cmsUInt8Number)b;
+
+ buffer15in[j].r = FROM_8_TO_15(r);
+ buffer15in[j].g = FROM_8_TO_15(g);
+ buffer15in[j].b = FROM_8_TO_15(b);
+
+ j++;
+ }
+
+ cmsDoTransform(ContextID, xform15, buffer15in, buffer15out, npixels);
+ cmsDoTransform(ContextID, xform8, buffer8in, buffer8out, npixels);
+
+ j = 0;
+ for (r = 0; r < 256; r++)
+ for (g = 0; g < 256; g++)
+ for (b = 0; b < 256; b++) {
+
+ // Check the results
+ if (!Valid15(buffer15out[j].r, buffer8out[j].r) ||
+ !Valid15(buffer15out[j].g, buffer8out[j].g) ||
+ !Valid15(buffer15out[j].b, buffer8out[j].b))
+ Fail("Conversion failed at (%d %d %d) != (%d %d %d)", buffer8out[j].r, buffer8out[j].g, buffer8out[j].b,
+ FROM_15_TO_8(buffer15out[j].r), FROM_15_TO_8(buffer15out[j].g), FROM_15_TO_8(buffer15out[j].b));
+
+ j++;
+ }
+
+ free(buffer8in); free(buffer15in);
+ free(buffer8out); free(buffer15out);
+ cmsDeleteTransform(ContextID, xform15);
+ cmsDeleteTransform(ContextID, xform8);
+}
+
+// Convert some known values
+static
+void Check15bitsConversions(cmsContext ContextID)
+{
+ Check15bitMacros();
+
+ printf("Checking accuracy of 15 bits on CLUT...");
+ TryAllValues15(ContextID, cmsOpenProfileFromFile(ContextID, "test5.icc", "r"), cmsOpenProfileFromFile(ContextID, "test3.icc", "r"), INTENT_PERCEPTUAL);
+ printf("Ok\n");
+
+ printf("Checking accuracy of 15 bits on same profile ...");
+ TryAllValues15(ContextID, cmsOpenProfileFromFile(ContextID, "test0.icc", "r"), cmsOpenProfileFromFile(ContextID, "test0.icc", "r"), INTENT_PERCEPTUAL);
+ printf("Ok\n");
+
+ printf("Checking accuracy of 15 bits on Matrix...");
+ TryAllValues15(ContextID, cmsOpenProfileFromFile(ContextID, "test5.icc", "r"), cmsOpenProfileFromFile(ContextID, "test0.icc", "r"), INTENT_PERCEPTUAL);
+ printf("Ok\n");
+
+ printf("All 15 bits tests passed OK\n\n");
+}
+
+// Next test checks results of optimized 16 bits versus raw 16 bits.
+static
+void TryAllValues16bits(cmsContext Raw, cmsContext Plugin, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut, cmsInt32Number Intent)
+{
+ Scanline_rgba16bits* bufferIn;
+ Scanline_rgba16bits* bufferRawOut;
+ Scanline_rgba16bits* bufferPluginOut;
+ int r, g, b;
+
+ int j;
+ cmsUInt32Number npixels = 256 * 256 * 256;
+
+ cmsHTRANSFORM xformRaw = cmsCreateTransform(Raw, hlcmsProfileIn, TYPE_RGBA_16, hlcmsProfileOut, TYPE_RGBA_16, Intent, cmsFLAGS_NOCACHE| cmsFLAGS_COPY_ALPHA);
+ cmsHTRANSFORM xformPlugin = cmsCreateTransform(Plugin, hlcmsProfileIn, TYPE_RGBA_16, hlcmsProfileOut, TYPE_RGBA_16, Intent, cmsFLAGS_NOCACHE| cmsFLAGS_COPY_ALPHA);
+
+ cmsCloseProfile(Raw, hlcmsProfileIn);
+ cmsCloseProfile(Raw, hlcmsProfileOut);
+
+ if (xformRaw == NULL || xformPlugin == NULL) {
+
+ Fail("NULL transforms on check float conversions");
+ }
+
+ // Again, no checking on mem alloc because this is just a test
+ bufferIn = (Scanline_rgba16bits*)malloc(npixels * sizeof(Scanline_rgba16bits));
+ bufferRawOut = (Scanline_rgba16bits*)malloc(npixels * sizeof(Scanline_rgba16bits));
+ bufferPluginOut = (Scanline_rgba16bits*)malloc(npixels * sizeof(Scanline_rgba16bits));
+
+ // Same input to both transforms
+ j = 0;
+ for (r = 0; r < 256; r++)
+ for (g = 0; g < 256; g++)
+ for (b = 0; b < 256; b++) {
+
+ bufferIn[j].r = FROM_8_TO_16(0xf8);
+ bufferIn[j].g = FROM_8_TO_16(0xf8);
+ bufferIn[j].b = FROM_8_TO_16(0xf8);
+ bufferIn[j].a = 0xffff;
+
+ j++;
+ }
+
+ // Different transforms, different output buffers
+ cmsDoTransform(Raw, xformRaw, bufferIn, bufferRawOut, npixels);
+ cmsDoTransform(Plugin, xformPlugin, bufferIn, bufferPluginOut, npixels);
+
+#if 1
+ // Lets compare results
+ j = 0;
+ for (r = 0; r < 256; r++)
+ for (g = 0; g < 256; g++)
+ for (b = 0; b < 256; b++) {
+
+ if (bufferRawOut[j].r != bufferPluginOut[j].r ||
+ bufferRawOut[j].g != bufferPluginOut[j].g ||
+ bufferRawOut[j].b != bufferPluginOut[j].b ||
+ bufferRawOut[j].a != bufferPluginOut[j].a)
+ Fail(
+ "Conversion failed at [%x %x %x %x] (%x %x %x %x) != (%x %x %x %x)",
+ bufferIn[j].r, bufferIn[j].g, bufferIn[j].b, bufferIn[j].a,
+ bufferRawOut[j].r, bufferRawOut[j].g, bufferRawOut[j].b, bufferRawOut[j].a,
+ bufferPluginOut[j].r, bufferPluginOut[j].g, bufferPluginOut[j].b, bufferPluginOut[j].a);
+
+ j++;
+ }
+#endif
+
+ free(bufferIn); free(bufferRawOut);
+ free(bufferPluginOut);
+
+ cmsDeleteTransform(Raw, xformRaw);
+ cmsDeleteTransform(Plugin, xformPlugin);
+}
+
+static
+void CheckAccuracy16Bits(cmsContext Raw, cmsContext Plugin)
+{
+ // CLUT should be as 16 bits or better
+ printf("Checking accuracy of 16 bits CLUT...");
+ TryAllValues16bits(Raw, Plugin, cmsOpenProfileFromFile(Raw, "test5.icc", "r"), cmsOpenProfileFromFile(Raw, "test3.icc", "r"), INTENT_PERCEPTUAL);
+ printf("All 16 bits tests passed OK\n\n");
+}
+
+// --------------------------------------------------------------------------------------------------
+// A C C U R A C Y C H E C K S
+// --------------------------------------------------------------------------------------------------
+
+
+// Check result accuracy
+static
+cmsBool ValidFloat(cmsFloat32Number a, cmsFloat32Number b)
+{
+ return fabsf(a-b) < EPSILON_FLOAT_TESTS;
+}
+
+// Do an in-depth test by checking all RGB cube of 8 bits, going from profilein to profileout.
+// Values with and without optimization are checked (different contexts, one with the plugin and another without)
+// Results should be same except for EPSILON_FLOAT_TESTS allowed for accuracy/speed tradeoff. Cache is disabled
+static
+void TryAllValuesFloat(cmsContext Raw, cmsContext Plugin, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut, cmsInt32Number Intent)
+{
+ Scanline_rgbFloat* bufferIn;
+ Scanline_rgbFloat* bufferRawOut;
+ Scanline_rgbFloat* bufferPluginOut;
+ int r, g, b;
+
+ int j;
+ cmsUInt32Number npixels = 256 * 256 * 256;
+
+ cmsHTRANSFORM xformRaw = cmsCreateTransform(Raw, hlcmsProfileIn, TYPE_RGB_FLT, hlcmsProfileOut, TYPE_RGB_FLT, Intent, cmsFLAGS_NOCACHE);
+ cmsHTRANSFORM xformPlugin = cmsCreateTransform(Plugin, hlcmsProfileIn, TYPE_RGB_FLT, hlcmsProfileOut, TYPE_RGB_FLT, Intent, cmsFLAGS_NOCACHE);
+
+ cmsCloseProfile(Raw, hlcmsProfileIn);
+ cmsCloseProfile(Raw, hlcmsProfileOut);
+
+ if (xformRaw == NULL || xformPlugin == NULL) {
+
+ Fail("NULL transforms on check float conversions");
+ }
+
+ // Again, no checking on mem alloc because this is just a test
+ bufferIn = (Scanline_rgbFloat*)malloc(npixels * sizeof(Scanline_rgbFloat));
+ bufferRawOut = (Scanline_rgbFloat*)malloc(npixels * sizeof(Scanline_rgbFloat));
+ bufferPluginOut = (Scanline_rgbFloat*)malloc(npixels * sizeof(Scanline_rgbFloat));
+
+ // Same input to both transforms
+ j = 0;
+ for (r = 0; r < 256; r++)
+ for (g = 0; g < 256; g++)
+ for (b = 0; b < 256; b++) {
+
+ bufferIn[j].r = (cmsFloat32Number)r / 255.0f;
+ bufferIn[j].g = (cmsFloat32Number)g / 255.0f;
+ bufferIn[j].b = (cmsFloat32Number)b / 255.0f;
+
+ j++;
+ }
+
+ // Different transforms, different output buffers
+ cmsDoTransform(Raw, xformRaw, bufferIn, bufferRawOut, npixels);
+ cmsDoTransform(Plugin, xformPlugin, bufferIn, bufferPluginOut, npixels);
+
+ // Lets compare results
+ j = 0;
+ for (r = 0; r < 256; r++)
+ for (g = 0; g < 256; g++)
+ for (b = 0; b < 256; b++) {
+
+ if (!ValidFloat(bufferRawOut[j].r, bufferPluginOut[j].r) ||
+ !ValidFloat(bufferRawOut[j].g, bufferPluginOut[j].g) ||
+ !ValidFloat(bufferRawOut[j].b, bufferPluginOut[j].b))
+ Fail("Conversion failed at (%f %f %f) != (%f %f %f)", bufferRawOut[j].r, bufferRawOut[j].g, bufferRawOut[j].b,
+ bufferPluginOut[j].r, bufferPluginOut[j].g, bufferPluginOut[j].b);
+
+ j++;
+ }
+
+ free(bufferIn); free(bufferRawOut);
+ free(bufferPluginOut);
+
+ cmsDeleteTransform(Raw, xformRaw);
+ cmsDeleteTransform(Plugin, xformPlugin);
+}
+
+static
+void TryAllValuesFloatAlpha(cmsContext Raw, cmsContext Plugin, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut, cmsInt32Number Intent)
+{
+ Scanline_rgbaFloat* bufferIn;
+ Scanline_rgbaFloat* bufferRawOut;
+ Scanline_rgbaFloat* bufferPluginOut;
+ int r, g, b;
+
+ int j;
+ cmsUInt32Number npixels = 256 * 256 * 256;
+
+ cmsHTRANSFORM xformRaw = cmsCreateTransform(Raw, hlcmsProfileIn, TYPE_RGBA_FLT, hlcmsProfileOut, TYPE_RGBA_FLT, Intent, cmsFLAGS_NOCACHE);
+ cmsHTRANSFORM xformPlugin = cmsCreateTransform(Plugin, hlcmsProfileIn, TYPE_RGBA_FLT, hlcmsProfileOut, TYPE_RGBA_FLT, Intent, cmsFLAGS_NOCACHE);
+
+ cmsCloseProfile(Raw, hlcmsProfileIn);
+ cmsCloseProfile(Plugin, hlcmsProfileOut);
+
+ if (xformRaw == NULL || xformPlugin == NULL) {
+
+ Fail("NULL transforms on check float conversions");
+ }
+
+ // Again, no checking on mem alloc because this is just a test
+ bufferIn = (Scanline_rgbaFloat*)malloc(npixels * sizeof(Scanline_rgbaFloat));
+ bufferRawOut = (Scanline_rgbaFloat*)malloc(npixels * sizeof(Scanline_rgbaFloat));
+ bufferPluginOut = (Scanline_rgbaFloat*)malloc(npixels * sizeof(Scanline_rgbaFloat));
+
+ // Same input to both transforms
+ j = 0;
+ for (r = 0; r < 256; r++)
+ for (g = 0; g < 256; g++)
+ for (b = 0; b < 256; b++) {
+
+ bufferIn[j].r = (cmsFloat32Number)r / 255.0f;
+ bufferIn[j].g = (cmsFloat32Number)g / 255.0f;
+ bufferIn[j].b = (cmsFloat32Number)b / 255.0f;
+ bufferIn[j].a = (cmsFloat32Number) 1.0f;
+
+ j++;
+ }
+
+ // Different transforms, different output buffers
+ cmsDoTransform(Raw, xformRaw, bufferIn, bufferRawOut, npixels);
+ cmsDoTransform(Plugin, xformPlugin, bufferIn, bufferPluginOut, npixels);
+
+#if 1
+ // Lets compare results
+ j = 0;
+ for (r = 0; r < 256; r++)
+ for (g = 0; g < 256; g++)
+ for (b = 0; b < 256; b++) {
+
+ if (!ValidFloat(bufferRawOut[j].r, bufferPluginOut[j].r) ||
+ !ValidFloat(bufferRawOut[j].g, bufferPluginOut[j].g) ||
+ !ValidFloat(bufferRawOut[j].b, bufferPluginOut[j].b) ||
+ !ValidFloat(bufferRawOut[j].a, bufferPluginOut[j].a))
+ Fail("Conversion failed at (%f %f %f %f) != (%f %f %f %f)", bufferRawOut[j].r, bufferRawOut[j].g, bufferRawOut[j].b, bufferRawOut[j].a,
+ bufferPluginOut[j].r, bufferPluginOut[j].g, bufferPluginOut[j].b, bufferPluginOut[j].a);
+
+ j++;
+ }
+#endif
+
+ free(bufferIn); free(bufferRawOut);
+ free(bufferPluginOut);
+
+ cmsDeleteTransform(Raw, xformRaw);
+ cmsDeleteTransform(Plugin, xformPlugin);
+}
+
+
+
+// Next test checks results of optimized floating point versus 16 bits. That is, converting the float to 16 bits, operating
+// in 16 bits and back to float. Results again should be in range of epsilon
+static
+cmsBool Valid16Float(cmsUInt16Number a, cmsFloat32Number b)
+{
+ return fabs(((cmsFloat32Number)a / (cmsFloat32Number) 0xFFFF) - b) < EPSILON_FLOAT_TESTS;
+}
+
+// Do an in-depth test by checking all RGB cube of 8 bits, going from profilein to profileout. 16 bits temporary is used as reference
+static
+void TryAllValuesFloatVs16(cmsContext Raw, cmsContext Plugin, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut, cmsInt32Number Intent)
+{
+ Scanline_rgbFloat* bufferIn;
+ Scanline_rgb16bits* bufferIn16;
+
+ Scanline_rgbFloat* bufferFloatOut;
+ Scanline_rgb16bits* buffer16Out;
+ int r, g, b;
+
+ int j;
+ cmsUInt32Number npixels = 256 * 256 * 256;
+
+ cmsHTRANSFORM xformRaw = cmsCreateTransform(Raw, hlcmsProfileIn, TYPE_RGB_16, hlcmsProfileOut, TYPE_RGB_16, Intent, cmsFLAGS_NOCACHE);
+ cmsHTRANSFORM xformPlugin = cmsCreateTransform(Plugin, hlcmsProfileIn, TYPE_RGB_FLT, hlcmsProfileOut, TYPE_RGB_FLT, Intent, cmsFLAGS_NOCACHE);
+
+ cmsCloseProfile(Raw, hlcmsProfileIn);
+ cmsCloseProfile(Raw, hlcmsProfileOut);
+
+ if (xformRaw == NULL || xformPlugin == NULL) {
+
+ Fail("NULL transforms on check float vs 16 conversions");
+ }
+
+ // Again, no checking on mem alloc because this is just a test
+ bufferIn = (Scanline_rgbFloat*)malloc(npixels * sizeof(Scanline_rgbFloat));
+ bufferIn16 = (Scanline_rgb16bits*)malloc(npixels * sizeof(Scanline_rgb16bits));
+ bufferFloatOut = (Scanline_rgbFloat*)malloc(npixels * sizeof(Scanline_rgbFloat));
+ buffer16Out = (Scanline_rgb16bits*)malloc(npixels * sizeof(Scanline_rgb16bits));
+
+
+ // Fill two equivalent input buffers
+ j = 0;
+ for (r = 0; r < 256; r++)
+ for (g = 0; g < 256; g++)
+ for (b = 0; b < 256; b++) {
+
+ bufferIn[j].r = (cmsFloat32Number)r / 255.0f;
+ bufferIn[j].g = (cmsFloat32Number)g / 255.0f;
+ bufferIn[j].b = (cmsFloat32Number)b / 255.0f;
+
+ bufferIn16[j].r = FROM_8_TO_16(r);
+ bufferIn16[j].g = FROM_8_TO_16(g);
+ bufferIn16[j].b = FROM_8_TO_16(b);
+
+ j++;
+ }
+
+ // Convert
+ cmsDoTransform(Raw, xformRaw, bufferIn16, buffer16Out, npixels);
+ cmsDoTransform(Plugin, xformPlugin, bufferIn, bufferFloatOut, npixels);
+
+
+ j = 0;
+ for (r = 0; r < 256; r++)
+ for (g = 0; g < 256; g++)
+ for (b = 0; b < 256; b++) {
+
+ // Check for same values
+ if (!Valid16Float(buffer16Out[j].r, bufferFloatOut[j].r) ||
+ !Valid16Float(buffer16Out[j].g, bufferFloatOut[j].g) ||
+ !Valid16Float(buffer16Out[j].b, bufferFloatOut[j].b))
+ Fail("Conversion failed at (%f %f %f) != (%f %f %f)", buffer16Out[j].r / 65535.0, buffer16Out[j].g / 65535.0, buffer16Out[j].b / 65535.0,
+ bufferFloatOut[j].r, bufferFloatOut[j].g, bufferFloatOut[j].b);
+
+ j++;
+ }
+
+ free(bufferIn16); free(buffer16Out);
+ free(bufferIn); free(bufferFloatOut);
+ cmsDeleteTransform(Raw, xformRaw);
+ cmsDeleteTransform(Plugin, xformPlugin);
+}
+
+
+// Check change format feature
+static
+void CheckChangeFormat(cmsContext ContextID)
+{
+ cmsHPROFILE hsRGB, hLab;
+ cmsHTRANSFORM xform, xform2;
+ cmsUInt8Number rgb8[3] = { 10, 120, 40 };
+ cmsUInt16Number rgb16[3] = { 10* 257, 120*257, 40*257 };
+ cmsUInt16Number lab16_1[3], lab16_2[3];
+
+ printf("Checking change format feature...");
+
+ hsRGB = cmsCreate_sRGBProfile(ContextID);
+ hLab = cmsCreateLab4Profile(ContextID, NULL);
+
+ xform = cmsCreateTransform(ContextID, hsRGB, TYPE_RGB_16, hLab, TYPE_Lab_16, INTENT_PERCEPTUAL, 0);
+
+ cmsCloseProfile(ContextID, hsRGB);
+ cmsCloseProfile(ContextID, hLab);
+
+ cmsDoTransform(ContextID, xform, rgb16, lab16_1, 1);
+
+ xform2 = cmsCloneTransformChangingFormats(ContextID, xform, TYPE_RGB_8, TYPE_Lab_16);
+
+ cmsDoTransform(ContextID, xform2, rgb8, lab16_2, 1);
+ cmsDeleteTransform(ContextID, xform);
+ cmsDeleteTransform(ContextID, xform2);
+
+ if (memcmp(lab16_1, lab16_2, sizeof(lab16_1)) != 0)
+ Fail("Change format failed!");
+
+ printf("Ok\n");
+
+}
+
+static
+cmsBool ValidInt(cmsUInt16Number a, cmsUInt16Number b)
+{
+ return abs(a - b) <= 32;
+}
+
+static
+void CheckLab2Roundtrip(cmsContext ContextID)
+{
+ cmsHPROFILE hsRGB, hLab;
+ cmsHTRANSFORM xform, xform2;
+ cmsInt8Number* lab;
+ cmsInt32Number Mb, j;
+ cmsInt32Number r, g, b;
+ Scanline_rgb8bits* In;
+ Scanline_rgb8bits* Out;
+
+ printf("Checking lab2 roundtrip...");
+
+ hsRGB = cmsCreate_sRGBProfile(ContextID);
+ hLab = cmsCreateLab2Profile(ContextID, NULL);
+
+
+ xform = cmsCreateTransform(ContextID, hsRGB, TYPE_RGB_8, hLab, TYPE_Lab_8, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_NOOPTIMIZE|cmsFLAGS_BLACKPOINTCOMPENSATION);
+ xform2 = cmsCreateTransform(ContextID, hLab, TYPE_Lab_8, hsRGB, TYPE_RGB_8, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_NOOPTIMIZE | cmsFLAGS_BLACKPOINTCOMPENSATION);
+
+ cmsCloseProfile(ContextID, hsRGB);
+ cmsCloseProfile(ContextID, hLab);
+
+
+ Mb = 256 * 256 * 256 * sizeof(Scanline_rgb8bits);
+ In = (Scanline_rgb8bits*)malloc(Mb);
+ Out = (Scanline_rgb8bits*)malloc(Mb);
+ lab = (cmsInt8Number*)malloc(256 * 256 * 256 * 3 * sizeof(cmsInt8Number));
+
+ j = 0;
+ for (r = 0; r < 256; r++)
+ for (g = 0; g < 256; g++)
+ for (b = 0; b < 256; b++)
+ {
+
+ In[j].r = (cmsUInt8Number)r;
+ In[j].g = (cmsUInt8Number)g;
+ In[j].b = (cmsUInt8Number)b;
+ j++;
+ }
+
+
+ cmsDoTransform(ContextID, xform, In, lab, 256 * 256 * 256);
+ cmsDoTransform(ContextID, xform2, lab, Out, 256 * 256 * 256);
+
+ cmsDeleteTransform(ContextID, xform);
+ cmsDeleteTransform(ContextID, xform2);
+
+
+ j = 0;
+ for (r = 0; r < 256; r++)
+ for (g = 0; g < 256; g++)
+ for (b = 0; b < 256; b++) {
+
+ // Check for same values
+ if (!ValidInt(In[j].r, Out[j].r) ||
+ !ValidInt(In[j].g, Out[j].g) ||
+ !ValidInt(In[j].b, Out[j].b))
+ Fail("Conversion failed at (%d %d %d) != (%d %d %d)", In[j].r, In[j].g, In[j].b,
+ Out[j].r, Out[j].g, Out[j].b);
+
+ j++;
+ }
+
+
+ free(In);
+ free(Out);
+ free(lab);
+ printf("Ok\n");
+
+}
+
+// Convert some known values
+static
+void CheckConversionFloat(cmsContext Raw, cmsContext Plugin)
+{
+ printf("Crash test...");
+ TryAllValuesFloatAlpha(Raw, Plugin, cmsOpenProfileFromFile(Raw, "test5.icc", "r"), cmsOpenProfileFromFile(Raw, "test0.icc", "r"), INTENT_PERCEPTUAL);
+ printf("Ok\n");
+
+ printf("Crash (II) test...");
+ TryAllValuesFloatAlpha(Raw, Plugin, cmsOpenProfileFromFile(Raw, "test0.icc", "r"), cmsOpenProfileFromFile(Raw, "test0.icc", "r"), INTENT_PERCEPTUAL);
+ printf("Ok\n");
+
+ // Matrix-shaper should be accurate
+ printf("Checking accuracy on Matrix-shaper...");
+ TryAllValuesFloat(Raw, Plugin, cmsOpenProfileFromFile(Raw, "test5.icc", "r"), cmsOpenProfileFromFile(Raw, "test0.icc", "r"), INTENT_PERCEPTUAL);
+ printf("Ok\n");
+
+ // CLUT should be as 16 bits or better
+ printf("Checking accuracy of CLUT...");
+ TryAllValuesFloatVs16(Raw, Plugin, cmsOpenProfileFromFile(Raw, "test5.icc", "r"), cmsOpenProfileFromFile(Raw, "test3.icc", "r"), INTENT_PERCEPTUAL);
+ printf("Ok\n");
+
+ // Same profile should give same values (we test both methods)
+ printf("Checking accuracy on same profile ...");
+ TryAllValuesFloatVs16(Raw, Plugin, cmsOpenProfileFromFile(Raw, "test0.icc", "r"), cmsOpenProfileFromFile(Raw, "test0.icc", "r"), INTENT_PERCEPTUAL);
+ TryAllValuesFloat(Raw, Plugin, cmsOpenProfileFromFile(Raw, "test0.icc", "r"), cmsOpenProfileFromFile(Raw, "test0.icc", "r"), INTENT_PERCEPTUAL);
+ printf("Ok\n");
+}
+
+
+
+// --------------------------------------------------------------------------------------------------
+// P E R F O R M A N C E C H E C K S
+// --------------------------------------------------------------------------------------------------
+
+
+static
+cmsFloat64Number MPixSec(cmsFloat64Number diff)
+{
+ cmsFloat64Number seconds = (cmsFloat64Number)diff / (cmsFloat64Number)CLOCKS_PER_SEC;
+ return (256.0 * 256.0 * 256.0) / (1024.0*1024.0*seconds);
+}
+
+typedef cmsFloat64Number(*perf_fn)(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut);
+
+
+static
+void PerformanceHeader(void)
+{
+ printf(" MPixel/sec. MByte/sec.\n");
+}
+
+static
+cmsFloat64Number Performance(const char* Title, perf_fn fn, cmsContext ct, const char* inICC, const char* outICC, size_t sz, cmsFloat64Number prev)
+{
+ cmsHPROFILE hlcmsProfileIn;
+ cmsHPROFILE hlcmsProfileOut;
+
+ if (inICC == NULL)
+ hlcmsProfileIn = CreateCurves(ct);
+ else
+ hlcmsProfileIn = cmsOpenProfileFromFile(ct, inICC, "r");
+
+ if (outICC == NULL)
+ hlcmsProfileOut = CreateCurves(ct);
+ else
+ hlcmsProfileOut = cmsOpenProfileFromFile(ct, outICC, "r");
+
+
+ cmsFloat64Number n = fn(ct, hlcmsProfileIn, hlcmsProfileOut);
+
+ printf("%-30s: ", Title); fflush(stdout);
+ printf("%-12.2f %-12.2f", n, n * sz);
+
+ if (prev > 0.0) {
+
+ cmsFloat64Number imp = n / prev;
+ if (imp > 1)
+ printf(" (x %-2.1f)", imp);
+ }
+
+ printf("\n"); fflush(stdout);
+ return n;
+}
+
+
+static
+void ComparativeCt(cmsContext ct1, cmsContext ct2, const char* Title, perf_fn fn1, perf_fn fn2, const char* inICC, const char* outICC)
+{
+ cmsHPROFILE hlcmsProfileIn;
+ cmsHPROFILE hlcmsProfileOut;
+
+ if (inICC == NULL)
+ hlcmsProfileIn = CreateCurves(ct1);
+ else
+ hlcmsProfileIn = cmsOpenProfileFromFile(ct1, inICC, "r");
+
+ if (outICC == NULL)
+ hlcmsProfileOut = CreateCurves(ct1);
+ else
+ hlcmsProfileOut = cmsOpenProfileFromFile(ct1, outICC, "r");
+
+
+ cmsFloat64Number n1 = fn1(ct1, hlcmsProfileIn, hlcmsProfileOut);
+
+ if (inICC == NULL)
+ hlcmsProfileIn = CreateCurves(ct2);
+ else
+ hlcmsProfileIn = cmsOpenProfileFromFile(ct2, inICC, "r");
+
+ if (outICC == NULL)
+ hlcmsProfileOut = CreateCurves(ct2);
+ else
+ hlcmsProfileOut = cmsOpenProfileFromFile(ct2, outICC, "r");
+
+ cmsFloat64Number n2 = fn2(ct2, hlcmsProfileIn, hlcmsProfileOut);
+
+
+ printf("%-30s: ", Title); fflush(stdout);
+ printf("%-12.2f %-12.2f\n", n1, n2);
+}
+
+static
+void Comparative(cmsContext Raw, cmsContext Plugin, const char* Title, perf_fn fn1, perf_fn fn2, const char* inICC, const char* outICC)
+{
+ ComparativeCt(Raw, Plugin, Title, fn1, fn2, inICC, outICC);
+}
+
+// The worst case is used, no cache and all rgb combinations
+static
+cmsFloat64Number SpeedTest8bitsRGB(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
+{
+ cmsInt32Number r, g, b, j;
+ clock_t atime;
+ cmsFloat64Number diff;
+ cmsHTRANSFORM hlcmsxform;
+ Scanline_rgb8bits *In;
+ cmsUInt32Number Mb;
+
+ if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
+ Fail("Unable to open profiles");
+
+ hlcmsxform = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_RGB_8, hlcmsProfileOut, TYPE_RGB_8, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
+ cmsCloseProfile(ct, hlcmsProfileIn);
+ cmsCloseProfile(ct, hlcmsProfileOut);
+
+ Mb = 256 * 256 * 256 * sizeof(Scanline_rgb8bits);
+ In = (Scanline_rgb8bits*)malloc(Mb);
+
+ j = 0;
+ for (r = 0; r < 256; r++)
+ for (g = 0; g < 256; g++)
+ for (b = 0; b < 256; b++) {
+
+ In[j].r = (cmsUInt8Number)r;
+ In[j].g = (cmsUInt8Number)g;
+ In[j].b = (cmsUInt8Number)b;
+
+ j++;
+ }
+
+ atime = clock();
+
+ cmsDoTransform(ct, hlcmsxform, In, In, 256 * 256 * 256);
+
+ diff = clock() - atime;
+ free(In);
+
+ cmsDeleteTransform(ct, hlcmsxform);
+
+ return MPixSec(diff);
+}
+
+static
+cmsFloat64Number SpeedTest8bitsRGBA(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
+{
+ cmsInt32Number r, g, b, j;
+ clock_t atime;
+ cmsFloat64Number diff;
+ cmsHTRANSFORM hlcmsxform;
+ Scanline_rgba8bits *In;
+ cmsUInt32Number Mb;
+
+ if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
+ Fail("Unable to open profiles");
+
+ hlcmsxform = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_RGBA_8, hlcmsProfileOut, TYPE_RGBA_8, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
+ cmsCloseProfile(ct, hlcmsProfileIn);
+ cmsCloseProfile(ct, hlcmsProfileOut);
+
+ Mb = 256 * 256 * 256 * sizeof(Scanline_rgba8bits);
+ In = (Scanline_rgba8bits*)malloc(Mb);
+
+ j = 0;
+ for (r = 0; r < 256; r++)
+ for (g = 0; g < 256; g++)
+ for (b = 0; b < 256; b++) {
+
+ In[j].r = (cmsUInt8Number)r;
+ In[j].g = (cmsUInt8Number)g;
+ In[j].b = (cmsUInt8Number)b;
+ In[j].a = 0;
+
+ j++;
+ }
+
+ atime = clock();
+
+ cmsDoTransform(ct, hlcmsxform, In, In, 256 * 256 * 256);
+
+ diff = clock() - atime;
+ free(In);
+
+ cmsDeleteTransform(ct, hlcmsxform);
+ return MPixSec(diff);
+
+}
+
+
+// The worst case is used, no cache and all rgb combinations
+static
+cmsFloat64Number SpeedTest15bitsRGB(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
+{
+ cmsInt32Number r, g, b, j;
+ clock_t atime;
+ cmsFloat64Number diff;
+ cmsHTRANSFORM hlcmsxform;
+ Scanline_rgb15bits *In;
+ cmsUInt32Number Mb;
+
+ if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
+ Fail("Unable to open profiles");
+
+ hlcmsxform = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_RGB_15, hlcmsProfileOut, TYPE_RGB_15, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
+ cmsCloseProfile(ct, hlcmsProfileIn);
+ cmsCloseProfile(ct, hlcmsProfileOut);
+
+ Mb = 256 * 256 * 256 * sizeof(Scanline_rgb15bits);
+ In = (Scanline_rgb15bits*)malloc(Mb);
+
+ j = 0;
+ for (r = 0; r < 256; r++)
+ for (g = 0; g < 256; g++)
+ for (b = 0; b < 256; b++) {
+
+ In[j].r = (cmsUInt16Number)r;
+ In[j].g = (cmsUInt16Number)g;
+ In[j].b = (cmsUInt16Number)b;
+
+ j++;
+ }
+
+ atime = clock();
+
+ cmsDoTransform(ct, hlcmsxform, In, In, 256 * 256 * 256);
+
+ diff = clock() - atime;
+ free(In);
+
+ cmsDeleteTransform(ct, hlcmsxform);
+
+ return MPixSec(diff);
+}
+
+static
+cmsFloat64Number SpeedTest15bitsRGBA(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
+{
+ cmsInt32Number r, g, b, j;
+ clock_t atime;
+ cmsFloat64Number diff;
+ cmsHTRANSFORM hlcmsxform;
+ Scanline_rgba15bits *In;
+ cmsUInt32Number Mb;
+
+ if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
+ Fail("Unable to open profiles");
+
+ hlcmsxform = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_RGBA_15, hlcmsProfileOut, TYPE_RGBA_15, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
+ cmsCloseProfile(ct, hlcmsProfileIn);
+ cmsCloseProfile(ct, hlcmsProfileOut);
+
+ Mb = 256 * 256 * 256 * sizeof(Scanline_rgba15bits);
+ In = (Scanline_rgba15bits*)malloc(Mb);
+
+ j = 0;
+ for (r = 0; r < 256; r++)
+ for (g = 0; g < 256; g++)
+ for (b = 0; b < 256; b++) {
+
+ In[j].r = (cmsUInt16Number)r;
+ In[j].g = (cmsUInt16Number)g;
+ In[j].b = (cmsUInt16Number)b;
+ In[j].a = 0;
+
+ j++;
+ }
+
+ atime = clock();
+
+ cmsDoTransform(ct, hlcmsxform, In, In, 256 * 256 * 256);
+
+ diff = clock() - atime;
+ free(In);
+
+ cmsDeleteTransform(ct, hlcmsxform);
+ return MPixSec(diff);
+
+}
+
+static
+cmsFloat64Number SpeedTest15bitsCMYK(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
+{
+
+ cmsInt32Number r, g, b, j;
+ clock_t atime;
+ cmsFloat64Number diff;
+ cmsHTRANSFORM hlcmsxform;
+ Scanline_cmyk15bits *In;
+ cmsUInt32Number Mb;
+
+ if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
+ Fail("Unable to open profiles");
+
+ hlcmsxform = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_CMYK_15, hlcmsProfileOut, TYPE_CMYK_15, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
+ cmsCloseProfile(ct, hlcmsProfileIn);
+ cmsCloseProfile(ct, hlcmsProfileOut);
+
+ Mb = 256 * 256 * 256 * sizeof(Scanline_cmyk15bits);
+ In = (Scanline_cmyk15bits*)malloc(Mb);
+
+ j = 0;
+ for (r = 0; r < 256; r++)
+ for (g = 0; g < 256; g++)
+ for (b = 0; b < 256; b++) {
+
+ In[j].r = (cmsUInt16Number)r;
+ In[j].g = (cmsUInt16Number)g;
+ In[j].b = (cmsUInt16Number)b;
+ In[j].a = (cmsUInt16Number)0;
+
+ j++;
+ }
+
+ atime = clock();
+
+ cmsDoTransform(ct, hlcmsxform, In, In, 256 * 256 * 256);
+
+ diff = clock() - atime;
+ free(In);
+
+ cmsDeleteTransform(ct, hlcmsxform);
+ return MPixSec(diff);
+}
+
+// The worst case is used, no cache and all rgb combinations
+static
+cmsFloat64Number SpeedTest16bitsRGB(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
+{
+ cmsInt32Number r, g, b, j;
+ clock_t atime;
+ cmsFloat64Number diff;
+ cmsHTRANSFORM hlcmsxform;
+ Scanline_rgb16bits *In;
+ cmsUInt32Number Mb;
+
+ if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
+ Fail("Unable to open profiles");
+
+ hlcmsxform = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_RGB_16, hlcmsProfileOut, TYPE_RGB_16, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
+ cmsCloseProfile(ct, hlcmsProfileIn);
+ cmsCloseProfile(ct, hlcmsProfileOut);
+
+ Mb = 256 * 256 * 256 * sizeof(Scanline_rgb16bits);
+ In = (Scanline_rgb16bits*)malloc(Mb);
+
+ j = 0;
+ for (r = 0; r < 256; r++)
+ for (g = 0; g < 256; g++)
+ for (b = 0; b < 256; b++) {
+
+ In[j].r = (cmsUInt16Number)FROM_8_TO_16(r);
+ In[j].g = (cmsUInt16Number)FROM_8_TO_16(g);
+ In[j].b = (cmsUInt16Number)FROM_8_TO_16(b);
+
+ j++;
+ }
+
+ atime = clock();
+
+ cmsDoTransform(ct, hlcmsxform, In, In, 256 * 256 * 256);
+
+ diff = clock() - atime;
+ free(In);
+
+ cmsDeleteTransform(ct, hlcmsxform);
+
+ return MPixSec(diff);
+}
+
+
+static
+void SpeedTest8(cmsContext ct)
+{
+ printf("\n\nP E R F O R M A N C E T E S T S 8 B I T S\n");
+ printf( "==============================================\n\n");
+
+ PerformanceHeader();
+ Performance("8 bits on CLUT profiles ", SpeedTest8bitsRGB, ct, "test5.icc", "test3.icc", sizeof(Scanline_rgb8bits), 0);
+ Performance("8 bits on Matrix-Shaper profiles", SpeedTest8bitsRGB, ct, "test5.icc", "test0.icc", sizeof(Scanline_rgb8bits), 0);
+ Performance("8 bits on same Matrix-Shaper ", SpeedTest8bitsRGB, ct, "test0.icc", "test0.icc", sizeof(Scanline_rgb8bits), 0);
+ Performance("8 bits on curves ", SpeedTest8bitsRGB, ct, NULL, NULL, sizeof(Scanline_rgb8bits), 0);
+ // Performance("8 bits on CMYK CLUT profiles ", SpeedTest8bitsCMYK, ct, "test1.icc", "test2.icc", sizeof(Scanline_rgba15bits), 0);
+}
+
+
+static
+void SpeedTest15(cmsContext ct)
+{
+ printf("\n\nP E R F O R M A N C E T E S T S 1 5 B I T S\n");
+ printf( "================================================\n\n");
+
+ PerformanceHeader();
+ Performance("15 bits on CLUT profiles ", SpeedTest15bitsRGB, ct, "test5.icc", "test3.icc", sizeof(Scanline_rgb15bits), 0);
+ Performance("15 bits on Matrix-Shaper profiles", SpeedTest15bitsRGB, ct, "test5.icc", "test0.icc", sizeof(Scanline_rgb15bits), 0);
+ Performance("15 bits on same Matrix-Shaper ", SpeedTest15bitsRGB, ct, "test0.icc", "test0.icc", sizeof(Scanline_rgb15bits), 0);
+ Performance("15 bits on curves ", SpeedTest15bitsRGB, ct, NULL, NULL, sizeof(Scanline_rgb15bits), 0);
+ Performance("15 bits on CMYK CLUT profiles ", SpeedTest15bitsCMYK, ct, "test1.icc", "test2.icc", sizeof(Scanline_rgba15bits), 0);
+}
+
+static
+void SpeedTest16(cmsContext ct)
+{
+ printf("\n\nP E R F O R M A N C E T E S T S 1 6 B I T S\n");
+ printf("================================================\n\n");
+
+ PerformanceHeader();
+ Performance("16 bits on CLUT profiles ", SpeedTest16bitsRGB, ct, "test5.icc", "test3.icc", sizeof(Scanline_rgb15bits), 0);
+
+}
+
+// The worst case is used, no cache and all rgb combinations
+static
+cmsFloat64Number SpeedTestFloatRGB(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
+{
+ cmsInt32Number r, g, b, j;
+ clock_t atime;
+ cmsFloat64Number diff;
+ cmsHTRANSFORM hlcmsxform;
+ Scanline_rgbFloat *In;
+ cmsUInt32Number Mb;
+
+ if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
+ Fail("Unable to open profiles");
+
+ hlcmsxform = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_RGB_FLT, hlcmsProfileOut, TYPE_RGB_FLT, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
+ cmsCloseProfile(ct, hlcmsProfileIn);
+ cmsCloseProfile(ct, hlcmsProfileOut);
+
+ Mb = 256 * 256 * 256 * sizeof(Scanline_rgbFloat);
+ In = (Scanline_rgbFloat*)malloc(Mb);
+
+ j = 0;
+ for (r = 0; r < 256; r++)
+ for (g = 0; g < 256; g++)
+ for (b = 0; b < 256; b++) {
+
+ In[j].r = (cmsFloat32Number)r / 255.0f;
+ In[j].g = (cmsFloat32Number)g / 255.0f;
+ In[j].b = (cmsFloat32Number)b / 255.0f;
+
+ j++;
+ }
+
+ atime = clock();
+
+ cmsDoTransform(ct, hlcmsxform, In, In, 256 * 256 * 256);
+
+ diff = clock() - atime;
+ free(In);
+
+ cmsDeleteTransform(ct, hlcmsxform);
+ return MPixSec(diff);
+}
+
+
+
+
+static
+void SpeedTestFloat(cmsContext noPlugin, cmsContext plugin)
+{
+ cmsFloat64Number t[10];
+
+ printf("\n\n");
+ printf("P E R F O R M A N C E T E S T S F L O A T (D E F A U L T)\n");
+ printf("==============================================================\n\n");
+ fflush(stdout);
+
+ PerformanceHeader();
+ t[0] = Performance("Floating point on CLUT profiles ", SpeedTestFloatRGB, noPlugin, "test5.icc", "test3.icc", sizeof(Scanline_rgbFloat), 0);
+ t[1] = Performance("Floating point on Matrix-Shaper ", SpeedTestFloatRGB, noPlugin, "test5.icc", "test0.icc", sizeof(Scanline_rgbFloat), 0);
+ t[2] = Performance("Floating point on same MatrixSh ", SpeedTestFloatRGB, noPlugin, "test0.icc", "test0.icc", sizeof(Scanline_rgbFloat), 0);
+ t[3] = Performance("Floating point on curves ", SpeedTestFloatRGB, noPlugin, NULL, NULL, sizeof(Scanline_rgbFloat), 0);
+
+ // Note that context 0 has the plug-in installed
+
+ printf("\n\n");
+ printf("P E R F O R M A N C E T E S T S F L O A T (P L U G I N)\n");
+ printf("===========================================================\n\n");
+ fflush(stdout);
+
+ PerformanceHeader();
+ Performance("Floating point on CLUT profiles ", SpeedTestFloatRGB, plugin, "test5.icc", "test3.icc", sizeof(Scanline_rgbFloat), t[0]);
+ Performance("Floating point on Matrix-Shaper ", SpeedTestFloatRGB, plugin, "test5.icc", "test0.icc", sizeof(Scanline_rgbFloat), t[1]);
+ Performance("Floating point on same MatrixSh ", SpeedTestFloatRGB, plugin, "test0.icc", "test0.icc", sizeof(Scanline_rgbFloat), t[2]);
+ Performance("Floating point on curves ", SpeedTestFloatRGB, plugin, NULL, NULL, sizeof(Scanline_rgbFloat), t[3]);
+}
+
+
+static
+cmsFloat64Number SpeedTestFloatByUsing16BitsRGB(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
+{
+ cmsInt32Number r, g, b, j;
+ clock_t atime;
+ cmsFloat64Number diff;
+ cmsHTRANSFORM xform16;
+ Scanline_rgbFloat *In;
+ Scanline_rgb16bits *tmp16;
+ cmsUInt32Number MbFloat, Mb16;
+
+ UNUSED_PARAMETER(ct);
+
+ if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
+ Fail("Unable to open profiles");
+
+ xform16 = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_RGB_16, hlcmsProfileOut, TYPE_RGB_16, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
+
+ cmsCloseProfile(ct, hlcmsProfileIn);
+ cmsCloseProfile(ct, hlcmsProfileOut);
+
+ MbFloat = 256 * 256 * 256 * sizeof(Scanline_rgbFloat);
+ Mb16 = 256 * 256 * 256 * sizeof(Scanline_rgb16bits);
+
+ In = (Scanline_rgbFloat*)malloc(MbFloat);
+ tmp16 = (Scanline_rgb16bits*)malloc(Mb16);
+
+
+ j = 0;
+ for (r = 0; r < 256; r++)
+ for (g = 0; g < 256; g++)
+ for (b = 0; b < 256; b++) {
+
+ In[j].r = (cmsFloat32Number)r / 255.0f;
+ In[j].g = (cmsFloat32Number)g / 255.0f;
+ In[j].b = (cmsFloat32Number)b / 255.0f;
+
+ j++;
+ }
+
+
+ atime = clock();
+
+
+ for (j = 0; j < 256 * 256 * 256; j++) {
+
+ tmp16[j].r = (cmsUInt16Number)floor(In[j].r * 65535.0 + 0.5);
+ tmp16[j].g = (cmsUInt16Number)floor(In[j].g * 65535.0 + 0.5);
+ tmp16[j].b = (cmsUInt16Number)floor(In[j].b * 65535.0 + 0.5);
+
+ j++;
+ }
+
+ cmsDoTransform(ct, xform16, tmp16, tmp16, 256 * 256 * 256);
+
+ for (j = 0; j < 256 * 256 * 256; j++) {
+
+ In[j].r = (cmsFloat32Number) (tmp16[j].r / 65535.0 );
+ In[j].g = (cmsFloat32Number) (tmp16[j].g / 65535.0);
+ In[j].b = (cmsFloat32Number) (tmp16[j].b / 65535.0);
+
+ j++;
+ }
+
+ diff = clock() - atime;
+ free(In);
+
+ cmsDeleteTransform(ct, xform16);
+ return MPixSec(diff);
+}
+
+
+
+
+
+static
+void ComparativeFloatVs16bits(cmsContext Raw, cmsContext Plugin)
+{
+ printf("\n\n");
+ printf("C O M P A R A T I V E converting to 16 bit vs. using float plug-in.\n");
+ printf(" values given in MegaPixels per second.\n");
+ printf("====================================================================\n");
+ printf(" 16 bits tmp. Float plugin\n");
+ fflush(stdout);
+
+ Comparative(Raw, Plugin, "Floating point on CLUT profiles ", SpeedTestFloatByUsing16BitsRGB, SpeedTestFloatRGB, "test5.icc", "test3.icc");
+ Comparative(Raw, Plugin, "Floating point on Matrix-Shaper ", SpeedTestFloatByUsing16BitsRGB, SpeedTestFloatRGB, "test5.icc", "test0.icc");
+ Comparative(Raw, Plugin, "Floating point on same MatrixSh ", SpeedTestFloatByUsing16BitsRGB, SpeedTestFloatRGB, "test0.icc", "test0.icc");
+ Comparative(Raw, Plugin, "Floating point on curves ", SpeedTestFloatByUsing16BitsRGB, SpeedTestFloatRGB, NULL, NULL);
+}
+
+
+
+
+
+
+
+typedef struct
+{
+ Scanline_rgba8bits pixels[256][256];
+ cmsUInt8Number padding[4];
+
+} padded_line;
+
+typedef struct
+{
+ padded_line line[256];
+} big_bitmap;
+
+
+static
+cmsFloat64Number SpeedTest8bitDoTransform(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
+{
+ cmsInt32Number r, g, b, j;
+ clock_t atime;
+ cmsFloat64Number diff;
+ cmsHTRANSFORM hlcmsxform;
+ big_bitmap* In;
+ big_bitmap* Out;
+ cmsUInt32Number Mb;
+
+ if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
+ Fail("Unable to open profiles");
+
+ hlcmsxform = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_RGBA_8, hlcmsProfileOut, TYPE_RGBA_8, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
+ cmsCloseProfile(ct, hlcmsProfileIn);
+ cmsCloseProfile(ct, hlcmsProfileOut);
+
+
+ // Our test bitmap is 256 x 256 padded lines
+ Mb = sizeof(big_bitmap);
+
+ In = (big_bitmap*)malloc(Mb);
+ Out = (big_bitmap*)malloc(Mb);
+
+ for (r = 0; r < 256; r++)
+ for (g = 0; g < 256; g++)
+ for (b = 0; b < 256; b++) {
+
+ In->line[r].pixels[g][b].r = (cmsUInt8Number)r;
+ In->line[r].pixels[g][b].g = (cmsUInt8Number)g;
+ In->line[r].pixels[g][b].b = (cmsUInt8Number)b;
+ In->line[r].pixels[g][b].a = 0;
+ }
+
+ atime = clock();
+
+ for (j = 0; j < 256; j++) {
+
+ cmsDoTransform(ct, hlcmsxform, In->line[j].pixels, Out->line[j].pixels, 256 * 256);
+ }
+
+ diff = clock() - atime;
+ free(In); free(Out);
+
+ cmsDeleteTransform(ct, hlcmsxform);
+ return MPixSec(diff);
+
+}
+
+
+static
+cmsFloat64Number SpeedTest8bitLineStride(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
+{
+ cmsInt32Number r, g, b;
+ clock_t atime;
+ cmsFloat64Number diff;
+ cmsHTRANSFORM hlcmsxform;
+ big_bitmap* In;
+ big_bitmap* Out;
+ cmsUInt32Number Mb;
+
+ if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
+ Fail("Unable to open profiles");
+
+ hlcmsxform = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_RGBA_8, hlcmsProfileOut, TYPE_RGBA_8, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
+ cmsCloseProfile(ct, hlcmsProfileIn);
+ cmsCloseProfile(ct, hlcmsProfileOut);
+
+
+ // Our test bitmap is 256 x 256 padded lines
+ Mb = sizeof(big_bitmap);
+
+ In = (big_bitmap*)malloc(Mb);
+ Out = (big_bitmap*)malloc(Mb);
+
+ for (r = 0; r < 256; r++)
+ for (g = 0; g < 256; g++)
+ for (b = 0; b < 256; b++) {
+
+ In->line[r].pixels[g][b].r = (cmsUInt8Number)r;
+ In->line[r].pixels[g][b].g = (cmsUInt8Number)g;
+ In->line[r].pixels[g][b].b = (cmsUInt8Number)b;
+ In->line[r].pixels[g][b].a = 0;
+ }
+
+ atime = clock();
+
+ cmsDoTransformLineStride(ct, hlcmsxform, In, Out, 256*256, 256, sizeof(padded_line), sizeof(padded_line), 0, 0);
+
+ diff = clock() - atime;
+ free(In); free(Out);
+
+ cmsDeleteTransform(ct, hlcmsxform);
+ return MPixSec(diff);
+
+}
+
+static
+void ComparativeLineStride8bits(cmsContext NoPlugin, cmsContext Plugin)
+{
+ printf("\n\n");
+ printf("C O M P A R A T I V E cmsDoTransform() vs. cmsDoTransformLineStride()\n");
+ printf(" values given in MegaPixels per second.\n");
+ printf("====================================================================\n");
+
+ fflush(stdout);
+
+ ComparativeCt(NoPlugin, Plugin, "CLUT profiles ", SpeedTest8bitDoTransform, SpeedTest8bitLineStride, "test5.icc", "test3.icc");
+ ComparativeCt(NoPlugin, Plugin, "CLUT 16 bits ", SpeedTest16bitsRGB, SpeedTest16bitsRGB, "test5.icc", "test3.icc");
+ ComparativeCt(NoPlugin, Plugin, "Matrix-Shaper ", SpeedTest8bitDoTransform, SpeedTest8bitLineStride, "test5.icc", "test0.icc");
+ ComparativeCt(NoPlugin, Plugin, "same MatrixSh ", SpeedTest8bitDoTransform, SpeedTest8bitLineStride, "test0.icc", "test0.icc");
+ ComparativeCt(NoPlugin, Plugin, "curves ", SpeedTest8bitDoTransform, SpeedTest8bitLineStride, NULL, NULL);
+}
+
+
+
+static
+void TestGrayTransformPerformance(cmsContext ct)
+{
+ cmsInt32Number j;
+ clock_t atime;
+ cmsFloat64Number diff;
+ cmsHTRANSFORM hlcmsxform;
+ float *In;
+
+ cmsInt32Number pixels;
+ cmsUInt32Number Mb;
+ cmsToneCurve* gamma18;
+ cmsToneCurve* gamma22;
+
+ cmsHPROFILE hlcmsProfileIn;
+ cmsHPROFILE hlcmsProfileOut;
+
+ gamma18 = cmsBuildGamma(ct, 1.8);
+ gamma22 = cmsBuildGamma(ct, 2.2);
+
+ hlcmsProfileIn = cmsCreateGrayProfile(ct, NULL, gamma18);
+ hlcmsProfileOut = cmsCreateGrayProfile(ct, NULL, gamma22);
+
+
+ cmsFreeToneCurve(ct, gamma18);
+ cmsFreeToneCurve(ct, gamma22);
+
+ hlcmsxform = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_GRAY_FLT | EXTRA_SH(1), hlcmsProfileOut, TYPE_GRAY_FLT|EXTRA_SH(1), INTENT_PERCEPTUAL, 0);
+ cmsCloseProfile(ct, hlcmsProfileIn);
+ cmsCloseProfile(ct, hlcmsProfileOut);
+
+ pixels = 256 * 256 * 256;
+ Mb = pixels* 2*sizeof(float);
+ In = malloc(Mb);
+
+ for (j = 0; j < pixels*2; j++)
+ In[j] = (j % 256) / 255.0f;
+
+ atime = clock();
+
+ cmsDoTransform(ct, hlcmsxform, In, In, pixels);
+
+ diff = clock() - atime;
+ free(In);
+
+ cmsDeleteTransform(ct, hlcmsxform);
+ printf("Gray conversion using two gray profiles\t %-12.2f MPixels/Sec.\n", MPixSec(diff));
+}
+
+static
+void TestGrayTransformPerformance1(cmsContext ct)
+{
+ cmsInt32Number j;
+ clock_t atime;
+ cmsFloat64Number diff;
+ cmsHTRANSFORM hlcmsxform;
+ float *In;
+
+ cmsInt32Number pixels;
+ cmsUInt32Number Mb;
+ cmsToneCurve* gamma18;
+ cmsToneCurve* gamma22;
+
+ cmsHPROFILE hlcmsProfileIn;
+ cmsHPROFILE hlcmsProfileOut;
+
+ gamma18 = cmsBuildGamma(ct, 1.8);
+ gamma22 = cmsBuildGamma(ct, 1./2.2);
+
+ hlcmsProfileIn = cmsCreateLinearizationDeviceLink(ct, cmsSigGrayData, &gamma18);
+ hlcmsProfileOut = cmsCreateLinearizationDeviceLink(ct, cmsSigGrayData, &gamma22);
+
+
+ cmsFreeToneCurve(ct, gamma18);
+ cmsFreeToneCurve(ct, gamma22);
+
+ hlcmsxform = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_GRAY_FLT, hlcmsProfileOut, TYPE_GRAY_FLT, INTENT_PERCEPTUAL, 0);
+ cmsCloseProfile(ct, hlcmsProfileIn);
+ cmsCloseProfile(ct, hlcmsProfileOut);
+
+ pixels = 256 * 256 * 256;
+ Mb = pixels* sizeof(float);
+ In = malloc(Mb);
+
+ for (j = 0; j < pixels; j++)
+ In[j] = (j % 256) / 255.0f;
+
+ atime = clock();
+
+ cmsDoTransform(ct, hlcmsxform, In, In, pixels);
+
+ diff = clock() - atime;
+ free(In);
+
+ cmsDeleteTransform(ct, hlcmsxform);
+ printf("Gray conversion using two devicelinks\t %-12.2f MPixels/Sec.\n", MPixSec(diff));
+}
+
+
+// The harness test
+int main()
+{
+ cmsContext raw = cmsCreateContext(NULL, NULL);
+ cmsContext plugin = cmsCreateContext(NULL, NULL);
+
+ printf("FastFloating point extensions testbed - 1.2\n");
+ printf("Copyright (c) 1998-2020 Marti Maria Saguer, all rights reserved\n");
+
+ printf("\nInstalling error logger ... ");
+ cmsSetLogErrorHandler(raw, FatalErrorQuit);
+ cmsSetLogErrorHandler(plugin, FatalErrorQuit);
+ printf("done.\n");
+
+ printf("Installing plug-in ... ");
+ cmsPlugin(plugin, cmsFastFloatExtensions());
+ printf("done.\n\n");
+
+ CheckLab2Roundtrip(plugin);
+
+ CheckComputeIncrements();
+
+ // 15 bit functionality
+ CheckFormatters15();
+ Check15bitsConversions(plugin);
+
+ // 16 bits functionality
+ CheckAccuracy16Bits(raw, plugin);
+
+ // Change format
+ CheckChangeFormat(plugin);
+
+ // Floating point functionality
+ CheckConversionFloat(raw, plugin);
+ printf("All floating point tests passed OK\n");
+
+ SpeedTest8(plugin);
+ SpeedTest16(plugin);
+ SpeedTest15(plugin);
+ SpeedTestFloat(raw, plugin);
+
+
+ ComparativeFloatVs16bits(raw, plugin);
+ ComparativeLineStride8bits(raw, plugin);
+
+ // Test gray performance
+ printf("\n\n");
+ printf("F L O A T G R A Y conversions performance.\n");
+ printf("====================================================================\n");
+ TestGrayTransformPerformance(plugin);
+ TestGrayTransformPerformance1(plugin);
+
+ printf("\nAll tests passed OK\n");
+
+
+ return 0;
+}
diff --git a/lcms2mt/plugins/fast_float/testbed/test0.icc b/lcms2mt/plugins/fast_float/testbed/test0.icc
new file mode 100644
index 00000000..a79f576b
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/testbed/test0.icc
Binary files differ
diff --git a/lcms2mt/plugins/fast_float/testbed/test1.icc b/lcms2mt/plugins/fast_float/testbed/test1.icc
new file mode 100644
index 00000000..d0245c81
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/testbed/test1.icc
Binary files differ
diff --git a/lcms2mt/plugins/fast_float/testbed/test2.icc b/lcms2mt/plugins/fast_float/testbed/test2.icc
new file mode 100644
index 00000000..73f1b5aa
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/testbed/test2.icc
Binary files differ
diff --git a/lcms2mt/plugins/fast_float/testbed/test3.icc b/lcms2mt/plugins/fast_float/testbed/test3.icc
new file mode 100644
index 00000000..d0e79301
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/testbed/test3.icc
Binary files differ
diff --git a/lcms2mt/plugins/fast_float/testbed/test5.icc b/lcms2mt/plugins/fast_float/testbed/test5.icc
new file mode 100644
index 00000000..34583ab1
--- /dev/null
+++ b/lcms2mt/plugins/fast_float/testbed/test5.icc
Binary files differ