diff options
author | Mattias Andrée <maandree@kth.se> | 2019-10-06 20:36:00 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2019-10-06 20:46:04 +0200 |
commit | 67bc1de939bdfb2072074bc9554dfea9b32f64cd (patch) | |
tree | 1870ce05873f8ed9cdfa87fafa0d8b3e6223dd8d | |
parent | fix cielab to ciexyz conversion (diff) | |
download | libclut-67bc1de939bdfb2072074bc9554dfea9b32f64cd.tar.gz libclut-67bc1de939bdfb2072074bc9554dfea9b32f64cd.tar.bz2 libclut-67bc1de939bdfb2072074bc9554dfea9b32f64cd.tar.xz |
Simplify
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
47 files changed, 3661 insertions, 11317 deletions
@@ -1,23 +1,8 @@ -_/ -/bin/ -/aux/ -/obj/ -\#*\# -.* -!.git* +*\#* *~ -*.bak -*.new -*.swo -*.swp -*.out *.o +*.a +*.lo *.su -*.gch -*.info -*.pdf -*.ps -*.dvi -/config.status -/Makefile - +*.so +/test diff --git a/COPYING b/COPYING deleted file mode 100644 index 94a9ed0..0000000 --- a/COPYING +++ /dev/null @@ -1,674 +0,0 @@ - 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>. diff --git a/DEPENDENCIES b/DEPENDENCIES deleted file mode 100644 index cfd6079..0000000 --- a/DEPENDENCIES +++ /dev/null @@ -1,22 +0,0 @@ -RUNTIME DEPENDENCIES: - - libc - - -BUILD DEPENDENCIES: - - make - coreutils - cc - texinfo>=4.11 (opt-out, for info, pdf, dvi, ps, and html manuals) - texlive-plainextra (opt-in, for pdf, dvi, and ps manuals) - - texinfo<4.11 can be used if '@frenchspacing on' is removed. - - -INSTALL DEPENDENCIES: - - make - coreutils - texinfo (opt-out, for dir-entry of info manual) - diff --git a/INSTALL b/INSTALL deleted file mode 100644 index 345abf0..0000000 --- a/INSTALL +++ /dev/null @@ -1,77 +0,0 @@ -Type './configure --help' for configuration options. The normal settings for a -GNU package should work. If not, please make a bug report. - - On a common GNU/Linux distribution the following should - be sufficient for most users: - - ./configure --prefix=/usr - make - make install DESTDIR="somewhere you want the files for now" - # Now let the package manager put the files in place... - - Or for an unstaged install: - - ./configure --prefix=/usr - make - sudo make install - -By default any applicable pre-install, post-install, pre-uninstall, and -post-install commands is run. This suppress these, run 'make' with 'N=true' -or 'N=:'. IF you want to know which these commands are, you can use the -methods specificed in the GNU Coding Standards. Another method is found in -mk/README. However, for this packages, these will be: - - infodir="usr/local/share/info" ## Assuming default prefix. - - post_install () { - install-info -- "${infodir}/libclut.info" "${infodir}/dir" - } - - pre_uninstall () { - install-info --delete -- "${infodir}/libclut.info" "${infodir}/dir" - } - - -──────────────────────────────────────────────────────────────────────────────── -CUSTOMISED COMPILATION -──────────────────────────────────────────────────────────────────────────────── - -The makefile is configured to compile the C code with -O2 -g, you can -change this by setting OPTIMISE, or with CFLAGS and LDFLAGS if you want -to change all optional flags compiling and linking flags: - - ./configure OPTIMISE="-Og -g" - - -──────────────────────────────────────────────────────────────────────────────── -CUSTOMISED INSTALLATION -──────────────────────────────────────────────────────────────────────────────── - -If you want to install absolutely everything, you can -instead use the commands below: - - make everything - make install-everything DESTDIR="pkg" - -Or if you only want to absolute basics: - - make base - make install-base DESTDIR="pkg" - -You can select freely what parts of the package to install and not -to install. This rules are available: - -┌─────────────┬─────────────────────┬────────────────────────────────────────────┐ -│ COMPILATION │ INSTALLATION │ DESCRIPTION │ -├─────────────┼─────────────────────┼────────────────────────────────────────────┤ -│ base │ install-base │ Install the basics: │ -│ │ install-lib │ Install the libclut library. │ -│ │ install-copyright │ Install the the GPL v3 license. │ -│ doc │ install-doc │ Include all manuals: │ -│ info │ install-info │ Include info manual. (Texinfo) │ -│ dvi │ install-dvi │ Include DVI manual. (Texinfo) │ -│ pdf │ install-pdf │ Include PDF manual. (Texinfo) │ -│ ps │ install-ps │ Include PostScript manual. (Texinfo) │ -│ html │ install-html │ Include multifile HTML manual. (Texinfo) │ -└─────────────┴─────────────────────┴────────────────────────────────────────────┘ - @@ -0,0 +1,15 @@ +ISC License + +© 2016, 2019 Mattias Andrée <maandree@kth.se> + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4ed58b0 --- /dev/null +++ b/Makefile @@ -0,0 +1,37 @@ +.POSIX: + +CONFIGFILE = config.mk +include $(CONFIGFILE) + +all: libclut.a + +libclut.o: libclut.c libclut.h + $(CC) -c -o $@ libclut.c $(CPPFLAGS) $(CFLAGS) + +libclut.a: libclut.o + $(AR) rc $@ libclut.o + $(AR) s $@ + +test.o: test.c libclut.h + $(CC) -c -o $@ test.c $(CPPFLAGS) $(CFLAGS) + +test: test.o libclut.a + $(CC) -o $@ test.o libclut.a $(LDFLAGS) + +check: test + ./test + +install: libclut.a + mkdir -p -- "$(DESTDIR)$(PREFIX)/lib" + mkdir -p -- "$(DESTDIR)$(PREFIX)/include" + cp -- libclut.a "$(DESTDIR)$(PREFIX)/lib" + cp -- libclut.h "$(DESTDIR)$(PREFIX)/include" + +uninstall: + -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libclut.a" + -rm -f -- "$(DESTDIR)$(PREFIX)/include/libclut.h" + +clean: + -rm -f -- *.o *.a test + +.PHONY: all check install uninstall clean diff --git a/Makefile.in b/Makefile.in deleted file mode 100644 index 13c1fac..0000000 --- a/Makefile.in +++ /dev/null @@ -1,84 +0,0 @@ -# Copyright (C) 2016 Mattias Andrée <maandree@member.fsf.org> -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without any warranty. - - -### This file will be stored to Makefile once you have run ./configure. ### -### See INSTALL for information on how to install this package. ### - - - -##### What is below this line is configurable, but is seldom useful. ##### - - -# Additional options for compiling info and HTML manuals. -INFO_FLAGS = - -# Additional options for compiling DVI, PDF, and PostScript manuals. -TEXINFO_FLAGS = - -# The name of the package as it should be installed. -PKGNAME = libclut - - - -##### Nothing interesting below this. ##### - - -# In case you want add some configurations. Primarily -# intended for maintainers. Perhaps add GPG_KEY here. -# Of course, you can declare everthing with ./configure, -# but with this you are less likely to forget it. --include .make-configurations - - -# YOU, AS A USER, SHOULD NOT CHANGE THESE VARIABLES. {{ -# They specify how the reusable makefiles in mk/ shall behave. - -# Package information. -_PROJECT = libclut -_VERSION = 1.2 - -# Used by mk/lang-c.mk -_C_STD = c99 -_H = libclut -_HEADER_DIRLEVELS = 1 -_LIB = libclut -_OBJ_libclut = libclut -_SO_VERSION_libclut = $(_VERSION) -_SO_MAJOR_libclut = $(shell echo $(_SO_VERSION_libclut) | cut -d . -f 1) - -# Used by mk/texinfo.mk -_TEXINFO_DIRLEVELS = 2 -_INFOPARTS = 0 -_HAVE_TEXINFO_MANUAL = yes -_HTML_FILES = Free-Software-Needs-Free-Documentation.html GNU-Free-Documentation-License.html \ - GNU-General-Public-License.html index.html Overview.html CLUT-Manipulation.html \ - Colour-Spaces.html - -# Used by mk/man.mk -#_MAN_PAGE_SECTIONS = 0 3 7 -#_MAN_0 = libclut.h -#_MAN_3 = -#_MAN_7 = libclut - -# Used by mk/copy.mk -_COPYING = COPYING - -# Used by mk/dist.mk -___EVERYTHING_INFO = libclut titlepage-data content hardcopy-copying \ - appx/fdl appx/free-software-needs-free-documentation appx/gpl \ - reusable/macros reusable/paper reusable/titlepage \ - chap/overview chap/clut-manipulation.texinfo chap/colour-spaces.texinfo -_EVERYTHING = $(__EVERYTHING_ALL_COMMON) DEPENDENCIES INSTALL NEWS \ - $(foreach F,$(___EVERYTHING_INFO),doc/info/$(F).texinfo) libclut.h - -# }} - - -# Reusable make rules and the configurations. -include $(v)mk/all.mk - @@ -1,38 +0,0 @@ -libclut NEWS -*- outline -*- - -* Noteworthy changes in release 1.2 (TBA) [stable] - - New RGB colour spaces added: ITU-R BT.2020, ITU-R BT.2100, - ITU-R BT.601 625 line, ITU-R BT.601 525 line, DCI-P3 D65, - and DCI-P3 Theater. - -* Noteworthy changes in release 1.1 (2016-(12)Dec-03) [stable] - - Support for CIELUV, CIELCh, YIQ, YDbDr, YPbPr, YCgCo, - CIE 1960 USC, and CIE U*V*W* added. - - New RGB colour spaces added: ITU-R BT.709 and Lightroom RGB. - - libclut_model_get_rgb_conversion_matrix accepts NULL as - as the first and second argument. - - Add the functions libclut_model_rgb_to_xyz and - libclut_model_rgb_to_xyz. - -* Noteworthy changes in release 1.0 (2016-(12)Dec-02) [stable] - - RGB colour space conversion added. - -* Noteworthy changes in release 0.3 (2016-(08)Aug-06) [beta] - - No significant changes. - -* Noteworthy changes in release 0.2 (2016-(08)Aug-05) [beta] - - No significant changes. - -* Noteworthy changes in release 0.1 (2016-(07)Jul-13) [beta] - - Initial release. - - _cie_ affixed functions have not been tested. @@ -7,4 +7,3 @@ DESCRIPTION SEE ALSO libcolour(7), libred(7), redshift(1), blueshift(1), libgamma(7), libcoopgamma(7) - diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..32897e2 --- /dev/null +++ b/config.mk @@ -0,0 +1,6 @@ +PREFIX = /usr +MANPREFIX = $(PREFIX)/share/man + +CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_GNU_SOURCE +CFLAGS = -std=c99 -Wall +LDFLAGS = -lm diff --git a/configure b/configure deleted file mode 100755 index 5914cd6..0000000 --- a/configure +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/sh - -# Copyright (C) 2016 Mattias Andrée <maandree@member.fsf.org> -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without any warranty. - - -# Run './configure --help' for usage information. - - -PKGNAME=libclut -MAN_SECTION_SUFFIX= - - -list_optional_features_help () -{ - true -} - -unrecognised_argument () -{ - option="${1}" - case "${option}" in - (--build | --target | --host) - incomplete="${option}" ;; - (--build=*) - ;; - (--target=*) - ;; - (--host=*) - ;; - (*) - ;; - esac -} - -. "$(dirname "${0}")"/mk/configure - - -cat <<EOF - -You can now run 'make && make install'. - -EOF - diff --git a/doc/info/appx/fdl.texinfo b/doc/info/appx/fdl.texinfo deleted file mode 100644 index cb71f05..0000000 --- a/doc/info/appx/fdl.texinfo +++ /dev/null @@ -1,505 +0,0 @@ -@c The GNU Free Documentation License. -@center Version 1.3, 3 November 2008 - -@c This file is intended to be included within another document, -@c hence no sectioning command or @node. - -@display -Copyright @copyright{} 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc. -@uref{http://fsf.org/} - -Everyone is permitted to copy and distribute verbatim copies -of this license document, but changing it is not allowed. -@end display - -@enumerate 0 -@item -PREAMBLE - -The purpose of this License is to make a manual, textbook, or other -functional and useful document @dfn{free} in the sense of freedom: to -assure everyone the effective freedom to copy and redistribute it, -with or without modifying it, either commercially or noncommercially. -Secondarily, this License preserves for the author and publisher a way -to get credit for their work, while not being considered responsible -for modifications made by others. - -This License is a kind of ``copyleft'', which means that derivative -works of the document must themselves be free in the same sense. It -complements the GNU General Public License, which is a copyleft -license designed for free software. - -We have designed this License in order to use it for manuals for free -software, because free software needs free documentation: a free -program should come with manuals providing the same freedoms that the -software does. But this License is not limited to software manuals; -it can be used for any textual work, regardless of subject matter or -whether it is published as a printed book. We recommend this License -principally for works whose purpose is instruction or reference. - -@item -APPLICABILITY AND DEFINITIONS - -This License applies to any manual or other work, in any medium, that -contains a notice placed by the copyright holder saying it can be -distributed under the terms of this License. Such a notice grants a -world-wide, royalty-free license, unlimited in duration, to use that -work under the conditions stated herein. The ``Document'', below, -refers to any such manual or work. Any member of the public is a -licensee, and is addressed as ``you''. You accept the license if you -copy, modify or distribute the work in a way requiring permission -under copyright law. - -A ``Modified Version'' of the Document means any work containing the -Document or a portion of it, either copied verbatim, or with -modifications and/or translated into another language. - -A ``Secondary Section'' is a named appendix or a front-matter section -of the Document that deals exclusively with the relationship of the -publishers or authors of the Document to the Document's overall -subject (or to related matters) and contains nothing that could fall -directly within that overall subject. (Thus, if the Document is in -part a textbook of mathematics, a Secondary Section may not explain -any mathematics.) The relationship could be a matter of historical -connection with the subject or with related matters, or of legal, -commercial, philosophical, ethical or political position regarding -them. - -The ``Invariant Sections'' are certain Secondary Sections whose titles -are designated, as being those of Invariant Sections, in the notice -that says that the Document is released under this License. If a -section does not fit the above definition of Secondary then it is not -allowed to be designated as Invariant. The Document may contain zero -Invariant Sections. If the Document does not identify any Invariant -Sections then there are none. - -The ``Cover Texts'' are certain short passages of text that are listed, -as Front-Cover Texts or Back-Cover Texts, in the notice that says that -the Document is released under this License. A Front-Cover Text may -be at most 5 words, and a Back-Cover Text may be at most 25 words. - -A ``Transparent'' copy of the Document means a machine-readable copy, -represented in a format whose specification is available to the -general public, that is suitable for revising the document -straightforwardly with generic text editors or (for images composed of -pixels) generic paint programs or (for drawings) some widely available -drawing editor, and that is suitable for input to text formatters or -for automatic translation to a variety of formats suitable for input -to text formatters. A copy made in an otherwise Transparent file -format whose markup, or absence of markup, has been arranged to thwart -or discourage subsequent modification by readers is not Transparent. -An image format is not Transparent if used for any substantial amount -of text. A copy that is not ``Transparent'' is called ``Opaque''. - -Examples of suitable formats for Transparent copies include plain -ASCII without markup, Texinfo input format, La@TeX{} input -format, SGML or XML using a publicly available -DTD, and standard-conforming simple HTML, -PostScript or PDF designed for human modification. Examples -of transparent image formats include PNG, XCF and -JPG. Opaque formats include proprietary formats that can be -read and edited only by proprietary word processors, SGML or -XML for which the DTD and/or processing tools are -not generally available, and the machine-generated HTML, -PostScript or PDF produced by some word processors for -output purposes only. - -The ``Title Page'' means, for a printed book, the title page itself, -plus such following pages as are needed to hold, legibly, the material -this License requires to appear in the title page. For works in -formats which do not have any title page as such, ``Title Page'' means -the text near the most prominent appearance of the work's title, -preceding the beginning of the body of the text. - -The ``publisher'' means any person or entity that distributes copies -of the Document to the public. - -A section ``Entitled XYZ'' means a named subunit of the Document whose -title either is precisely XYZ or contains XYZ in parentheses following -text that translates XYZ in another language. (Here XYZ stands for a -specific section name mentioned below, such as ``Acknowledgements'', -``Dedications'', ``Endorsements'', or ``History''.) To ``Preserve the Title'' -of such a section when you modify the Document means that it remains a -section ``Entitled XYZ'' according to this definition. - -The Document may include Warranty Disclaimers next to the notice which -states that this License applies to the Document. These Warranty -Disclaimers are considered to be included by reference in this -License, but only as regards disclaiming warranties: any other -implication that these Warranty Disclaimers may have is void and has -no effect on the meaning of this License. - -@item -VERBATIM COPYING - -You may copy and distribute the Document in any medium, either -commercially or noncommercially, provided that this License, the -copyright notices, and the license notice saying this License applies -to the Document are reproduced in all copies, and that you add no other -conditions whatsoever to those of this License. You may not use -technical measures to obstruct or control the reading or further -copying of the copies you make or distribute. However, you may accept -compensation in exchange for copies. If you distribute a large enough -number of copies you must also follow the conditions in section 3. - -You may also lend copies, under the same conditions stated above, and -you may publicly display copies. - -@item -COPYING IN QUANTITY - -If you publish printed copies (or copies in media that commonly have -printed covers) of the Document, numbering more than 100, and the -Document's license notice requires Cover Texts, you must enclose the -copies in covers that carry, clearly and legibly, all these Cover -Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on -the back cover. Both covers must also clearly and legibly identify -you as the publisher of these copies. The front cover must present -the full title with all words of the title equally prominent and -visible. You may add other material on the covers in addition. -Copying with changes limited to the covers, as long as they preserve -the title of the Document and satisfy these conditions, can be treated -as verbatim copying in other respects. - -If the required texts for either cover are too voluminous to fit -legibly, you should put the first ones listed (as many as fit -reasonably) on the actual cover, and continue the rest onto adjacent -pages. - -If you publish or distribute Opaque copies of the Document numbering -more than 100, you must either include a machine-readable Transparent -copy along with each Opaque copy, or state in or with each Opaque copy -a computer-network location from which the general network-using -public has access to download using public-standard network protocols -a complete Transparent copy of the Document, free of added material. -If you use the latter option, you must take reasonably prudent steps, -when you begin distribution of Opaque copies in quantity, to ensure -that this Transparent copy will remain thus accessible at the stated -location until at least one year after the last time you distribute an -Opaque copy (directly or through your agents or retailers) of that -edition to the public. - -It is requested, but not required, that you contact the authors of the -Document well before redistributing any large number of copies, to give -them a chance to provide you with an updated version of the Document. - -@item -MODIFICATIONS - -You may copy and distribute a Modified Version of the Document under -the conditions of sections 2 and 3 above, provided that you release -the Modified Version under precisely this License, with the Modified -Version filling the role of the Document, thus licensing distribution -and modification of the Modified Version to whoever possesses a copy -of it. In addition, you must do these things in the Modified Version: - -@enumerate A -@item -Use in the Title Page (and on the covers, if any) a title distinct -from that of the Document, and from those of previous versions -(which should, if there were any, be listed in the History section -of the Document). You may use the same title as a previous version -if the original publisher of that version gives permission. - -@item -List on the Title Page, as authors, one or more persons or entities -responsible for authorship of the modifications in the Modified -Version, together with at least five of the principal authors of the -Document (all of its principal authors, if it has fewer than five), -unless they release you from this requirement. - -@item -State on the Title page the name of the publisher of the -Modified Version, as the publisher. - -@item -Preserve all the copyright notices of the Document. - -@item -Add an appropriate copyright notice for your modifications -adjacent to the other copyright notices. - -@item -Include, immediately after the copyright notices, a license notice -giving the public permission to use the Modified Version under the -terms of this License, in the form shown in the Addendum below. - -@item -Preserve in that license notice the full lists of Invariant Sections -and required Cover Texts given in the Document's license notice. - -@item -Include an unaltered copy of this License. - -@item -Preserve the section Entitled ``History'', Preserve its Title, and add -to it an item stating at least the title, year, new authors, and -publisher of the Modified Version as given on the Title Page. If -there is no section Entitled ``History'' in the Document, create one -stating the title, year, authors, and publisher of the Document as -given on its Title Page, then add an item describing the Modified -Version as stated in the previous sentence. - -@item -Preserve the network location, if any, given in the Document for -public access to a Transparent copy of the Document, and likewise -the network locations given in the Document for previous versions -it was based on. These may be placed in the ``History'' section. -You may omit a network location for a work that was published at -least four years before the Document itself, or if the original -publisher of the version it refers to gives permission. - -@item -For any section Entitled ``Acknowledgements'' or ``Dedications'', Preserve -the Title of the section, and preserve in the section all the -substance and tone of each of the contributor acknowledgements and/or -dedications given therein. - -@item -Preserve all the Invariant Sections of the Document, -unaltered in their text and in their titles. Section numbers -or the equivalent are not considered part of the section titles. - -@item -Delete any section Entitled ``Endorsements''. Such a section -may not be included in the Modified Version. - -@item -Do not retitle any existing section to be Entitled ``Endorsements'' or -to conflict in title with any Invariant Section. - -@item -Preserve any Warranty Disclaimers. -@end enumerate - -If the Modified Version includes new front-matter sections or -appendices that qualify as Secondary Sections and contain no material -copied from the Document, you may at your option designate some or all -of these sections as invariant. To do this, add their titles to the -list of Invariant Sections in the Modified Version's license notice. -These titles must be distinct from any other section titles. - -You may add a section Entitled ``Endorsements'', provided it contains -nothing but endorsements of your Modified Version by various -parties---for example, statements of peer review or that the text has -been approved by an organization as the authoritative definition of a -standard. - -You may add a passage of up to five words as a Front-Cover Text, and a -passage of up to 25 words as a Back-Cover Text, to the end of the list -of Cover Texts in the Modified Version. Only one passage of -Front-Cover Text and one of Back-Cover Text may be added by (or -through arrangements made by) any one entity. If the Document already -includes a cover text for the same cover, previously added by you or -by arrangement made by the same entity you are acting on behalf of, -you may not add another; but you may replace the old one, on explicit -permission from the previous publisher that added the old one. - -The author(s) and publisher(s) of the Document do not by this License -give permission to use their names for publicity for or to assert or -imply endorsement of any Modified Version. - -@item -COMBINING DOCUMENTS - -You may combine the Document with other documents released under this -License, under the terms defined in section 4 above for modified -versions, provided that you include in the combination all of the -Invariant Sections of all of the original documents, unmodified, and -list them all as Invariant Sections of your combined work in its -license notice, and that you preserve all their Warranty Disclaimers. - -The combined work need only contain one copy of this License, and -multiple identical Invariant Sections may be replaced with a single -copy. If there are multiple Invariant Sections with the same name but -different contents, make the title of each such section unique by -adding at the end of it, in parentheses, the name of the original -author or publisher of that section if known, or else a unique number. -Make the same adjustment to the section titles in the list of -Invariant Sections in the license notice of the combined work. - -In the combination, you must combine any sections Entitled ``History'' -in the various original documents, forming one section Entitled -``History''; likewise combine any sections Entitled ``Acknowledgements'', -and any sections Entitled ``Dedications''. You must delete all -sections Entitled ``Endorsements.'' - -@item -COLLECTIONS OF DOCUMENTS - -You may make a collection consisting of the Document and other documents -released under this License, and replace the individual copies of this -License in the various documents with a single copy that is included in -the collection, provided that you follow the rules of this License for -verbatim copying of each of the documents in all other respects. - -You may extract a single document from such a collection, and distribute -it individually under this License, provided you insert a copy of this -License into the extracted document, and follow this License in all -other respects regarding verbatim copying of that document. - -@item -AGGREGATION WITH INDEPENDENT WORKS - -A compilation of the Document or its derivatives with other separate -and independent documents or works, in or on a volume of a storage or -distribution medium, is called an ``aggregate'' if the copyright -resulting from the compilation is not used to limit the legal rights -of the compilation's users beyond what the individual works permit. -When the Document is included in an aggregate, this License does not -apply to the other works in the aggregate which are not themselves -derivative works of the Document. - -If the Cover Text requirement of section 3 is applicable to these -copies of the Document, then if the Document is less than one half of -the entire aggregate, the Document's Cover Texts may be placed on -covers that bracket the Document within the aggregate, or the -electronic equivalent of covers if the Document is in electronic form. -Otherwise they must appear on printed covers that bracket the whole -aggregate. - -@item -TRANSLATION - -Translation is considered a kind of modification, so you may -distribute translations of the Document under the terms of section 4. -Replacing Invariant Sections with translations requires special -permission from their copyright holders, but you may include -translations of some or all Invariant Sections in addition to the -original versions of these Invariant Sections. You may include a -translation of this License, and all the license notices in the -Document, and any Warranty Disclaimers, provided that you also include -the original English version of this License and the original versions -of those notices and disclaimers. In case of a disagreement between -the translation and the original version of this License or a notice -or disclaimer, the original version will prevail. - -If a section in the Document is Entitled ``Acknowledgements'', -``Dedications'', or ``History'', the requirement (section 4) to Preserve -its Title (section 1) will typically require changing the actual -title. - -@item -TERMINATION - -You may not copy, modify, sublicense, or distribute the Document -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense, or distribute it is void, and -will automatically terminate your rights under this License. - -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, receipt of a copy of some or all of the same material does -not give you any rights to use it. - -@item -FUTURE REVISIONS OF THIS LICENSE - -The Free Software Foundation may publish new, revised versions -of the GNU Free Documentation 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. See -@uref{http://www.gnu.org/copyleft/}. - -Each version of the License is given a distinguishing version number. -If the Document specifies that a particular numbered version of this -License ``or any later version'' applies to it, you have the option of -following the terms and conditions either of that specified version or -of any later version that has been published (not as a draft) by the -Free Software Foundation. If the Document does not specify a version -number of this License, you may choose any version ever published (not -as a draft) by the Free Software Foundation. If the Document -specifies that a proxy can decide which future versions of this -License can be used, that proxy's public statement of acceptance of a -version permanently authorizes you to choose that version for the -Document. - -@item -RELICENSING - -``Massive Multiauthor Collaboration Site'' (or ``MMC Site'') means any -World Wide Web server that publishes copyrightable works and also -provides prominent facilities for anybody to edit those works. A -public wiki that anybody can edit is an example of such a server. A -``Massive Multiauthor Collaboration'' (or ``MMC'') contained in the -site means any set of copyrightable works thus published on the MMC -site. - -``CC-BY-SA'' means the Creative Commons Attribution-Share Alike 3.0 -license published by Creative Commons Corporation, a not-for-profit -corporation with a principal place of business in San Francisco, -California, as well as future copyleft versions of that license -published by that same organization. - -``Incorporate'' means to publish or republish a Document, in whole or -in part, as part of another Document. - -An MMC is ``eligible for relicensing'' if it is licensed under this -License, and if all works that were first published under this License -somewhere other than this MMC, and subsequently incorporated in whole -or in part into the MMC, (1) had no cover texts or invariant sections, -and (2) were thus incorporated prior to November 1, 2008. - -The operator of an MMC Site may republish an MMC contained in the site -under CC-BY-SA on the same site at any time before August 1, 2009, -provided the MMC is eligible for relicensing. - -@end enumerate - -@page -@heading ADDENDUM: How to use this License for your documents - -To use this License in a document you have written, include a copy of -the License in the document and put the following copyright and -license notices just after the title page: - -@smallexample -@group - Copyright (C) @var{year} @var{your name}. - Permission is granted to copy, distribute and/or modify this document - under the terms of the GNU Free Documentation License, Version 1.3 - or any later version published by the Free Software Foundation; - with no Invariant Sections, no Front-Cover Texts, and no Back-Cover - Texts. A copy of the license is included in the section entitled ``GNU - Free Documentation License''. -@end group -@end smallexample - -If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, -replace the ``with@dots{}Texts.''@: line with this: - -@smallexample -@group - with the Invariant Sections being @var{list their titles}, with - the Front-Cover Texts being @var{list}, and with the Back-Cover Texts - being @var{list}. -@end group -@end smallexample - -If you have Invariant Sections without Cover Texts, or some other -combination of the three, merge those two alternatives to suit the -situation. - -If your document contains nontrivial examples of program code, we -recommend releasing these examples in parallel under your choice of -free software license, such as the GNU General Public License, -to permit their use in free software. - -@c Local Variables: -@c ispell-local-pdict: "ispell-dict" -@c End: diff --git a/doc/info/appx/free-software-needs-free-documentation.texinfo b/doc/info/appx/free-software-needs-free-documentation.texinfo deleted file mode 100644 index 8800993..0000000 --- a/doc/info/appx/free-software-needs-free-documentation.texinfo +++ /dev/null @@ -1,31 +0,0 @@ -@node Free Software Needs Free Documentation -@appendix Free Software Needs Free Documentation - -@indent -@i{The following article was written by Richard Stallman, founder of the GNU Project.} -@* - -@noindent -The biggest deficiency in the free software community today is not in the software --- it is the lack of good free documentation that we can include with the free software. Many of our most important programs do not come with free reference manuals and free introductory texts. Documentation is an essential part of any software package; when an important free software package does not come with a free manual and a free tutorial, that is a major gap. We have many such gaps today. - -Consider Perl, for instance. The tutorial manuals that people normally use are non-free. How did this come about? Because the authors of those manuals published them with restrictive terms --- no copying, no modification, source files not available --- which exclude them from the free software world. - -That wasn't the first time this sort of thing happened, and it was far from the last. Many times we have heard a @sc{GNU} user eagerly describe a manual that he is writing, his intended contribution to the community, only to learn that he had ruined everything by signing a publication contract to make it non-free. - -Free documentation, like free software, is a matter of freedom, not price. The problem with the non-free manual is not that publishers charge a price for printed copies --- that in itself is fine. (The Free Software Foundation sells printed copies of manuals, too.) The problem is the restrictions on the use of the manual. Free manuals are available in source code form, and give you permission to copy and modify. Non-free manuals do not allow this. - -The criteria of freedom for a free manual are roughly the same as for free software. Redistribution (including the normal kinds of commercial redistribution) must be permitted, so that the manual can accompany every copy of the program, both on-line and on paper. - -Permission for modification of the technical content is crucial too. When people modify the software, adding or changing features, if they are conscientious they will change the manual too --- so they can provide accurate and clear documentation for the modified program. A manual that leaves you no choice but to write a new manual to document a changed version of the program is not really available to our community. - -Some kinds of limits on the way modification is handled are acceptable. For example, requirements to preserve the original author's copyright notice, the distribution terms, or the list of authors, are ok. It is also no problem to require modified versions to include notice that they were modified. Even entire sections that may not be deleted or changed are acceptable, as long as they deal with nontechnical topics (like this one). These kinds of restrictions are acceptable because they don't obstruct the community's normal use of the manual. - -However, it must be possible to modify all the technical content of the manual, and then distribute the result in all the usual media, through all the usual channels. Otherwise, the restrictions obstruct the use of the manual, it is not free, and we need another manual to replace it. - -Please spread the word about this issue. Our community continues to lose manuals to proprietary publishing. If we spread the word that free software needs free reference manuals and free tutorials, perhaps the next person who wants to contribute by writing documentation will realize, before it is too late, that only free manuals contribute to the free software community. - -If you are writing documentation, please insist on publishing it under the @sc{GNU} Free Documentation License or another free documentation license. Remember that this decision requires your approval --- you don't have to let the publisher decide. Some commercial publishers will use a free license if you insist, but they will not propose the option; it is up to you to raise the issue and say firmly that this is what you want. If the publisher you are dealing with refuses, please try other publishers. If you're not sure whether a proposed license is free, write to licensing@@gnu.org. - -You can encourage commercial publishers to sell more free, copylefted manuals and tutorials by buying them, and particularly by buying copies from the publishers that paid for their writing or for major improvements. Meanwhile, try to avoid buying non-free documentation at all. Check the distribution terms of a manual before you buy it, and insist that whoever seeks your business must respect your freedom. Check the history of the book, and try reward the publishers that have paid or pay the authors to work on it. - -The Free Software Foundation maintains a list of free documentation published by other publishers, at @url{http://www.fsf.org/doc/other-free-books.html}. diff --git a/doc/info/appx/gpl.texinfo b/doc/info/appx/gpl.texinfo deleted file mode 100644 index c773b1d..0000000 --- a/doc/info/appx/gpl.texinfo +++ /dev/null @@ -1,717 +0,0 @@ -@c The GNU General Public License. -@center Version 3, 29 June 2007 - -@c This file is intended to be included within another document, -@c hence no sectioning command or @node. - -@display -Copyright @copyright{} 2007 Free Software Foundation, Inc. @url{http://fsf.org/} - -Everyone is permitted to copy and distribute verbatim copies of this -license document, but changing it is not allowed. -@end display - -@heading 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. - -@heading TERMS AND CONDITIONS - -@enumerate 0 -@item 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. - -@item 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. - -@item 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. - -@item 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. - -@item 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. - -@item 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: - -@enumerate a -@item -The work must carry prominent notices stating that you modified it, -and giving a relevant date. - -@item -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''. - -@item -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. - -@item -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. -@end enumerate - -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. - -@item 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: - -@enumerate a -@item -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. - -@item -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. - -@item -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. - -@item -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. - -@item -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. - -@end enumerate - -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. - -@item 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: - -@enumerate a -@item -Disclaiming warranty or limiting liability differently from the terms -of sections 15 and 16 of this License; or - -@item -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 - -@item -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 - -@item -Limiting the use for publicity purposes of names of licensors or -authors of the material; or - -@item -Declining to grant rights under trademark law for use of some trade -names, trademarks, or service marks; or - -@item -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. -@end enumerate - -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. - -@item 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. - -@item 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. - -@item 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. - -@item 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. - -@item 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. - -@item 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. - -@item 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. - -@item 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@. - -@item 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@. - -@item 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 enumerate - -@heading END OF TERMS AND CONDITIONS - -@heading 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. - -@smallexample -@var{one line to give the program's name and a brief idea of what it does.} -Copyright (C) @var{year} @var{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 @url{http://www.gnu.org/licenses/}. -@end smallexample - -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: - -@smallexample -@var{program} Copyright (C) @var{year} @var{name of author} -This program comes with ABSOLUTELY NO WARRANTY; for details type @samp{show w}. -This is free software, and you are welcome to redistribute it -under certain conditions; type @samp{show c} for details. -@end smallexample - -The hypothetical commands @samp{show w} and @samp{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 -@url{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 @url{http://www.gnu.org/philosophy/why-not-lgpl.html}. diff --git a/doc/info/chap/clut-manipulation.texinfo b/doc/info/chap/clut-manipulation.texinfo deleted file mode 100644 index 99fc0f0..0000000 --- a/doc/info/chap/clut-manipulation.texinfo +++ /dev/null @@ -1,477 +0,0 @@ -@node CLUT Manipulation -@chapter CLUT Manipulation - -@command{libclut} has a number of function-like macros -for manipulating colour lookup tables. These have -3 common initial parameters, that describe the -colour lookup table that shall be manipulated. -@table @code -@item clut -Pointer to the gamma ramps. This must be a pointer -to an instance of a @code{struct} that must at least -have the array members @code{red}, @code{green}, and -@code{blue}, whose elements shall be of the type -specified by the parameter @code{type}. The @code{struct} -must also have the scalar members @code{red_size}, -@code{green_size}, and @code{blue_size}, and shall be -of the type @code{size_t}; they shall specify the -number of stops (elements) in the arrays @code{.red}, -@code{.green}, and @code{.blue}, respectively, which -shall be the gamma ramp for the ``red''@footnote{Acutally -orange.}, green, and blue channels respectively. -@item max -The maximum value on each stop in the ramps. -@item type -The data type used for each stop in the ramps. -@end table -@noindent -Additionally, these macros do not allow that arguments -have side-effects.@footnote{Some macros currently allow -side-effects on some parameters, but this may change -in the future.} None, if the macros have a return value. - -@table @code -@item libclut_rgb_contrast(clut, max, type, r, g, b) -Apply contrast correction on the colour curves using sRGB. - -In this context, contrast is a measure of difference between -the whitepoint and blackpoint, if the difference is 0 than -they are both grey. - -Parameters: -@table @code -@item r -The contrast parameter for the red curve. -@item g -The contrast parameter for the green curve. -@item b -The contrast parameter for the blue curve. -@end table - - -@item libclut_cie_contrast(clut, max, type, r, g, b) -Apply contrast correction on the colour curves using CIE xyY. - -In this context, contrast is a measure of difference between -the whitepoint and blackpoint, if the difference is 0 than -they are both grey. - -Requires linking with @option{-lclut}. - -Parameters: -@table @code -@item r -The contrast parameter for the red curve. -@item g -The contrast parameter for the green curve. -@item b -The contrast parameter for the blue curve. -@end table - - -@item libclut_rgb_brightness(clut, max, type, r, g, b) -Apply brightness correction on the colour curves using sRGB. - -In this context, brightness is a measure of the whiteness -of the whitepoint. - -Parameters: -@table @code -@item r -The brightness parameter for the red curve. -@item g -The brightness parameter for the green curve. -@item b -The brightness parameter for the blue curve. -@end table - - -@item libclut_cie_brightness(clut, max, type, r, g, b) -Apply brightness correction on the colour curves using CIE xyY. - -In this context, brightness is a measure of the whiteness -of the whitepoint. - -Requires linking with @option{-lclut}. - -Parameters: -@table @code -@item r -The brightness parameter for the red curve. -@item g -The brightness parameter for the green curve. -@item b -The brightness parameter for the blue curve. -@end table - - -@item libclut_linearise(clut, max, type, r, g, b) -Convert the curves from formatted in standard RGB to linear RGB. - -Requires linking with @option{-lclut}, or @option{-lm} if -@code{libclut_model_standard_to_linear1} is not undefined. - -Parameters: -@table @code -@item r -Whether to convert the red colour curve. -@item g -Whether to convert the green colour curve. -@item b -Whether to convert the blue colour curve. -@end table - - -@item libclut_standardise(clut, max, type, r, g, b) -Convert the curves from formatted in linear RGB to standard RGB. - -Requires linking with @option{-lclut}, or @option{-lm} if -@code{libclut_model_linear_to_standard1} is not undefined. - -Parameters: -@table @code -@item r -Whether to convert the red colour curve. -@item g -Whether to convert the green colour curve. -@item b -Whether to convert the blue colour curve. -@end table - - -@item libclut_gamma(clut, max, type, r, g, b) -Apply gamma correction on the colour curves. - -Requires linking with @option{-lm}. - -Parameters: -@table @code -@item r -The gamma parameter for the red curve. -@item g -The gamma parameter for the green curve. -@item b -The gamma parameter for the blue curve. -@end table - - -@item libclut_negative(clut, max, type, r, g, b) -Reverse the colour curves (negative image with gamma preservation.) - -Parameters: -@table @code -@item r -Whether to reverse the red colour curve. -@item g -Whether to reverse the green colour curve. -@item b -Whether to reverse the blue colour curve. -@end table - - -@item libclut_rgb_invert(clut, max, type, r, g, b) -Invert the colour curves (negative image with gamma -invertion), using sRGB. - -Parameters: -@table @code -@item r -Whether to invert the red colour curve. -@item g -Whether to invert the green colour curve. -@item b -Whether to invert the blue colour curve. -@end table - - -@item libclut_cie_invert(clut, max, type, r, g, b) -Invert the colour curves (negative image with gamma -invertion), using CIE xyY. - -Requires linking with @option{-lclut}. - -Parameters: -@table @code -@item r -Whether to invert the red colour curve. -@item g -Whether to invert the green colour curve. -@item b -Whether to invert the blue colour curve. -@end table - - -@item libclut_sigmoid(clut, max, type, rp, gp, bp) -Apply S-curve correction on the colour curves. -This is intended for fine tuning LCD monitors, -4.5 is good value start start testing at. -You would probably like to use @code{rgb_limits} -before this to adjust the blackpoint as that is -the only way to adjust the blackpoint on many LCD -monitors. - -Requires linking with @option{-lm}. - -Parameters: -@table @code -@item rp -Pointer to the sigmoid parameter for the red curve. -@code{NULL} for no adjustment. -@item gp -Pointer to the sigmoid parameter for the green curve. -@code{NULL} for no adjustment. -@item bp -Pointer to the sigmoid parameter for the blue curve. -@code{NULL} for no adjustment. -@end table - - -@item libclut_rgb_limits(clut, max, type, rmin, rmax, gmin, gmax, bmin, bmax) -Changes the blackpoint and the whitepoint, using sRGB. - -Parameters: -@table @code -@item rmin -The red component value of the blackpoint. -That is, the brightness on the red channel. -@item rmax -The red component value of the whitepoint. -That is, the contrast on the red channel. -@item gmin -The green component value of the blackpoint. -That is, the brightness on the green channel. -@item gmax -The green component value of the whitepoint. -That is, the contrast on the green channel. -@item bmin -The blue component value of the blackpoint. -That is, the brightness on the blue channel. -@item bmax -The blue component value of the whitepoint. -That is, the contrast on the blue channel. -@end table - - -@item libclut_cie_limits(clut, max, type, rmin, rmax, gmin, gmax, bmin, bmax) -Changes the blackpoint and the whitepoint, using CIE xyY. - -Requires linking with @option{-lclut}. - -Parameters: -@table @code -@item rmin -The red component value of the blackpoint. -That is, the brightness on the red channel. -@item rmax -The red component value of the whitepoint. -That is, the contrast on the red channel. -@item gmin -The green component value of the blackpoint. -That is, the brightness on the green channel. -@item gmax -The green component value of the whitepoint. -That is, the contrast on the green channel. -@item bmin -The blue component value of the blackpoint. -That is, the brightness on the blue channel. -@item bmax -The blue component value of the whitepoint. -That is, the contrast on the blue channel. -@end table - - -@item libclut_manipulate(clut, max, type, r, g, b) -Manipulate the colour curves using a function on the -sRGB colour space. - -Parameters: -@table @code -@item r -Function to manipulate the red colour curve. It -shall map from old stop values to new stop values. -This should either be @code{NULL} for no manipulation, -or a function that maps from @code{double} to -@code{double}. 0 % and 100 % is encoded as 0 and 1, -respectively, in both input and ouput. Its signature -should be @code{double (*)(double)}. -@item g -Function to manipulate the green colour curve. It -shall map from old stop values to new stop values. -This should either be @code{NULL} for no manipulation, -or a function that maps from @code{double} to -@code{double}. 0 % and 100 % is encoded as 0 and 1, -respectively, in both input and ouput. Its signature -should be @code{double (*)(double)}. -@item b -Function to manipulate the blue colour curve. It -shall map from old stop values to new stop values. -This should either be @code{NULL} for no manipulation, -or a function that maps from @code{double} to -@code{double}. 0 % and 100 % is encoded as 0 and 1, -respectively, in both input and ouput. Its signature -should be @code{double (*)(double)}. -@end table - - -@item libclut_cie_manipulate(clut, max, type, r, g, b) -Manipulate the colour curves using a function on the -CIE xyY colour space. - -Requires linking with @option{-lclut}. - -Parameters: -@table @code -@item r -Function to manipulate the red colour curve. It -shall map from old stop values to new stop values. -This should either be @code{NULL} for no manipulation, -or a function that maps from @code{double} to -@code{double}. 0 % and 100 % is encoded as 0 and 1, -respectively, in both input and ouput. Its signature -should be @code{double (*)(double)}. -@item g -Function to manipulate the green colour curve. It -shall map from old stop values to new stop values. -This should either be @code{NULL} for no manipulation, -or a function that maps from @code{double} to -@code{double}. 0 % and 100 % is encoded as 0 and 1, -respectively, in both input and ouput. Its signature -should be @code{double (*)(double)}. -@item b -Function to manipulate the blue colour curve. It -shall map from old stop values to new stop values. -This should either be @code{NULL} for no manipulation, -or a function that maps from @code{double} to -@code{double}. 0 % and 100 % is encoded as 0 and 1, -respectively, in both input and ouput. Its signature -should be @code{double (*)(double)}. -@end table - - -@item libclut_start_over(clut, max, type, r, g, b) -Resets colour curvers to linear mappings. -(Identity mapping if imaginged to map from [0, 1] to [0, 1].) - -Parameters: -@table @code -@item r -Whether to reset the red colour curve. -@item g -Whether to reset the green colour curve. -@item b -Whether to reset the blue colour curve. -@end table - - -@item libclut_clip(clut, max, type, r, g, b) -Clip colour curves to only map to values between the -minimum and maximum. This should be done, before apply -the curves, and before applying changes with limited -domain. - -Values below 0 are set to 0, and values above @code{max} -are set to @code{max}. - -Parameters: -@table @code -@item r -Whether to clip the red colour curve. -@item g -Whether to clip the green colour curve. -@item b -Whether to clip the blue colour curve. -@end table - - -@item libclut_lower_resolution(clut, max, type, rx, ry, gx, gy, bx, by) -Emulates low colour resolution. - -Parameters: -@table @code -@item rx -The desired emulated red encoding resolution, -0 for unchanged. -@item ry -The desired emulated red output resolution, -0 for unchanged. -@item gx -The desired emulated green encoding resolution, -0 for unchanged. -@item gy -The desired emulated green output resolution, -0 for unchanged. -@item bx -The desired emulated blue encoding resolution, -0 for unchanged. -@item by -The desired emulated blue output resolution, -0 for unchanged. -@end table - - -@item libclut_apply(clut, max, type, filter, fmax, ftype, r, g, b) -Applies a filter or calibration. - -Parameters: -@table @code -@item filter -Same as @code{clut}, but for the filter to apply. -@item fmax -Same as @code{max}, but for the filter to apply. -@item ftype -Same as @code{type}, but for the filter to apply. -(Not actually used.) -@item r -Whether to apply the filter for the red curve. -@item g -Whether to apply the filter for the green curve. -@item b -Whether to apply the filter for the blue curve. -@end table - - -@item libclut_cie_apply(clut, max, type, filter, fmax, ftype, r, g, b) -Applies a filter or calibration, using CIE xyY. - -Requires linking with @option{-lclut}. - -Parameters: -@table @code -@item filter -Same as @code{clut}, but for the filter to apply. -@item fmax -Same as @code{max}, but for the filter to apply. -@item ftype -Same as @code{type}, but for the filter to apply. -(Not actually used.) -@item r -Whether to apply the filter for the red curve. -@item g -Whether to apply the filter for the green curve. -@item b -Whether to apply the filter for the blue curve. -@end table - - -@item libclut_translate(dclut, dmax, dtype, sclut, smax, stype) -Translates a gamma ramp structure to another -gamma ramp structure type. - -Parameters: -@table @code -@item dclut -Like @code{clut} described above, for the destination. -@item dmax -Like @code{max} described above, for the destination. -@item dtype -Like @code{type} described above, for the destination. -@item sclut -Like @code{clut} described above, for the source. -@item smax -Like @code{max} described above, for the source. -@item stype -Like @code{type} described above, for the source. -(Not actually used.) -@end table -@end table - diff --git a/doc/info/chap/colour-spaces.texinfo b/doc/info/chap/colour-spaces.texinfo deleted file mode 100644 index 89e7677..0000000 --- a/doc/info/chap/colour-spaces.texinfo +++ /dev/null @@ -1,1139 +0,0 @@ -@node Colour Spaces -@chapter Colour Spaces - -@menu -* RGB Conversion:: RGB colour space conversion functions. -@end menu - - -@command{libclut} has a number of functions for converting -between colour space models. The supported colour space models -are [0, 1] sRGB, [0, 1] linear sRGB, CIE xyY, CIE XYZ, CIE L*a*b*, -CIE 1976 (L*, u*, v*), CIELCh@sub{uv}, YIQ, YD@sub{b}D@sub{r}, -YP@sub{b}P@sub{r}, YCgCo, CIE 1960 USC, CIE U*V*W*, - -These functions are implemented as macros, but regular functions -are available either by putting the name in the function is -brackets, taking the address of the function, or by undefining -the macro with the name of the function. - -@command{libclut} has two functions intended for internal use. -If the macro verions are used, their parameter must not have -any side-effets. Additionally their macro versions require -linking with @option{-lm}. - -@table @code -@item double libclut_model_linear_to_standard1(double c) -Convert one component from [0, 1] linear sRGB to [0, 1] sRGB. -@item double libclut_model_standard_to_linear1(double c) -Convert one component from [0, 1] sRGB to [0, 1] linear sRGB. -@end table - -@command{libclut} has ten functions that are intended for the -user to use, but some are used internally too. These functions' -parameters may have side-effects. All parameters are of the -type @code{double}, and they do not have a return value. - -@table @code -@item libclut_model_linear_to_standard(*r. *g, *b) -Convert [0, 1] linear sRGB to [0, 1] sRGB. - -The macro variant requires linking with @option{-lm}, if -the @code{libclut_model_linear_to_standard1} is defined, -otherwise it requires linking with @option{-lclut}. - -Parameters: -@table @code -@item r -Pointer to the linear red component, and output parameter -for the red component. -@item g -Pointer to the linear green component, and output parameter -for the green component. -@item b -Pointer to the linear blue component, and output parameter -for the blue component. -@end table - - -@item libclut_model_standard_to_linear(*r, *g, *b) -Convert [0, 1] sRGB to [0, 1] linear sRGB. - -The macro variant requires linking with @option{-lm}, if -the @code{libclut_model_standard_to_linear1} is defined, -otherwise it requires linking with @option{-lclut}. - -Parameters: -@table @code -@item r -Pointer to the red component, and output parameter for the -linear red component. -@item g -Pointer to the green component, and output parameter for the -linear green component. -@item b -Pointer to the blue component, and output parameter for the -linear blue component. -@end table - - -@item libclut_model_ciexyy_to_ciexyz(x, y, Y, *X, *Z) -Convert CIE xyY to CIE XYZ. - -Parameters: -@table @code -@item x -The x parameter. -@item y -The y parameter. -@item Y -The Y parameter. This is also the Y (middle) parameter -for the CIE XYZ colour. -@item X -Output parameter for the X parameter. -@item Z -Output parameter for the Z parameter. -@end table - - -@item libclut_model_ciexyz_to_ciexyy(X, Y, Z, *x, *y) -Convert CIE XYZ to CIE xyY. - -Parameters: -@table @code -@item X -The X parameter. -@item Y -The Y parameter. This is also the Y (last) parameter -for the CIE xyY colour. -@item Z -The Z parameter. -@item x -Output parameter for the x parameter. -@item y -Output parameter for the y parameter. -@end table - - -@item libclut_model_ciexyz_to_linear(X, Y, Z, *r, *g, *b) -Convert CIE XYZ to [0, 1] linear sRGB. - -Parameters: -@table @code -@item X -The X parameter. -@item Y -The Y parameter. -@item Z -The Z parameter. -@item r -Output parameter for the red component. -@item g -Output parameter for the green component. -@item b -Output parameter for the blue component. -@end table - - -@item libclut_model_linear_to_ciexyz(r, g, b, *X, *Y, *Z) -Convert [0, 1] linear sRGB to CIE XYZ. - -Parameters: -@table @code -@item r -The red component. -@item g -The green component. -@item b -The blue component. -@item X -Output parameter for the X parameter. -@item Y -Output parameter for the Y parameter. -@item Z -Output parameter for the Z parameter. -@end table - - -@item libclut_model_srgb_to_ciexyy(r, g, b, *x, *y, *Y) -Convert [0, 1] linear sRGB to CIE xyY. - -The macro variant requires linking with @option{-lclut} -if any of @code{libclut_model_ciexyz_to_ciexyy}, -@code{libclut_model_linear_to_ciexyz}, and -@code{libclut_model_standard_to_linear} are undefined. -The macro variant requires linking with @option{-lm} if -neither @code{libclut_model_standard_to_linear} nor -@code{libclut_model_standard_to_linear1} are undefined. - -Parameters: -@table @code -@item r -The red component. -@item g -The green component. -@item b -The blue component. -@item x -Output parameter for the x parameter. -@item y -Output parameter for the y parameter. -@item Y -Output parameter for the Y parameter. -@end table - - -@item libclut_model_ciexyy_to_srgb(x, y, Y, *r, *g, *b) -Convert CIE xyY to [0, 1] sRGB. - -The macro variant requires linking with @option{-lclut} -if any of @code{libclut_model_ciexyy_to_ciexyz}, -@code{libclut_model_ciexyz_to_linear}, and -@code{libclut_model_linear_to_standard} are undefined. -The macro variant requires linking with @option{-lm} if -neither @code{libclut_model_linear_to_standard} nor -@code{libclut_model_linear_to_standard1} are undefined. - -Parameters: -@table @code -@item x -The x parameter. -@item y -The y parameter. -@item Y -The Y parameter. -@item r -Output parameter for the red component. -@item g -Output parameter for the green component. -@item b -Output parameter for the blue component. -@end table - - -@item libclut_model_ciexyz_to_cielab(X, Y, Z, *L, *a, *b) -Convert from CIE XYZ to CIE L*a*b*. - -The macro variant requires linking with @option{-lm}. - -Parameters: -@table @code -@item X -The X parameter. -@item Y -The Y parameter. -@item Z -The Z parameter. -@item L -Output parameter for the L* component. -@item a -Output parameter for the a* component. -@item b -Output parameter for the b* component. -@end table - - -@item libclut_model_cielab_to_ciexyz(L, a, b, *X, *Y, *Z) -Convert from CIE L*a*b* to CIE XYZ. - -Parameters: -@table @code -@item L -The L* component. -@item a -The a* component. -@item b -The b* component. -@item X -Output parameter for the X parameter. -@item Y -Output parameter for the Y parameter. -@item Z -Output parameter for the Z parameter. -@end table - - -@item libclut_model_ciexyz_to_cieluv(X, Y, Z, Xn, Yn, Zn, *L, *u, *v) -Convert from CIE XYZ to CIE 1976 (L*, u*, v*). - -The macro variant requires linking with @option{-lm}. - -Parameters: -@table @code -@item L -The X component. -@item a -The Y component. -@item b -The Z component. -@item Xn -The X component of the specified white object (white point). -@item Yn -The Y component of the specified white object (white point). -@item Zn -The Z component of the specified white object (white point). -@item X -Output parameter for the L* parameter. -@item Y -Output parameter for the u* parameter. -@item Z -Output parameter for the v* parameter. -@end table - - -@item libclut_model_cieluv_to_ciexyz(L, u, v, Xn, Yn, Zn, *X, *Y, *Z) -Convert from CIE 1976 (L*, u*, v*) to CIE XYZ. - -Parameters: -@table @code -@item L -The L* component. -@item a -The u* component. -@item b -The v* component. -@item Xn -The X component of the specified white object (white point). -@item Yn -The Y component of the specified white object (white point). -@item Zn -The Z component of the specified white object (white point). -@item X -Output parameter for the X parameter. -@item Y -Output parameter for the Y parameter. -@item Z -Output parameter for the Z parameter. -@end table - - -@item libclut_model_cielch_to_cieluv(C, h, *u, *v) -Convert from CIE LCh@sub{uv} to CIE 1976 (L*, u*, v*). - -The L* component remains unchanged. - -The macro variant requires linking with @option{-lm}. - -Parameters: -@table @code -@item C -The C*@sub{uv} component. -@item h -The h@sub{uv} component. -@item u -Output parameter for the u* parameter. -@item v -Output parameter for the v* parameter. -@end table - - -@item libclut_model_cieluv_to_cielch(u, v, *C, *h) -Convert from CIE 1976 (L*, u*, v*) to CIE LCh@sub{uv}. - -The L* component remains unchanged. - -The macro variant requires linking with @option{-lm}. - -Parameters: -@table @code -@item a -The u* component. -@item b -The v* component. -@item C -Output parameter for the C*@sub{uv} parameter. -@item h -Output parameter for the h@sub{uv} parameter. -@end table - - -@item libclut_model_srgb_to_yiq(r, g, b, *Y, *I, *Q) -Convert from [0, 1] sRGB to YIQ. - -The macro variant requires linking with @option{-lm}, -or if @option{-lclut} if the macro -@code{libclut_model_standard_to_linear1} has been -undefined. - -Parameters: -@table @code -@item r -The red component. -@item g -The green component. -@item b -The blue component. -@item Y -Output parameter for the Y parameter. -@item I -Output parameter for the I parameter. -@item Q -Output parameter for the Q parameter. -@end table - - -@item libclut_model_yiq_to_srgb(Y, I, Q, *r, *g, *b) -Convert from YIQ to [0, 1] sRGB. - -The macro variant requires linking with @option{-lm}, -or if @option{-lclut} if the macro -@code{libclut_model_linear_to_standard1} has been -undefined. - -Parameters: -@table @code -@item Y -The Y component. -@item I -The I component. -@item Q -The Q component. -@item r -Output parameter for the red parameter. -@item g -Output parameter for the green parameter. -@item b -Output parameter for the blue parameter. -@end table - - -@item libclut_model_srgb_to_ydbdr(r, g, b, *Y, *Db, *Dr) -Convert from [0, 1] sRGB to YD@sub{b}D@sub{r}. - -The macro variant requires linking with @option{-lm}, -or if @option{-lclut} if the macro -@code{libclut_model_standard_to_linear1} has been -undefined. - -Parameters: -@table @code -@item r -The red component. -@item g -The green component. -@item b -The blue component. -@item Y -Output parameter for the Y parameter. -@item Db -Output parameter for the D@sub{b} parameter. -@item Dr -Output parameter for the D@sub{r} parameter. -@end table - - -@item libclut_model_ydbdr_to_srgb(Y, Db, Dr, *r, *g, *b) -Convert from YD@sub{b}D@sub{r} to [0, 1] sRGB. - -The macro variant requires linking with @option{-lm}, -or if @option{-lclut} if the macro -@code{libclut_model_linear_to_standard1} has been -undefined. - -Parameters: -@table @code -@item Y -The Y component. -@item Db -The D@sub{b} component. -@item Dr -The D@sub{r} component. -@item r -Output parameter for the red parameter. -@item g -Output parameter for the green parameter. -@item b -Output parameter for the blue parameter. -@end table - - -@item libclut_model_yuv_to_ydbdr(U, V, *Db, *Dr) -Convert from YUV to YD@sub{b}D@sub{r}. - -The Y component remains unchanged. - -Parameters: -@table @code -@item Y -The U component. -@item V -The V component. -@item Db -Output parameter for the D@sub{b} parameter. -@item Dr -Output parameter for the D@sub{r} parameter. -@end table - - -@item libclut_model_ydbdr_to_yuv(Db, Dr, *U, *V) -Convert from YD@sub{b}D@sub{r} to YUV. - -The Y component remains unchanged. - -Parameters: -@table @code -@item Db -The D@sub{b} component. -@item Dr -The D@sub{r} component. -@item U -Output parameter for the U parameter. -@item V -Output parameter for the V parameter. -@end table - - -@item libclut_model_srgb_to_ypbpr(r, g, b, *Y, *Pb, *Pr) -Convert from [0, 1] sRGB to YP@sub{b}P@sub{r}. - -The macro variant requires linking with @option{-lm}, -or if @option{-lclut} if the macro -@code{libclut_model_standard_to_linear1} has been -undefined. - -Parameters: -@table @code -@item r -The red component. -@item g -The green component. -@item b -The blue component. -@item Y -Output parameter for the Y parameter. -@item Pb -Output parameter for the P@sub{b} parameter. -@item Pr -Output parameter for the P@sub{r} parameter. -@end table - - -@item libclut_model_ypbpr_to_srgb(Y, Pb, Pr, *r, *g, *b) -Convert from YP@sub{b}P@sub{r} to [0, 1] sRGB. - -The macro variant requires linking with @option{-lm}, -or if @option{-lclut} if the macro -@code{libclut_model_linear_to_standard1} has been -undefined. - -Parameters: -@table @code -@item Y -The Y component. -@item Pb -The P@sub{b} component. -@item Pr -The P@sub{r} component. -@item r -Output parameter for the red parameter. -@item g -Output parameter for the green parameter. -@item b -Output parameter for the blue parameter. -@end table - - -@item libclut_model_srgb_to_ycgco(r, g, b, *Y, *Cg, *Co) -Convert from [0, 1] sRGB to YCgCo. - -The macro variant requires linking with @option{-lm}, -or if @option{-lclut} if the macro -@code{libclut_model_standard_to_linear1} has been -undefined. - -Parameters: -@table @code -@item r -The red component. -@item g -The green component. -@item b -The blue component. -@item Y -Output parameter for the Y parameter. -@item Cg -Output parameter for the Cg parameter. -@item Co -Output parameter for the Co parameter. -@end table - - -@item libclut_model_ycgco_to_srgb(Y, Cg, Co, *r, *g, *b) -Convert from YCgCo to [0, 1] sRGB. - -The macro variant requires linking with @option{-lm}, -or if @option{-lclut} if the macro -@code{libclut_model_linear_to_standard1} has been -undefined. - -Parameters: -@table @code -@item Y -The Y component. -@item Cg -The Cg component. -@item Co -The Co component. -@item r -Output parameter for the red parameter. -@item g -Output parameter for the green parameter. -@item b -Output parameter for the blue parameter. -@end table - - -@item libclut_model_cie_1960_ucs_to_ciexyz(u, v, Y, *x, *y, *z) -Convert from CIE 1960 UCS to CIE XYZ. - -Parameters: -@table @code -@item u -The u component. -@item v -The v component. -@item Y -The Y component. -@item x -Output parameter for the X parameter. -@item y -Output parameter for the Y parameter. -@item z -Output parameter for the Z parameter. -@end table - - -@item libclut_model_ciexyz_to_cie_1960_ucs(x, y, z, *u, *v, *Y) -Convert from CIE XYZ to CIE 1960 UCS. - -Parameters: -@table @code -@item x -The X component. -@item y -The Y component. -@item z -The Z component. -@item u -Output parameter for the u parameter. -@item v -Output parameter for the v parameter. -@item Y -Output parameter for the Y parameter. -@end table - - -@item libclut_model_cie_1960_ucs_to_cieuvw(U, V, W, u0, v0, *x, *y, *z) -Convert from CIE 1960 UCS to CIE U*V*W*. - -Parameters: -@table @code -@item U -The U* component. -@item V -The V* component. -@item W -The W* component. -@item u0 -The u parameter for the white point. -@item v0 -The v parameter for the white point. -@item x -Output parameter for the X parameter. -@item y -Output parameter for the Y parameter. -@item z -Output parameter for the Z parameter. -@end table - - -@item libclut_model_cieuvw_to_cie_1960_ucs(x, y, z, u0, v0, *U, *V, *W) -Convert from CIE U*V*W* to CIE 1960 UCS. - -The macro variant requires linking with @option{-lm}. - -Parameters: -@table @code -@item x -The X component. -@item y -The Y component. -@item z -The Z component. -@item u0 -The u parameter for the white point. -@item v0 -The v parameter for the white point. -@item U* -Output parameter for the u parameter. -@item V* -Output parameter for the v parameter. -@item W* -Output parameter for the Y parameter. -@end table -@end table - - -@node RGB Conversion -@section RGB Conversion - -@command{libclut} provides a functions for converting -RGB values between RGB colour spaces. An RGB colour space -is described using @code{struct libclut_rgb_colour_space} -(also known as @code{libclut_rgb_colour_space_t}). It -describes the colour of the red, green, and blue, -stimuli as well as the white point, in CIE xyY. It does -however not describe the colour space's gamma function, -because sRGB uses a irregular gamma function, and -ECI@tie{}RGB@tie{}v2 uses L*. The structure contains -the following @code{double}:s: - -@table @code -@item red_x -The CIE xyY x-value of the red stimulus. -@item red_y -The CIE xyY y-value of the red stimulus. -@item red_Y -The CIE xyY Y-value of the red stimulus. -@item green_x -The CIE xyY x-value of the green stimulus. -@item green_y -The CIE xyY y-value of the green stimulus. -@item green_Y -The CIE xyY Y-value of the green stimulus. -@item blue_x -The CIE xyY x-value of the blue stimulus. -@item blue_y -The CIE xyY y-value of the blue stimulus. -@item blue_Y -The CIE xyY Y-value of the blue stimulus. -@item white_x -The CIE xyY x-value of the white point. -@item white_y -The CIE xyY y-value of the white point. -@item white_Y -The CIE xyY Y-value of the white point. -@end table - -@code{libclut} provides macros used to initialise a -@code{struct libclut_rgb_colour_space} with values -for a number of RGB colour spaces. These are listed -below, along with the gamma each colour space uses. - -@multitable {PAL/SECAM RGB} {@b{Gamma}} {@code{LIBCLUT_RGB_COLOUR_SPACE_WIDE_GAMUT_RGB_INITIALISER}} -@item -@b{Model} -@tab -@b{Gamma} -@tab -@b{Initialiser} -@item -sRGB -@tab -custom -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_SRGB_INITIALISER} -@item -Adobe RGB (1998) -@tab -2.2 -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_ADOBE_RGB_INITIALISER} -@item -Apple RGB -@tab -1.8 -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_APPLE_RGB_INITIALISER} -@item -Best RGB -@tab -2.2 -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_BEST_RGB_INITIALISER} -@item -Beta RGB -@tab -2.2 -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_BETA_RGB_INITIALISER} -@item -Bruce RGB -@tab -2.2 -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_BRUCE_RGB_INITIALISER} -@item -CIE RGB -@tab -2.2 -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_CIE_RGB_INITIALISER} -@item -ColorMatch RGB -@tab -1.8 -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_COLORMATCH_RGB_INITIALISER} -@item -DCI-P3 D65 -@tab -2.6 -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_DCI_P3_D65_INITIALISER} -@item -DCI-P3 Theater -@tab -2.6 -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_DCI_P3_THEATER_INITIALISER} -@item -Don RGB 4 -@tab -2.2 -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_DON_RGB_4_INITIALISER} -@item -ECI RGB v2 -@tab -L* -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_ECI_RGB_V2_INITIALISER} -@item -Ekta Space PS5 -@tab -2.2 -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_EKTA_SPACE_PS5_INITIALISER} -@item -525 line@footnote{ITU-R Recommendation BT.601 (ITU-R BT.601), 525 line} -@tab -custom -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_ITU_R_BT_601_525_LINE_INITIALISER} -@item -625 line@footnote{ITU-R Recommendation BT.601 (ITU-R BT.601), 625 line} -@tab -custom -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_ITU_R_BT_601_625_LINE_INITIALISER} -@item -ITU-R BT.709@footnote{ITU-R Recommendation BT.709} -@tab -2.4 -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_ITU_R_BT_709_INITIALISER} -@item -ITU-R BT.2020@footnote{ITU-R Recommendation BT.2020} -@tab -custom -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_ITU_R_BT_2020_INITIALISER} -@item -ITU-R BT.2100@footnote{ITU-R Recommendation BT.2100} -@tab -custom -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_ITU_R_BT_2100_INITIALISER} -@item -Lightroom RGB -@tab -linear -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_LIGHTROOM_RGB_INITIALISER} -@item -NTSC RGB -@tab -2.2 -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_NTSC_RGB_INITIALISER} -@item -PAL/SECAM RGB -@tab -2.2 -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_PAL_SECAM_RGB_INITIALISER} -@item -ProPhoto RGB -@tab -1.8 -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_PROPHOTO_RGB_INITIALISER} -@item -SMPTE-C RGB -@tab -2.2 -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_SMPTE_C_RGB_INITIALISER} -@item -Wide Gamut RGB -@tab -2.2 -@tab -@code{LIBCLUT_RGB_COLOUR_SPACE_WIDE_GAMUT_RGB_INITIALISER} -@end multitable - -@page -To create a description for the sRGB colour space write: - -@example -struct libclut_rgb_colour_space srgb = \ - LIBCLUT_RGB_COLOUR_SPACE_SRGB_INITIALISER; -@end example - -@command{libgamma} and @command{libcoopgamma} can be used -to get the x and y values of the user's monitors' red, -green, and blue stimuli. Otherwise, all values specified -by @code{LIBCLUT_RGB_COLOUR_SPACE_SRGB_INITIALISER} can -be used, and the sRGB gamma function can be used. However, -the Y values of the stimuli may be off, however, this does -not affect conversion. - -sRGB uses an irregular gamma function. @command{libclut} -assumes that the colour spaces uses this gamma function -when converting between RGB colour spaces. If you want to -convert from a colour space with another gamma function, -you must first convert the gamma function. This can be -done by linearising the values and then use -@code{libclut_model_linear_to_standard1}, -@code{libclut_model_linear_to_standard}, or -@code{libclut_standardise}. If you want to convert to a -colour spce with another gamma function, you must after -the conversion also convert the gamma function. This can -be done by using @code{libclut_model_standard_to_linear1}, -@code{libclut_model_standard_to_linear}, or -@code{libclut_linearise}, and then converting from linear -to the proper gamma function. Note that even if you are -converting between two colour spaces with the same gamma -function, gamma function conversion must be done (before -and after) unless they use the sRGB gamma function. - -Before RGB colour space conversion can be done, you need -to create a conversion matrix. It has the type - -@example -typedef double libclut_colour_space_conversion_matrix_t[3][3]; -@end example - -@noindent -and can be created with -@table @code -@item int libclut_model_get_rgb_conversion_matrix(*from, *to, M, Minv) -Create a conversion matrix from one RGB colour space to another -RGB colour space, and optionally a matrix for an inverse conversion. - -Returns 0 on success, and -1 on error. The only possible error is -@code{EINVAL}, which indicates that there is something wrong with -the colour spaces and a conversion matrix cannot be created. - -This function is not available as a macro, thus, linking with -@option{-lclut} is required. - -Parameters: -@table @code -@item const libclut_rgb_colour_space_t* from -Description of the input colour space. CIE XYZ is -used use if this parameter is @code{NULL}. -@item const libclut_rgb_colour_space_t* to -Description of the output colour space. CIE XYZ is -used use if this parameter is @code{NULL}. -@item libclut_colour_space_conversion_matrix_t M -Matrix to fill with values so it can be used for -converting from the input colour space to the -output colour space. -@item libclut_colour_space_conversion_matrix_t Minv -Matrix to fill with values so it can be used for -converting from the output colour space to the -input colour space. (That is, inverse conversion.) -This parameter may be @code{NULL}. -@end table -@end table - -You can also create the matrix manually. If you for example -have a @code{libclut_colour_space_conversion_matrix_t} named -@code{M}, and want to set the cell at row 1 and column 3, to -0.5, you make the assignment @code{M[0][2] = 0.5}. - -Once you have your conversion matrix, @command{libclut} has -three macro functions you can used to convert colours between -RGB colour space. Remember that they require the sRGB gamma -function. - -@table @code -@item libclut_model_convert_rgb(r, g, b, M, *out_r, *out_g, *out_b) -Convert a single RGB colour into another RGB colour space. -The colour space must have same gamma functions as sRGB. - -This macro is also available a function. If the function is -used, linking with @option{-lclut} is required, otherwise, -linking with @option{-lm} is required, or @option{-lclut} if -@code{libclut_model_standard_to_linear1} or -@code{libclut_model_linear_to_standard1} is undefined. - -Parameters: -@table @code -@item double r -The red value of the colour to convert. -@item double g -The green value of the colour to convert. -@item double b -The blue value of the colour to convert. -@item libclut_colour_space_conversion_matrix_t M -The conversion matrix. -@item double* out_r -Output parameter for the red value of the colour after conversion. -@item double* out_g -Output parameter for the green value of the colour after conversion. -@item double* out_b -Output parameter for the blue value of the colour after conversion. -@end table - - -@item libclut_convert_rgb_inplace(clut, max, type, m, trunc) -Convert the curves between two RGB colour spaces. - -The red, green, and blue ramps must be of the same size. - -None of the parameter may have side-effects. - -Requires linking with @option{-lm}, or @option{-lclut} if -@code{libclut_model_standard_to_linear1}, -@code{libclut_model_linear_to_standard1}, or -@code{libclut_model_convert_rgb} is undefined. - -Parameters: -@table @code -@item clut -Pointer to the gamma ramps to convert. This must be a pointer to -an instance of a struct that must at least have the array members -@code{red}, @code{green}, and @code{blue}, whose elements shall be -of the type specified by the parameter @code{type}. The @code{struct} -must also have the scalar members @code{red_size}, @code{green_size}, -and @code{blue_size}, and shall be of the type @code{size_t}; they -shall specify the number of stops (elements) in the arrays @code{.red}, -@code{.green}, and @code{.blue}, respectively, which shall be the -gamma ramp for the red, green, and blue channels respectively. Its -values will be modified to the new values. -@item max -The maximum value on each stop in the ramps. -@item type -The data type used for each stop in the ramps. -@item libclut_colour_space_conversion_matrix_t m -Conversion matrix. -@item int trunc -If this is a non-zero value, resulting colours that are -out of gamut are truncated. (Not necessarily the best -approximation.) -@end table - - -@item libclut_convert_rgb(clut, max, type, m, trunc, out) -Convert the curves between two RGB colour spaces. - -This is a slower version of @code{libclut_convert_rgb_inplace} -that supports clut:s where the red, green, and blue ramps -are not of the same size. - -None of the parameter may have side-effects. - -Requires linking with @option{-lm}. If -@code{libclut_model_linear_to_standard1}, -@code{libclut_model_standard_to_linear1}, or -@code{libclut_model_convert_rgb} has been undefined, -linking with @option{-lclut} is also required. - -Parameters: -@table @code -@item clut -Pointer to the gamma ramps to convert. This must be a pointer to -an instance of a struct that must at least have the array members -@code{red}, @code{green}, and @code{blue}, whose elements shall be -of the type specified by the parameter @code{type}. The @code{struct} -must also have the scalar members @code{red_size}, @code{green_size}, -and @code{blue_size}, and shall be of the type @code{size_t}; they -shall specify the number of stops (elements) in the arrays @code{.red}, -@code{.green}, and @code{.blue}, respectively, which shall be the -gamma ramp for the red, green, and blue channels respectively. Its -values are not modified. -@item max -The maximum value on each stop in the ramps. -@item type -The data type used for each stop in the ramps. -@item libclut_colour_space_conversion_matrix_t m -Conversion matrix. -@item int trunc -If this is a non-zero value, resulting colours that are -out of gamut are truncated. (Not necessarily the best -approximation.) -@item clut -Pointer to the gamma ramps of the output values. Shall be of -the same data type as @code{clut}. And have the same values on -@code{.red_size}, @code{.green_size}, and @code{.blue_size} as -@code{clut}. -@end table -@end table - -There is also two functions for converting between a custom RGB -colour space and CIE XYZ, one function in each direction. Note -that the three functions above do not work if one of the colour -spaces is CIE XYZ. - -@table @code -@item libclut_model_rgb_to_ciexyz(r, g, b, M, *X, *Y, *Z) -Convert a single RGB colour if a custom RGB colour space -to CIE XYZ. - -The RGB colour space must have the same gamma function as sRGB. - -This macro is also available a function. If the function is -used, linking with @option{-lclut} is required, otherwise, -linking with @option{-lm} is required, or @option{-lclut} if -@code{libclut_model_standard_to_linear1} is undefined. - -Parameters: -@table @code -@item double r -The red component. -@item double g -The green component. -@item double b -The blue component. -@item libclut_colour_space_conversion_matrix_t M -The conversion matrix. -@item double* X -Output parameter for the X component. -@item double* Y -Output parameter for the Y component. -@item double* Z -Output parameter for the Z component. -@end table - - -@item libclut_model_rgb_to_ciexyz(X, Y, Z, M, *r, *g, *b) -Convert a single colour from CIE XYZ to a custom RGB colour space. - -The RGB colour space must have the same gamma function as sRGB. - -This macro is also available a function. If the function is -used, linking with @option{-lclut} is required, otherwise, -linking with @option{-lm} is required, or @option{-lclut} if -@code{libclut_model_linear_to_standard1} is undefined. - -Parameters: -@table @code -@item double X -The X component. -@item double Y -The Y component. -@item double Z -The Z component. -@item libclut_colour_space_conversion_matrix_t M -The conversion matrix. -@item double* r -Output parameter for the red component. -@item double* g -Output parameter for the green component. -@item double* b -Output parameter for the blue component. -@end table -@end table diff --git a/doc/info/chap/overview.texinfo b/doc/info/chap/overview.texinfo deleted file mode 100644 index 65a2b76..0000000 --- a/doc/info/chap/overview.texinfo +++ /dev/null @@ -1,13 +0,0 @@ -@node Overview -@chapter Overview - -@command{libclut} is C library for manipulating colour -lookup tables. @command{libclut} is used by including -the header @file{<libclut.h>}. Some functionality also -requires that the objects be linked with @option{-lclut}. - -@command{libclut} is designed to work well with -@command{libgamma} and @command{libcoopgamma}, but does -not require that either is used for any of its -[@command{libclut}'s] functionality. - diff --git a/doc/info/content.texinfo b/doc/info/content.texinfo deleted file mode 100644 index eb1b40c..0000000 --- a/doc/info/content.texinfo +++ /dev/null @@ -1,54 +0,0 @@ -@c This file includes everything after the titlepage. - - -@ifnothtml -@c @shortcontents @c (if the table of content gets too large.) -@contents -@end ifnothtml - - -@menu -* Overview:: Brief overview of @command{libclut}. -* CLUT Manipulation:: Function-like macros for CLUT manipulation. -* Colour Spaces:: Colour space conversion functions. - -* Free Software Needs Free Documentation:: Why free documentation is important. -* GNU General Public License:: Copying and sharing @command{libclut}. -* GNU Free Documentation License:: Copying and sharing this manual. - -@detailmenu - --- The Detailed Node Listing --- - -Overview - -CLUT Manipulation - -Colour Spaces - -* RGB Conversion:: RGB colour space conversion functions. - - -Free Software Needs Free Documentation - -GNU General Public License - -GNU Free Documentation License -@end detailmenu -@end menu -@c In GNU Emacs a @detailmenu can be created with `C-c C-u m`. - - -@include chap/overview.texinfo -@include chap/clut-manipulation.texinfo -@include chap/colour-spaces.texinfo - -@include appx/free-software-needs-free-documentation.texinfo - -@node GNU General Public License -@appendix GNU General Public License -@include appx/gpl.texinfo - -@node GNU Free Documentation License -@appendix GNU Free Documentation License -@include appx/fdl.texinfo - diff --git a/doc/info/hardcopy-copying.texinfo b/doc/info/hardcopy-copying.texinfo deleted file mode 100644 index d5f83f5..0000000 --- a/doc/info/hardcopy-copying.texinfo +++ /dev/null @@ -1,70 +0,0 @@ -@c --- This is a template for the hardcopy-copying.texinfo file. --- - -@c Uncomment this when dead tree editions can be ordered. -@c @set HARDCOPY_AVAILABLE - - -@set PRINTINGNUMBER First -@set PRINTINGDATE Januari 0000 -@set ISBNNUMBER 0000000000 - -@ifset HARDCOPY -@copying -@ifset VERSION -This manual documents @value{programnamewiththe} version @value{VERSION}@. -@end ifset -@ifclear VERSION -This manual documents @value{programnamewiththe}. -@end ifclear -@* -@ifset EDITION -@sc{ISBN} @value{ISBNNUMBER}, @value{EDITION} Edition, @value{PRINTINGNUMBER} Printing, @value{PRINTINGDATE}. -@end ifset -@ifclear EDITION -@sc{ISBN} @value{ISBNNUMBER}, @value{PRINTINGNUMBER} Printing, @value{PRINTINGDATE}. -@end ifclear -@* - -Printed by: -@* - -X - -@*@* -Copyright @copyright{} 2016 Mattias Andrée @e{maandree@@member.fsf.org} -@* - -@c The copyright information from the main file, add any required -@c Invariant Sections being used on the dead tree edition. -Permission is granted to copy, distribute and/or modify this document -under the terms of the GNU Free Documentation License, Version@tie{}1.3 or -any later version published by the Free Software Foundation; -with the Invariant Sections being -``Free Software Needs Free Documentation'', -the ``GNU General Public License'', -the ``GNU Free Documentation License'', -with no Front-Cover Texts, -and with no Back-Cover Texts. -A copy of the license is included in the section entitled -``GNU Free Documentation License''. -@c THIS WAS LAST UPPDATE 2016-JANUARY-06 UTC -@c AUTHORITATIVE COPYRIGHT INFORMATION IS AVAILABLE -@c IN libclut.texinfo. THIS FILL MUST BE UPDATED -@c BEFORE PRINTING. - -@* -Cover art by XY Z. Cover design by XY Z. Printed in XYZ. -@end copying -@end ifset - - - -@ifclear HARDCOPY -@ifset HARDCOPY_AVAILABLE -@macro orderhardcopy{} -If you prefer a dead tree edition, you can order one from -... -@endif -@end ifset -@end ifclear - diff --git a/doc/info/libclut.texinfo b/doc/info/libclut.texinfo deleted file mode 100644 index de9d573..0000000 --- a/doc/info/libclut.texinfo +++ /dev/null @@ -1,104 +0,0 @@ -\input texinfo @c -*-texinfo-*- -@c %**start of header -@documentencoding UTF-8 -@include reusable/macros.texinfo -@copying -@c -------------------------------------------------------------------------------- -Copyright @copyright{} 2016 @w{Mattias Andrée @e{maandree@@member.fsf.org}} - -@quotation -Permission is granted to copy, distribute and/or modify this document -under the terms of the GNU Free Documentation License, Version@tie{}1.3 or -any later version published by the Free Software Foundation; with the -Invariant Sections being ``Free Software Needs Free Documentation'', the -``GNU General Public License'', the ``GNU Free Documentation License'', -with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the -license is included in the section entitled ``GNU Free Documentation License''. -@end quotation -@c THIS WAS LAST CHANGED 2016-JANUARY-06 UTC -@c When updated, please remember to update hardcopy-copying.texinfo too. -@c -------------------------------------------------------------------------------- -@end copying - -@setfilename libclut.info -@settitle libclut -@documentlanguage en_GB -@include titlepage-data.texinfo - -@c You can change the title of the document in dir by compiling with -@c INFO_FLAGS='-c CATEGORY=your_new_category' -@ifclear CATEGORY -@set CATEGORY Library -@end ifclear - -@dircategory @value{CATEGORY} -@direntry -* libclut: (libclut). @value{subtitle} -@end direntry - -@documentdescription -Reference manual for libclut. -A library for manipulating colour -lookup tables. -@end documentdescription -@c %**end of header - - -@iftex -@c @set USLETTER -@c @set AFOURPAPER -@c @set AFIVEPAPER -@c @set SMALLBOOK - -@c @set HARDCOPY -@c @set CROPMARKS -@c @set SKIPCHAPTERNEWPAGE -@c @set SKIPFONTTEXTSIZE -@end iftex -@c @set LOGO -@c @set DOUBLEHEADINGS -@c @set SINGLEHEADINGS -@c @set AMERICANSPACING -@c @set NOFINALOUT - -@ignore - - CROPMARKS has no effect unless HARDCOPY is set. CROPMARKS - and AFIVEPAPER (or actually @cropmarks and @afivepaper) does - not play well together. - - You can configure how TeX output files should look by uncommenting - @set commands above. Do not uncomment more than one of the paper - sizes (USLETTER, AFOURPAPER, AFIVEPAPER and SMALLBOOK); if none is - uncomment AFOURPAPER will be set unless HARDCOPY is set, in which - case SMALLBOOK will be set. However, if you do not want to modify - this source file, you can run `make` with for example - `TEXINFO_FLAGS='--texinfo="@set HARDCOPY"'`. - - Finally, you can include, on the front page, the version of libclut - that the manual is up to date with, by setting the value of VERSION - to the version of libclut, as well as date of the last update by - setting DATE, and edition by setting EDITION. This is intended for - printed manuals. The date is recommended to not be more accurate, - or less accurate, than to the month. The edition should be formatted - as, for example, ``1@sup{st}''. - -@end ignore - -@comment You can see these too with TEXINFO_FLAGS. -@c @paragraphindent asis -@c @firstparagraphindent none -@c @exampleindent asis -@c @kbdinputstyle distinct - -@include reusable/paper.texinfo - - -@include hardcopy-copying.texinfo -@include reusable/titlepage.texinfo -@setheadings{} - -@include content.texinfo - -@bye - diff --git a/doc/info/reusable/macros.texinfo b/doc/info/reusable/macros.texinfo deleted file mode 100644 index 8d95983..0000000 --- a/doc/info/reusable/macros.texinfo +++ /dev/null @@ -1,48 +0,0 @@ -@c GENERAL ADVICE. -@c Because of an previous regression bug in Texinfo -@c it is a good idea to use @w around lines using -@c macros. - - -@c Use this comment to get a good looking e-mail -@c address in both the info output and the TeX -@c processed output. -@iftex -@macro e{a} -(@email{\a\}) -@end macro -@end iftex -@ifnottex -@macro e{a} -@email{\a\} -@end macro -@end ifnottex - -@c This is intented do be used inside @example. -@c At the beginning of non-code text in a source -@c code comment, use this macro to make it look -@c good in TeX processed output. End with @xtt. -@iftex -@macro xrm{} -@rm{} -@end macro -@end iftex -@ifnottex -@macro xrm{} -@end macro -@end ifnottex - -@c This is intented do be used inside @example. -@c At the end of non-code text in a source code -@c comment, use this macro to make it look -@c good in TeX processed output. -@iftex -@macro xtt{} -@tt{} -@end macro -@end iftex -@ifnottex -@macro xtt{} -@end macro -@end ifnottex - diff --git a/doc/info/reusable/paper.texinfo b/doc/info/reusable/paper.texinfo deleted file mode 100644 index 5a6aca8..0000000 --- a/doc/info/reusable/paper.texinfo +++ /dev/null @@ -1,109 +0,0 @@ -@c This file is used, by inclusion, to allow the -@c builder to specify how output shall be formatted. - -@c On dead tree editions we defailt to smallbook format. -@ifset HARDCOPY -@ifclear USLETTER -@ifclear AFOURPAPER -@ifclear AFIVEPAPER -@ifclear SMALLBOOK -@set SMALLBOOK -@end ifclear -@end ifclear -@end ifclear -@end ifclear -@end ifset - -@c On dead tree editions the heading on the left page -@c is different from the heading on the right page. -@c On online editions the heading is identical on the -@c left pages and on the right pages. -@ifclear SINGLE_HEADINGS -@ifclear DOUBLE_HEADINGS -@ifclear HARDCOPY -@set SINGLE_HEADINGS -@end ifclear -@ifset HARDCOPY -@set DOUBLE_HEADINGS -@end ifset -@end ifclear -@end ifclear - -@c Apply paper format. Default to A4. (Remember -@c dead tree editions defaulted to smallbook.) -@ifset AFIVEPAPER -@afivepaper -@end ifset -@ifset SMALLBOOK -@smallbook -@end ifset -@ifclear AFIVEPAPER -@ifclear SMALLBOOK -@ifclear USLETTER -@afourpaper -@set AFOURPAPER -@end ifclear -@end ifclear -@end ifclear -@c (Texinfo defaults to US letter, thus nothing is -@c done for USLETTER.) - -@c Only on dead tree editions: optionally add -@c cropmarks, and by default, chapters begin -@c on odd page numbers (the right side.) -@ifset HARDCOPY -@ifset CROPMARKS -@cropmarks -@end ifset -@ifclear SKIPCHAPTERNEWPAGE -@setchapternewpage odd -@end ifclear -@end ifset - -@c Apply font size. On smallbook and A5 default to -@c 10 points, on A4 and US letter we default to -@c 11 points. -@ifclear SKIPFONTTEXTSIZE -@ifset SMALLBOOK -@set SMALLFONT -@end ifset -@ifset AFIVEPAPER -@set SMALLFONT -@end ifset -@end ifclear -@ifset SMALLFONT -@fonttextsize 10 -@end ifset -@ifclear SMALLFONT -@iftex @c Because of bug in Texinfo<=4.13 -@fonttextsize 11 -@end iftex -@end ifclear - -@c In America it is customary to have two spaces after -@c a period. It is not elsewhere. (@frenchspacing is a -@c misnomer) -@ifclear AMERICANSPACING -@frenchspacing on -@end ifclear - -@c This should only be used when writting the document. -@c It is used to locate overflows. It should be be used -@c in a printed version. It can be used in an online come -@c use users can easier detect overflows and report them. -@ifclear NOFINALOUT -@finalout -@end ifclear - - -@c Call this macro after the title page, but before the -@c table of content, or the short table of content. -@macro setheadings{} -@ifset DOUBLEHEADINGS -@headings double -@end ifset -@ifset SINGLEHEADINGS -@headings single -@end ifset -@end macro - diff --git a/doc/info/reusable/titlepage.texinfo b/doc/info/reusable/titlepage.texinfo deleted file mode 100644 index 55981f7..0000000 --- a/doc/info/reusable/titlepage.texinfo +++ /dev/null @@ -1,79 +0,0 @@ -@c This file @top or @titlepage. - -@ifnottex -@node Top -@top @value{title} -- @value{subtitle} -@insertcopying -@end ifnottex - -@titlepage -@title @value{title} -@subtitle @value{subtitle} - -@c Date, edition, and version of the program. -@c Should be set on dead tree editions. Not too -@c important on online editions. -@ifset DATE -@ifset VERSION -@ifset EDITION -@subtitle @value{DATE}, @value{programname} version@tie{}@value{VERSION}, @value{EDITION} edition -@end ifset -@ifclear EDITION -@subtitle @value{DATE}, @value{programname} version@tie{}@value{VERSION} -@end ifclear -@end ifset -@ifclear VERSION -@ifset EDITION -@subtitle @value{DATE}, @value{EDITION} edition -@end ifset -@ifclear EDITION -@subtitle @value{DATE} -@end ifclear -@end ifclear -@end ifset -@ifclear DATE -@ifset VERSION -@ifset EDITION -@subtitle @value{programname} version@tie{}@value{VERSION}, @value{EDITION} edition -@end ifset -@ifclear EDITION -@subtitle @value{programname} version@tie{}@value{VERSION} -@end ifclear -@end ifset -@ifclear VERSION -@ifset EDITION -@subtitle @value{EDITION} edition -@end ifset -@end ifclear -@end ifclear - -@ifset LOGO -@vskip 0pt plus 1filll -@c This way, it is centered exactly in pdf and approximently -@c in dvi and ps. @center does not work for @image in dvi and ps. -@multitable @columnfractions 0.15 0.7 -@item @tab @center @image{../logo,250px} -@end multitable -@vskip 0pt plus 2filll -@end ifset -@authors{} - -@page -@ifset HARDCOPY -@vskip 0pt plus 1filll -@insertcopying -@page -@end ifset -@ifset HAVE_DEDICATION -@dedication{} -@end ifset -@ifclear HARDCOPY -@vskip 0pt plus 1filll -@ifset HARDCOPY_AVAILABLE -@orderhardcopy{} -@* -@end ifset -@insertcopying -@end ifclear -@end titlepage - diff --git a/doc/info/titlepage-data.texinfo b/doc/info/titlepage-data.texinfo deleted file mode 100644 index 365e7ac..0000000 --- a/doc/info/titlepage-data.texinfo +++ /dev/null @@ -1,23 +0,0 @@ -@c The title and the subtitle of the manual. -@set title libclut -@set subtitle Colour lookup table manipulation - -@c The full name of the documented program or package. -@set programname @command{libclut} -@set programnamewiththe @command{libclut} - - -@c Authors of the manual. Included at the bottom -@c of the titlepage on TeX processed output. -@macro authors{} -@author by Mattias Andrée (maandree) -@end macro - - -@c Dedication for TeX processed output. -@c @set HAVE_DEDICATION -@c @macro dedication{} -@c @center `' -@c @end macro -@c (I don't use dedications, I use quotes.) - diff --git a/libclut.c b/libclut.c new file mode 100644 index 0000000..911fdce --- /dev/null +++ b/libclut.c @@ -0,0 +1,749 @@ +/* See LICENSE file for copyright and license details. */ +#include "libclut.h" + +#include <errno.h> + +/** + * Convert one component from [0, 1] linear sRGB to [0, 1] sRGB + * + * @param c The linear sRGB value + * @return Corresponding sRGB value + */ +double +(libclut_model_linear_to_standard1)(double c) +{ + return libclut_model_linear_to_standard1(c); +} + +/** + * Convert [0, 1] linear sRGB to [0, 1] sRGB + * + * @param r Pointer to the linear red component, + * and output parameter for the red component + * @param g Pointer to the linear green component, + * and output parameter for the green component + * @param b Pointer to the linear blue component, + * and output parameter for the blue component + */ +void +(libclut_model_linear_to_standard)(double *r, double *g, double *b) +{ + libclut_model_linear_to_standard(r, g, b); +} + +/** + * Convert one component from [0, 1] sRGB to [0, 1] linear sRGB + * + * @param c The sRGB value + * @return Corresponding linear sRGB value + */ +double +(libclut_model_standard_to_linear1)(double c) +{ + return libclut_model_standard_to_linear1(c); +} + +/** + * Convert [0, 1] sRGB to [0, 1] linear sRGB + * + * @param r Pointer to the red component, and output + * parameter for the linear red component + * @param g Pointer to the green component, and output + * parameter for the linear green component + * @param b Pointer to the blue component, and output + * parameter for the linear blue component + */ +void +(libclut_model_standard_to_linear)(double *r, double *g, double *b) +{ + libclut_model_standard_to_linear(r, g, b); +} + +/** + * Convert CIE xyY to CIE XYZ. + * + * @param x The x parameter + * @param y The y parameter + * @param Y The Y parameter; this is also the Y (middle) parameter for the CIE XYZ colour + * @param X Output parameter for the X parameter + * @param Z Output parameter for the Z parameter + */ +void +(libclut_model_ciexyy_to_ciexyz)(double x, double y, double Y, double *X, double *Z) +{ + libclut_model_ciexyy_to_ciexyz(x, y, Y, X, Z); +} + +/** + * Convert CIE XYZ to CIE xyY + * + * @param X The X parameter + * @param Y The Y parameter; this is also the Y (last) parameter for the CIE xyY colour + * @param Z The Z parameter + * @param x Output parameter for the x parameter + * @param y Output parameter for the y parameter + */ +void +(libclut_model_ciexyz_to_ciexyy)(double X, double Y, double Z, double *x, double *y) +{ + libclut_model_ciexyz_to_ciexyy(X, Y, Z, x, y); +} + +/** + * Convert CIE XYZ to [0, 1] linear sRGB + * + * @param X The X parameter + * @param Y The Y parameter + * @param Z The Z parameter + * @param r Output parameter for the red component + * @param g Output parameter for the green component + * @param b Output parameter for the blue component + */ +void +(libclut_model_ciexyz_to_linear)(double X, double Y, double Z, double *r, double *g, double *b) +{ + libclut_model_ciexyz_to_linear(X, Y, Z, r, g, b); +} + +/** + * Convert [0, 1] linear sRGB to CIE XYZ + * + * @param r The red component + * @param g The green component + * @param b The blue component + * @param X Output parameter for the X parameter + * @param Y Output parameter for the Y parameter + * @param Z Output parameter for the Z parameter + */ +void +(libclut_model_linear_to_ciexyz)(double r, double g, double b, double *X, double *Y, double *Z) +{ + libclut_model_linear_to_ciexyz(r, g, b, X, Y, Z); +} + +/** + * Convert [0, 1] linear sRGB to CIE xyY + * + * @param r The red component + * @param g The green component + * @param b The blue component + * @param x Output parameter for the x parameter + * @param y Output parameter for the y parameter + * @param Y Output parameter for the Y parameter + */ +void +(libclut_model_srgb_to_ciexyy)(double r, double g, double b, double *x, double *y, double *Y) +{ + libclut_model_srgb_to_ciexyy(r, g, b, x, y, Y); +} + +/** + * Convert CIE xyY to [0, 1] sRGB + * + * @param x The x parameter + * @param y The y parameter + * @param Y The Y parameter + * @param r Output parameter for the red component + * @param g Output parameter for the green component + * @param b Output parameter for the blue component + */ +void +(libclut_model_ciexyy_to_srgb)(double x, double y, double Y, double *r, double *g, double *b) +{ + libclut_model_ciexyy_to_srgb(x, y, Y, r, g, b); +} + +/** + * Convert from CIE XYZ to CIE L*a*b* + * + * @param X The X parameter + * @param Y The Y parameter + * @param Z The Z parameter + * @param L Output parameter for the L* component + * @param a Output parameter for the a* component + * @param b Output parameter for the b* component + */ +void +(libclut_model_ciexyz_to_cielab)(double X, double Y, double Z, double *L, double *a, double *b) +{ + libclut_model_ciexyz_to_cielab(X, Y, Z, L, a, b); +} + +/** + * Convert from CIE L*a*b* to CIE XYZ + * + * @param L The L* component + * @param a The a* component + * @param b The b* component + * @param X Output parameter for the X parameter + * @param Y Output parameter for the Y parameter + * @param Z Output parameter for the Z parameter + */ +void +(libclut_model_cielab_to_ciexyz)(double L, double a, double b, double *X, double *Y, double *Z) +{ + libclut_model_cielab_to_ciexyz(L, a, b, X, Y, Z); +} + +/** + * Convert from CIE XYZ to CIE L*u*v* + * + * @param X The X parameter + * @param Y The Y parameter + * @param Z The Z parameter + * @param Xn The X component of the specified white object (white point) + * @param Yn The Y component of the specified white object (white point) + * @param Zn The Z component of the specified white object (white point) + * @param L Output parameter for the L* component + * @param u Output parameter for the u* component + * @param v Output parameter for the v* component + */ +void +(libclut_model_ciexyz_to_cieluv)(double X, double Y, double Z, double Xn, double Yn, double Zn, double *L, double *u, double *v) +{ + libclut_model_ciexyz_to_cieluv(X, Y, Z, Xn, Yn, Zn, L, u, v); +} + +/** + * Convert from CIE L*u*v* to CIE XYZ + * + * @param L The L* component + * @param u The u* component + * @param v The v* component + * @param Xn The X component of the specified white object (white point) + * @param Yn The Y component of the specified white object (white point) + * @param Zn The Z component of the specified white object (white point) + * @param X Output parameter for the X parameter + * @param Y Output parameter for the Y parameter + * @param Z Output parameter for the Z parameter + */ +void +(libclut_model_cieluv_to_ciexyz)(double L, double u, double v, double Xn, double Yn, double Zn, double *X, double *Y, double *Z) +{ + libclut_model_cieluv_to_ciexyz(L, u, v, Xn, Yn, Zn, X, Y, Z); +} + +/** + * Convert from CIELCh to CIE L*u*v* + * + * @param L The L* component + * @param C The C*_uv component + * @param h The h_uv component + * @param u Output parameter for the u* parameter + * @param v Output parameter for the v* parameter + */ +void +(libclut_model_cielch_to_cieluv)(double C, double h, double *u, double *v) +{ + libclut_model_cielch_to_cieluv(C, h, u, v); +} + +/** + * Convert from CIE L*u*v* to CIELCh + * + * @param L The L* component + * @param u The u* component + * @param v The v* component + * @param C Output parameter for the C*_uv parameter + * @param h Output parameter for the h_uv parameter + */ +void +(libclut_model_cieluv_to_cielch)(double u, double v, double *C, double *h) +{ + libclut_model_cieluv_to_cielch(u, v, C, h); +} + +/** + * Convert from sRGB to YIQ + * + * @param r The R component + * @param g The G component + * @param b The B component + * @param y Output parameter for the Y parameter + * @param i Output parameter for the I parameter + * @param q Output parameter for the Q parameter + */ +void +(libclut_model_srgb_to_yiq)(double r, double g, double b, double *y, double *i, double *q) +{ + libclut_model_srgb_to_yiq(r, g, b, y, i, q); +} + +/** + * Convert from YIQ to sRGB + * + * @param y The Y component + * @param i The I component + * @param q The Q component + * @param r Output parameter for the R parameter + * @param g Output parameter for the G parameter + * @param b Output parameter for the B parameter + */ +void +(libclut_model_yiq_to_srgb)(double y, double i, double q, double *r, double *g, double *b) +{ + libclut_model_yiq_to_srgb(y, i, q, r, g, b); +} + +/** + * Convert from sRGB to YDbDr + * + * @param r The R component + * @param g The G component + * @param b The B component + * @param y Output parameter for the Y parameter + * @param db Output parameter for the Db parameter + * @param dr Output parameter for the Dr parameter + */ +void +(libclut_model_srgb_to_ydbdr)(double r, double g, double b, double *y, double *db, double *dr) +{ + libclut_model_srgb_to_ydbdr(r, g, b, y, db, dr); +} + +/** + * Convert from YDbDr to sRGB + * + * @param y The Y component + * @param db The Db component + * @param dr The Dr component + * @param r Output parameter for the R parameter + * @param g Output parameter for the G parameter + * @param b Output parameter for the B parameter + */ +void +(libclut_model_ydbdr_to_srgb)(double y, double db, double dr, double *r, double *g, double *b) +{ + libclut_model_ydbdr_to_srgb(y, db, dr, r, g, b); +} + +/** + * Convert from YUV to YDbDr + * + * @param u The U component + * @param v The V component + * @param db Output parameter for the Db parameter + * @param dr Output parameter for the Dr parameter + */ +void +(libclut_model_yuv_to_ydbdr)(double u, double v, double *db, double *dr) +{ + libclut_model_yuv_to_ydbdr(u, v, db, dr); +} + +/** + * Convert from YDbDr to YUV + * + * @param db The Db component + * @param dr The Dr component + * @param u Output parameter for the U parameter + * @param v Output parameter for the V parameter + */ +void +(libclut_model_ydbdr_to_yuv)(double db, double dr, double *u, double *v) +{ + libclut_model_ydbdr_to_yuv(db, dr, u, v); +} + +/** + * Convert from sRGB to YPbPr + * + * @param r The R component + * @param g The G component + * @param b The B component + * @param y Output parameter for the Y parameter + * @param pb Output parameter for the Pb parameter + * @param pr Output parameter for the Pr parameter + */ +void +(libclut_model_srgb_to_ypbpr)(double r, double g, double b, double *y, double *pb, double *pr) +{ + libclut_model_srgb_to_ypbpr(r, g, b, y, pb, pr); +} + +/** + * Convert from YPbPr to sRGB + * + * @param y The Y component + * @param pb The Pb component + * @param pr The Pr component + * @param r Output parameter for the R parameter + * @param g Output parameter for the G parameter + * @param b Output parameter for the B parameter + */ +void +(libclut_model_ypbpr_to_srgb)(double y, double pb, double pr, double *r, double *g, double *b) +{ + libclut_model_ypbpr_to_srgb(y, pb, pr, r, g, b); +} + +/** + * Convert from sRGB to YCgCo + * + * @param r The R component + * @param g The G component + * @param b The B component + * @param y Output parameter for the Y parameter + * @param cg Output parameter for the Cg parameter + * @param co Output parameter for the Co parameter + */ +void +(libclut_model_srgb_to_ycgco)(double r, double g, double b, double *y, double *cg, double *co) +{ + libclut_model_srgb_to_ycgco(r, g, b, y, cg, co); +} + +/** + * Convert from YCgCo to sRGB + * + * @param y The Y component + * @param cg The Cg component + * @param co The Co component + * @param r Output parameter for the R parameter + * @param g Output parameter for the G parameter + * @param b Output parameter for the B parameter + */ +void +(libclut_model_ycgco_to_srgb)(double y, double cg, double co, double *r, double *g, double *b) +{ + libclut_model_ycgco_to_srgb(y, cg, co, r, g, b); +} + +/** + * Convert from CIE 1960 UCS to CIE XYZ + * + * @param u The u component + * @param v The v component + * @param Y The Y component + * @param x Output parameter for the X parameter + * @param y Output parameter for the Y parameter + * @param z Output parameter for the Z parameter + */ +void +(libclut_model_cie_1960_ucs_to_ciexyz)(double u, double v, double Y, double *x, double *y, double *z) +{ + libclut_model_cie_1960_ucs_to_ciexyz(u, v, Y, x, y, z); +} + +/** + * Convert from CIE XYZ to CIE 1960 UCS + * + * @param x The X component + * @param y The Y component + * @param z The Z component + * @param u Output parameter for the u parameter + * @param v Output parameter for the v parameter + * @param Y Output parameter for the Y parameter + */ +void +(libclut_model_ciexyz_to_cie_1960_ucs)(double x, double y, double z, double *u, double *v, double *Y) +{ + libclut_model_ciexyz_to_cie_1960_ucs(x, y, z, u, v, Y); +} + +/** + * Convert from CIEUVW to CIE 1960 UCS + * + * @param U The U* component + * @param V The V* component + * @param W The W* component + * @param u0 The u parameter for the white point + * @param v0 The v parameter for the white point + * @param u Output parameter for the u parameter + * @param v Output parameter for the v parameter + * @param Y Output parameter for the Y parameter + */ +void +(libclut_model_cieuvw_to_cie_1960_ucs)(double U, double V, double W, double u0, double v0, double *u, double *v, double *Y) +{ + libclut_model_cieuvw_to_cie_1960_ucs(U, V, W, u0, v0, u, v, Y); +} + +/** + * Convert from CIE 1960 UCS to CIEUVW + * + * Requires linking with `-lm` + * + * @param u The u component + * @param v The v component + * @param Y The Y component + * @param u0 The u parameter for the white point + * @param v0 The v parameter for the white point + * @param U Output parameter for the U* parameter + * @param V Output parameter for the V* parameter + * @param W Output parameter for the W* parameter + */ +void +(libclut_model_cie_1960_ucs_to_cieuvw)(double u, double v, double Y, double u0, double v0, double *U, double *V, double *W) +{ + libclut_model_cie_1960_ucs_to_cieuvw(u, v, Y, u0, v0, U, V, W); +} + +/** + * Divide all values in a row by a divisor + * + * @param m The first part of the row + * @param a The second part of the row + * @param d The divisor + */ +static void +divrow(double m[3], double a[3], double d) +{ + m[0] /= d, m[1] /= d, m[2] /= d; + a[0] /= d, a[1] /= d, a[2] /= d; +} + +/** + * Subtract all values in a row by corresponding value + * in another row multiplied by a common value + * + * @param a1 The first part of the minuend/difference row + * @param a2 The second part of the minuend/difference row + * @param b1 The first part of the subtrahend row + * @param b2 The second part of the subtrahend row + * @param m The multiplier + */ +static void +subrow(double a1[3], double a2[3], double b1[3], double b2[3], double m) +{ + a1[0] -= b1[0] * m, a1[1] -= b1[1] * m, a1[2] -= b1[2] * m; + a2[0] -= b2[0] * m, a2[1] -= b2[1] * m, a2[2] -= b2[2] * m; +} + +/** + * Invert a matrix + * + * @param M The matrix to invert, will be modified to an + * identity matrix, possibly with reordered rows + * @param A The inversion of M (as input) + * @return 1 on success, 0 if the matrix is not invertible + */ +static int +invert(libclut_colour_space_conversion_matrix_t M, libclut_colour_space_conversion_matrix_t A) +{ + int r0 = 0, r1 = 1, r2 = 2, t, swapped = 0; + libclut_colour_space_conversion_matrix_t T; + + A[0][0] = A[1][1] = A[2][2] = 1; + A[0][1] = A[0][2] = A[1][0] = A[1][2] = A[2][0] = A[2][1] = 0; + + if (libclut_0__(M[r0][0])) { + if (libclut_0__(M[r1][0])) { + if (libclut_0__(M[r2][0])) + return 0; + t = r0, r0 = r2, r2 = t; + } else { + t = r0, r0 = r1, r1 = t; + } + swapped = 1; + } + + divrow(M[r0], A[r0], M[r0][0]); + subrow(M[r1], A[r1], M[r0], A[r0], M[r1][0]); + subrow(M[r2], A[r2], M[r0], A[r0], M[r2][0]); + + if (libclut_0__(M[r1][1])) { + if (libclut_0__(M[r2][1])) + return 0; + t = r1, r1 = r2, r2 = t; + swapped = 1; + } + + divrow(M[r1], A[r1], M[r1][1]); + subrow(M[r2], A[r2], M[r1], A[r1], M[r2][1]); + + if (libclut_0__(M[r2][2])) + return 0; + + divrow(M[r2], A[r2], M[r2][2]); + + subrow(M[r1], A[r1], M[r2], A[r2], M[r1][2]); + subrow(M[r0], A[r0], M[r2], A[r2], M[r0][2]); + + subrow(M[r0], A[r0], M[r1], A[r1], M[r0][1]); + + if (swapped) { + memcpy(T, A, sizeof(T)); + memcpy(A[0], T[r0], sizeof(*T)); + memcpy(A[1], T[r1], sizeof(*T)); + memcpy(A[2], T[r2], sizeof(*T)); + } + + return 1; +} + +/** + * Create an RGB to CIE XYZ conversion matrix + * + * @param cs The colour space + * @param M The output matrix + * @return Zero on success, -1 on error + * + * @throws EINVAL The colour space cannot be used + */ +static int +get_conversion_matrix(const libclut_rgb_colour_space_t *cs, libclut_colour_space_conversion_matrix_t M) +{ +#define XYY_TO_XYZ(x, y, Y, Xp, Yp, Zp)\ + (libclut_0__(Y)) ?\ + (*(Xp) = *(Zp) = *(Yp) = (Y)) :\ + (*(Xp) = (x) * (Y) / (y),\ + *(Yp) = (Y),\ + *(Zp) = (1 - (x) - (y)) * (Y) / (y)) + + double Xr, Yr, Zr, Xg, Yg, Zg, Xb, Yb, Zb, Xw, Yw, Zw, Sr, Sg, Sb; + libclut_colour_space_conversion_matrix_t M2; + + XYY_TO_XYZ(cs->red_x, cs->red_y, 1, &Xr, &Yr, &Zr); + XYY_TO_XYZ(cs->green_x, cs->green_y, 1, &Xg, &Yg, &Zg); + XYY_TO_XYZ(cs->blue_x, cs->blue_y, 1, &Xb, &Yb, &Zb); + XYY_TO_XYZ(cs->white_x, cs->white_y, cs->white_Y, &Xw, &Yw, &Zw); + + M2[0][0] = Xr, M2[0][1] = Xg, M2[0][2] = Xb; + M2[1][0] = Yr, M2[1][1] = Yg, M2[1][2] = Yb; + M2[2][0] = Zr, M2[2][1] = Zg, M2[2][2] = Zb; + + if (!invert(M2, M)) + return errno = EINVAL, -1; + + Sr = M[0][0] * Xw + M[0][1] * Yw + M[0][2] * Zw; + Sg = M[1][0] * Xw + M[1][1] * Yw + M[1][2] * Zw; + Sb = M[2][0] * Xw + M[2][1] * Yw + M[2][2] * Zw; + + M[0][0] = Sr * Xr, M[0][1] = Sg * Xg, M[0][2] = Sb * Xb; + M[1][0] = Sr * Yr, M[1][1] = Sg * Yg, M[1][2] = Sb * Yb; + M[2][0] = Sr * Zr, M[2][1] = Sg * Zg, M[2][2] = Sb * Zb; + + return 0; + +#undef XYY_TO_XYZ +} + +/** + * Create a matrix for converting values between + * two RGB colour spaces + * + * @param from The input colour space, the Y-component is only necessary + * for the white point, `NULL` for CIE XYZ + * @param to The output colour space, the Y-component is only necessary + * for the white point, `NULL` for CIE XYZ + * @param M Output matrix for conversion from `from` to `to` + * @param Minv Output matrix for conversion from `to` to `from`, may be `NULL` + * @return Zero on success, -1 on error + * + * @throws EINVAL The colour space cannot be used + */ +int +libclut_model_get_rgb_conversion_matrix(const libclut_rgb_colour_space_t *from, + const libclut_rgb_colour_space_t *to, + libclut_colour_space_conversion_matrix_t M, + libclut_colour_space_conversion_matrix_t Minv) +{ + libclut_colour_space_conversion_matrix_t A, B; + + if (from) { + if (get_conversion_matrix(from, A)) + return -1; + } else { + A[0][0] = A[1][1] = A[2][2] = 1; + A[0][1] = A[1][0] = A[2][0] = 0; + A[0][2] = A[1][2] = A[2][1] = 0; + } + + if (to) { + if (get_conversion_matrix(to, M)) + return -1; + if (!invert(M, B)) { + errno = EINVAL; + return -1; + } + + if (from) { + M[0][0] = B[0][0] * A[0][0] + B[0][1] * A[1][0] + B[0][2] * A[2][0]; + M[0][1] = B[0][0] * A[0][1] + B[0][1] * A[1][1] + B[0][2] * A[2][1]; + M[0][2] = B[0][0] * A[0][2] + B[0][1] * A[1][2] + B[0][2] * A[2][2]; + + M[1][0] = B[1][0] * A[0][0] + B[1][1] * A[1][0] + B[1][2] * A[2][0]; + M[1][1] = B[1][0] * A[0][1] + B[1][1] * A[1][1] + B[1][2] * A[2][1]; + M[1][2] = B[1][0] * A[0][2] + B[1][1] * A[1][2] + B[1][2] * A[2][2]; + + M[2][0] = B[2][0] * A[0][0] + B[2][1] * A[1][0] + B[2][2] * A[2][0]; + M[2][1] = B[2][0] * A[0][1] + B[2][1] * A[1][1] + B[2][2] * A[2][1]; + M[2][2] = B[2][0] * A[0][2] + B[2][1] * A[1][2] + B[2][2] * A[2][2]; + } else { + memcpy(M, B, sizeof(B)); + } + } else { + memcpy(M, A, sizeof(A)); + } + + if (Minv) { + memcpy(A, M, sizeof(A)); + if (!invert(A, Minv)) { + errno = EINVAL; + return -1; + } + } + + return 0; +} + +/** + * Convert an RGB colour into another RGB colour space + * + * Both RGB colour spaces must have same gamma functions as sRGB + * + * @param r The red component of the colour to convert + * @param g The green component of the colour to convert + * @param b The blue component of the colour to convert + * @param M Conversion matrix, create with `libclut_model_get_rgb_conversion_matrix` + * @param out_r Output parameter for the new red component + * @param out_g Output parameter for the new green component + * @param out_b Output parameter for the new blue component + */ +void +(libclut_model_convert_rgb)(double r, double g, double b, libclut_colour_space_conversion_matrix_t M, + double *out_r, double *out_g, double *out_b) +{ + libclut_model_convert_rgb(r, g, b, M, out_r, out_g, out_b); +} + +/** + * Convert an RGB colour of a custom RGB colour space to CIE XYZ + * + * The RGB colour space must have same gamma functions as sRGB + * + * @param r The red component + * @param g The green component + * @param b The blue component + * @param M Conversion matrix, create with `libclut_model_get_rgb_conversion_matrix` + * @param x Output parameter for the X component + * @param y Output parameter for the Y component + * @param z Output parameter for the Z component + */ +void +(libclut_model_rgb_to_ciexyz)(double r, double g, double b, libclut_colour_space_conversion_matrix_t M, + double *x, double *y, double *z) +{ + libclut_model_rgb_to_ciexyz(r, g, b, M, x, y, z); +} + +/** + * Convert a CIE XYZ colour to a custom RGB colour space + * + * The RGB colour space must have same gamma functions as sRGB + * + * @param x The X component + * @param y The Y component + * @param z The Z component + * @param M Conversion matrix, create with `libclut_model_get_rgb_conversion_matrix` + * @param r Output parameter for the red component + * @param g Output parameter for the green component + * @param b Output parameter for the blue component + */ +void +(libclut_model_ciexyz_to_rgb)(double x, double y, double z, libclut_colour_space_conversion_matrix_t M, + double *r, double *g, double *b) +{ + libclut_model_ciexyz_to_rgb(x, y, z, M, r, g, b); +} diff --git a/libclut.h b/libclut.h new file mode 100644 index 0000000..f318df2 --- /dev/null +++ b/libclut.h @@ -0,0 +1,2396 @@ +/* See LICENSE file for copyright and license details. */ +#ifndef LIBCLUT_H +#define LIBCLUT_H + +#include <stddef.h> +#include <string.h> +#include <math.h> + +/* Not documented, may be removed or modified in the future. */ +#define LIBCLUT_ILLUMINANT_A .white_x = 0.44757, .white_y = 0.40745, .white_Y = 1 +#define LIBCLUT_ILLUMINANT_B .white_x = 0.34842, .white_y = 0.35161, .white_Y = 1 +#define LIBCLUT_ILLUMINANT_C .white_x = 0.31006, .white_y = 0.31616, .white_Y = 1 +#define LIBCLUT_ILLUMINANT_D50 .white_x = 0.34567, .white_y = 0.35850, .white_Y = 1 +#define LIBCLUT_ILLUMINANT_D55 .white_x = 0.33242, .white_y = 0.34743, .white_Y = 1 +#define LIBCLUT_ILLUMINANT_D65 .white_x = 0.31271, .white_y = 0.32902, .white_Y = 1 +#define LIBCLUT_ILLUMINANT_D75 .white_x = 0.29902, .white_y = 0.31485, .white_Y = 1 +#define LIBCLUT_ILLUMINANT_E .white_x = 1. / 3, .white_y = 1. / 3, .white_Y = 1 +#define LIBCLUT_ILLUMINANT_F1 .white_x = 0.31310, .white_y = 0.33727, .white_Y = 1 +#define LIBCLUT_ILLUMINANT_F2 .white_x = 0.37208, .white_y = 0.37529, .white_Y = 1 +#define LIBCLUT_ILLUMINANT_F3 .white_x = 0.40910, .white_y = 0.39430, .white_Y = 1 +#define LIBCLUT_ILLUMINANT_F4 .white_x = 0.44018, .white_y = 0.40329, .white_Y = 1 +#define LIBCLUT_ILLUMINANT_F5 .white_x = 0.31379, .white_y = 0.34531, .white_Y = 1 +#define LIBCLUT_ILLUMINANT_F6 .white_x = 0.37790, .white_y = 0.38835, .white_Y = 1 +#define LIBCLUT_ILLUMINANT_F7 .white_x = 0.31292, .white_y = 0.32933, .white_Y = 1 +#define LIBCLUT_ILLUMINANT_F8 .white_x = 0.34588, .white_y = 0.35875, .white_Y = 1 +#define LIBCLUT_ILLUMINANT_F9 .white_x = 0.37417, .white_y = 0.37281, .white_Y = 1 +#define LIBCLUT_ILLUMINANT_F10 .white_x = 0.34609, .white_y = 0.35986, .white_Y = 1 +#define LIBCLUT_ILLUMINANT_F11 .white_x = 0.38052, .white_y = 0.37713, .white_Y = 1 +#define LIBCLUT_ILLUMINANT_F12 .white_x = 0.43695, .white_y = 0.40441, .white_Y = 1 + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the sRGB colour space + * + * sRGB does not use a regular gamma function, but rather two different + * functions. `libclut_model_linear_to_standard1` and + * and `libclut_model_standard_to_linear1` can be used so to convert + * between sRGB and linear sRGB + */ +#define LIBCLUT_RGB_COLOUR_SPACE_SRGB_INITIALISER {\ + .red_x = 0.6400, .red_y = 0.3300, .red_Y = 0.212656,\ + .green_x = 0.3000, .green_y = 0.6000, .green_Y = 0.715158,\ + .blue_x = 0.1500, .blue_y = 0.0600, .blue_Y = 0.072186,\ + LIBCLUT_ILLUMINANT_D65} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the Adobe RGB (1998) colour space + * + * This colour space's gamma is 2.2. It cannot be used with + * RGB colour space conversion unless the values are tranlated into + * using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_ADOBE_RGB_INITIALISER {\ + .red_x = 0.6400, .red_y = 0.3300, .red_Y = 0.297361,\ + .green_x = 0.2100, .green_y = 0.7100, .green_Y = 0.627355,\ + .blue_x = 0.1500, .blue_y = 0.0600, .blue_Y = 0.075285,\ + LIBCLUT_ILLUMINANT_D65} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the Apple RGB colour space + * + * This colour space's gamma is 1.8. It cannot be used with + * RGB colour space conversion unless the values are tranlated into + * using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_APPLE_RGB_INITIALISER {\ + .red_x = 0.6250, .red_y = 0.3400, .red_Y = 0.244634,\ + .green_x = 0.2800, .green_y = 0.5950, .green_Y = 0.672034,\ + .blue_x = 0.1550, .blue_y = 0.0700, .blue_Y = 0.083332,\ + LIBCLUT_ILLUMINANT_D65} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the Best RGB colour space + * + * This colour space's gamma is 2.2. It cannot be used with + * RGB colour space conversion unless the values are tranlated into + * using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_BEST_RGB_INITIALISER {\ + .red_x = 0.7347, .red_y = 0.2653, .red_Y = 0.228457,\ + .green_x = 0.2150, .green_y = 0.7750, .green_Y = 0.737352,\ + .blue_x = 0.1300, .blue_y = 0.0350, .blue_Y = 0.034191,\ + LIBCLUT_ILLUMINANT_D50} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the Beta RGB colour space + * + * This colour space's gamma is 2.2. It cannot be used with + * RGB colour space conversion unless the values are tranlated into + * using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_BETA_RGB_INITIALISER {\ + .red_x = 0.6888, .red_y = 0.3112, .red_Y = 0.303273,\ + .green_x = 0.1986, .green_y = 0.7551, .green_Y = 0.663786,\ + .blue_x = 0.1265, .blue_y = 0.0352, .blue_Y = 0.032941,\ + LIBCLUT_ILLUMINANT_D50} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the Bruce RGB colour space + * + * This colour space's gamma is 2.2. It cannot be used with + * RGB colour space conversion unless the values are tranlated into + * using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_BRUCE_RGB_INITIALISER {\ + .red_x = 0.6400, .red_y = 0.3300, .red_Y = 0.240995,\ + .green_x = 0.2800, .green_y = 0.6500, .green_Y = 0.683554,\ + .blue_x = 0.1500, .blue_y = 0.0600, .blue_Y = 0.075452,\ + LIBCLUT_ILLUMINANT_D65} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the CIE RGB colour space + * + * This colour space's gamma is 2.2. It cannot be used with + * RGB colour space conversion unless the values are tranlated into + * using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_CIE_RGB_INITIALISER {\ + .red_x = 0.7350, .red_y = 0.2650, .red_Y = 0.176204,\ + .green_x = 0.2740, .green_y = 0.7170, .green_Y = 0.812985,\ + .blue_x = 0.1670, .blue_y = 0.0090, .blue_Y = 0.010811,\ + LIBCLUT_ILLUMINANT_E} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the ColorMatch RGB colour space + * + * This colour space's gamma is 1.8. It cannot be used with + * RGB colour space conversion unless the values are tranlated into + * using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_COLORMATCH_RGB_INITIALISER {\ + .red_x = 0.6300, .red_y = 0.3400, .red_Y = 0.274884,\ + .green_x = 0.2950, .green_y = 0.6050, .green_Y = 0.658132,\ + .blue_x = 0.1500, .blue_y = 0.0750, .blue_Y = 0.066985,\ + LIBCLUT_ILLUMINANT_D50} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the DCI-P3 D65 colour space + * + * This colour space's gamma is 2.6. It cannot be used with + * RGB colour space conversion unless the values are tranlated into + * using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_DCI_P3_D65_INITIALISER {\ + .red_x = 0.680, .red_y = 0.320, .red_Y = 0.22897344,\ + .green_x = 0.265, .green_y = 0.690, .green_Y = 0.69175166,\ + .blue_x = 0.150, .blue_y = 0.060, .blue_Y = 0.07927490,\ + LIBCLUT_ILLUMINANT_D50} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the DCI-P3 Theater colour space + * + * This colour space's gamma is 2.6. It cannot be used with + * RGB colour space conversion unless the values are tranlated into + * using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_DCI_P3_THEATER_INITIALISER {\ + .red_x = 0.680, .red_y = 0.320, .red_Y = 0.20949168,\ + .green_x = 0.265, .green_y = 0.690, .green_Y = 0.72159525,\ + .blue_x = 0.150, .blue_y = 0.060, .blue_Y = 0.06891307,\ + .white_x = 0.314, .white_y = 0.351, .white_Y = 1} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the Don RGB 4 colour space + * + * This colour space's gamma is 2.2. It cannot be used with + * RGB colour space conversion unless the values are tranlated into + * using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_DON_RGB_4_INITIALISER {\ + .red_x = 0.6960, .red_y = 0.3000, .red_Y = 0.278350,\ + .green_x = 0.2150, .green_y = 0.7650, .green_Y = 0.687970,\ + .blue_x = 0.1300, .blue_y = 0.0350, .blue_Y = 0.033680,\ + LIBCLUT_ILLUMINANT_D50} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the ECI RGB v2 colour space + * + * This colour space's used the L* gamma function. It cannot + * be used with RGB colour space conversion unless the values are + * tranlated into using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_ECI_RGB_V2_INITIALISER {\ + .red_x = 0.6700, .red_y = 0.3300, .red_Y = 0.320250,\ + .green_x = 0.2100, .green_y = 0.7100, .green_Y = 0.602071,\ + .blue_x = 0.1400, .blue_y = 0.0800, .blue_Y = 0.077679,\ + LIBCLUT_ILLUMINANT_D50} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the Ekta Space PS5 colour space + * + * This colour space's gamma is 2.2. It cannot be used with + * RGB colour space conversion unless the values are tranlated into + * using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_EKTA_SPACE_PS5_INITIALISER {\ + .red_x = 0.6950, .red_y = 0.3050, .red_Y = 0.260629,\ + .green_x = 0.2600, .green_y = 0.7000, .green_Y = 0.734946,\ + .blue_x = 0.1100, .blue_y = 0.0050, .blue_Y = 0.004425,\ + LIBCLUT_ILLUMINANT_D50} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the ITU-R Recommendation BT.601 (ITU-R BT.601), 625 line colour + * space + * + * This colour space uses a custom gamma function. It cannot be used + * with RGB colour space conversion unless the values are tranlated + * into using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_ITU_R_BT_601_625_LINE_INITIALISER {\ + .red_x = 0.640, .red_y = 0.330, .red_Y = 0.2220023,\ + .green_x = 0.290, .green_y = 0.600, .green_Y = 0.7066689,\ + .blue_x = 0.150, .blue_y = 0.060, .blue_Y = 0.0713288,\ + LIBCLUT_ILLUMINANT_D65} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the ITU-R Recommendation BT.601 (ITU-R BT.601), 525 line colour + * space + * + * This colour space uses a custom gamma function. It cannot be used + * with RGB colour space conversion unless the values are tranlated + * into using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_ITU_R_BT_601_525_LINE_INITIALISER {\ + .red_x = 0.630, .red_y = 0.340, .red_Y = 0.2220023,\ + .green_x = 0.310, .green_y = 0.595, .green_Y = 0.7066689,\ + .blue_x = 0.155, .blue_y = 0.070, .blue_Y = 0.0713288,\ + LIBCLUT_ILLUMINANT_D65} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the ITU-R Recommendation BT.709 (ITU-R BT.709) colour space + * + * This colour space's gamma is 2._. It cannot be used with + * RGB colour space conversion unless the values are tranlated into + * using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_ITU_R_BT_709_INITIALISER {\ + .red_x = 0.6400, .red_y = 0.3300, .red_Y = 0.212656,\ + .green_x = 0.3000, .green_y = 0.6000, .green_Y = 0.715158,\ + .blue_x = 0.1500, .blue_y = 0.0600, .blue_Y = 0.072186,\ + LIBCLUT_ILLUMINANT_D65} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the ITU-R Recommendation BT.2020 (ITU-R BT.2020) colour space + * + * This colour space uses a custom gamma function. It cannot be used + * with RGB colour space conversion unless the values are tranlated + * into using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_ITU_R_BT_2020_INITIALISER {\ + .red_x = 0.7080, .red_y = 0.2920, .red_Y = 0.2627296,\ + .green_x = 0.1700, .green_y = 0.7970, .green_Y = 0.6767483,\ + .blue_x = 0.1310, .blue_y = 0.0460, .blue_Y = 0.0605221,\ + LIBCLUT_ILLUMINANT_D65} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the ITU-R Recommendation BT.2100 (ITU-R BT.2100) colour space + * + * This colour space uses a custom gamma function. It cannot be used + * with RGB colour space conversion unless the values are tranlated + * into using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_ITU_R_BT_2100_INITIALISER {\ + .red_x = 0.7080, .red_y = 0.2920, .red_Y = 0.2627296,\ + .green_x = 0.1700, .green_y = 0.7970, .green_Y = 0.6767483,\ + .blue_x = 0.1310, .blue_y = 0.0460, .blue_Y = 0.0605221,\ + LIBCLUT_ILLUMINANT_D65} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the Lightroom RGB colour space + * + * This colour space's gamma is 1 (linear). It cannot be used with + * RGB colour space conversion unless the values are tranlated into + * using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_LIGHTROOM_RGB_INITIALISER {\ + .red_x = 0.7347, .red_y = 0.2653, .red_Y = 0.288040,\ + .green_x = 0.1596, .green_y = 0.8404, .green_Y = 0.711874,\ + .blue_x = 0.0366, .blue_y = 0.0001, .blue_Y = 0.000086,\ + LIBCLUT_ILLUMINANT_D50} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the NTSC RGB colour space + * + * This colour space's gamma is 2.2. It cannot be used with + * RGB colour space conversion unless the values are tranlated into + * using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_NTSC_RGB_INITIALISER {\ + .red_x = 0.6700, .red_y = 0.3300, .red_Y = 0.298839,\ + .green_x = 0.2100, .green_y = 0.7100, .green_Y = 0.586811,\ + .blue_x = 0.1400, .blue_y = 0.0800, .blue_Y = 0.114350,\ + LIBCLUT_ILLUMINANT_C} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the PAL/SECAM RGB colour space + * + * This colour space's gamma is 2.2. It cannot be used with + * RGB colour space conversion unless the values are tranlated into + * using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_PAL_SECAM_RGB_INITIALISER {\ + .red_x = 0.6400, .red_y = 0.3300, .red_Y = 0.222021,\ + .green_x = 0.2900, .green_y = 0.6000, .green_Y = 0.706645,\ + .blue_x = 0.1500, .blue_y = 0.0600, .blue_Y = 0.071334,\ + LIBCLUT_ILLUMINANT_D65} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the ProPhoto RGB colour space + * + * This colour space's gamma is 1.8. It cannot be used with + * RGB colour space conversion unless the values are tranlated into + * using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_PROPHOTO_RGB_INITIALISER {\ + .red_x = 0.7347, .red_y = 0.2653, .red_Y = 0.288040,\ + .green_x = 0.1596, .green_y = 0.8404, .green_Y = 0.711874,\ + .blue_x = 0.0366, .blue_y = 0.0001, .blue_Y = 0.000086,\ + LIBCLUT_ILLUMINANT_D50} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the SMPTE-C RGB colour space + * + * This colour space's gamma is 2.2. It cannot be used with + * RGB colour space conversion unless the values are tranlated into + * using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_SMPTE_C_RGB_INITIALISER {\ + .red_x = 0.6300, .red_y = 0.3400, .red_Y = 0.212395,\ + .green_x = 0.3100, .green_y = 0.5950, .green_Y = 0.701049,\ + .blue_x = 0.1550, .blue_y = 0.0700, .blue_Y = 0.086556,\ + LIBCLUT_ILLUMINANT_D65} + +/** + * Initialiser for `struct libclut_rgb_colour_space` with the values + * of the Wide Gamut RGB colour space + * + * This colour space's gamma is 2.2. It cannot be used with + * RGB colour space conversion unless the values are tranlated into + * using the sRGB gamma function. + */ +#define LIBCLUT_RGB_COLOUR_SPACE_WIDE_GAMUT_RGB_INITIALISER {\ + .red_x = 0.7350, .red_y = 0.2650, .red_Y = 0.258187,\ + .green_x = 0.1150, .green_y = 0.8260, .green_Y = 0.724938,\ + .blue_x = 0.1570, .blue_y = 0.0180, .blue_Y = 0.016875,\ + LIBCLUT_ILLUMINANT_D50} + +/* + * TODO gamma functions: + * https://en.wikipedia.org/wiki/Rec._2020#Transfer_characteristics + * http://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.2100-0-201607-I!!PDF-E.pdf + * https://en.wikipedia.org/wiki/Rec._601 + */ + +/** + * RGB colour space structure + */ +typedef struct libclut_rgb_colour_space { + /** + * The x-component of the red colour's xyY value + */ + double red_x; + + /** + * The y-component of the red colour's xyY value + */ + double red_y; + + /** + * The Y-component of the red colour's xyY value + */ + double red_Y; + + /** + * The x-component of the green colour's xyY value + */ + double green_x; + + /** + * The y-component of the green colour's xyY value + */ + double green_y; + + /** + * The Y-component of the green colour's xyY value + */ + double green_Y; + + /** + * The x-component of the blue colour's xyY value + */ + double blue_x; + + /** + * The y-component of the blue colour's xyY value + */ + double blue_y; + + /** + * The Y-component of the blue colour's xyY value + */ + double blue_Y; + + /** + * The x-component of the white point's xyY value + */ + double white_x; + + /** + * The y-component of the white point's xyY value + */ + double white_y; + + /** + * The Y-component of the white point's xyY value + */ + double white_Y; +} libclut_rgb_colour_space_t; + +/** + * Matrix date-type for colour space conversion + */ +typedef double libclut_colour_space_conversion_matrix_t[3][3]; + +/* This is to avoid warnings about comparing double, These are only + * used when it is safe, for example to test whether optimisations + * are possible. { */ +#if defined(__GNUC__) || defined(__clang__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wfloat-equal" +#endif +static inline int libclut_eq__(double a, double b) { return a == b; } +static inline int libclut_1__(double x) { return libclut_eq__(x, 1); } +static inline int libclut_0__(double x) { return libclut_eq__(x, 0); } +#if defined(__GNUC__) || defined(__clang__) +# pragma GCC diagnostic pop +#endif +/* } */ + +#if defined(__clang__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wdocumentation" +#endif + +/** + * Apply contrast correction on the colour curves using sRGB + * + * In this context, contrast is a measure of difference between + * the whitepoint and blackpoint, if the difference is 0 than + * they are both grey + * + * None of the parameter may have side-effects + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param r The contrast parameter for the red curve + * @param g The contrast parameter for the green curve + * @param b The contrast parameter for the blue curve + */ +#define libclut_rgb_contrast(clut, max, type, r, g, b)\ + do {\ + const double h__ = (double)5 / 10;\ + if (!libclut_1__(r)) libclut__(clut, red, type, (LIBCLUT_VALUE - (max) * h__) * (r) + (max) * h__);\ + if (!libclut_1__(g)) libclut__(clut, green, type, (LIBCLUT_VALUE - (max) * h__) * (g) + (max) * h__);\ + if (!libclut_1__(b)) libclut__(clut, blue, type, (LIBCLUT_VALUE - (max) * h__) * (b) + (max) * h__);\ + } while (0) + +/** + * Apply contrast correction on the colour curves using CIE xyY + * + * In this context, contrast is a measure of difference between + * the whitepoint and blackpoint, if the difference is 0 than + * they are both grey + * + * None of the parameter may have side-effects + * + * Requires linking with '-lclut' + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param r The contrast parameter for the red curve + * @param g The contrast parameter for the green curve + * @param b The contrast parameter for the blue curve + */ +#define libclut_cie_contrast(clut, max, type, r, g, b)\ + do {\ + const double h__ = (double)5 / 10;\ + libclut_cie__(clut, max, type, libclut_eq__((r), (g)) && libclut_eq__((g), (b)),\ + !libclut_1__(r), !libclut_1__(g), !libclut_1__(b),\ + (Y__ - h__) * (r) + h__, (Y__ - h__) * (g) + h__, (Y__ - h__) * (b) + h__);\ + } while (0) + +/** + * Apply brightness correction on the colour curves using sRGB + * + * In this context, brightness is a measure of the whiteness of the whitepoint + * + * None of the parameter may have side-effects + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param r The brightness parameter for the red curve + * @param g The brightness parameter for the green curve + * @param b The brightness parameter for the blue curve + */ +#define libclut_rgb_brightness(clut, max, type, r, g, b)\ + do {\ + if (!libclut_1__(r)) libclut__(clut, red, type, LIBCLUT_VALUE * (r));\ + if (!libclut_1__(g)) libclut__(clut, green, type, LIBCLUT_VALUE * (g));\ + if (!libclut_1__(b)) libclut__(clut, blue, type, LIBCLUT_VALUE * (b));\ + } while (0) + +/** + * Apply brightness correction on the colour curves using CIE xyY + * + * In this context, brightness is a measure of the whiteness of the whitepoint + * + * None of the parameter may have side-effects + * + * Requires linking with '-lclut' + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param r The brightness parameter for the red curve + * @param g The brightness parameter for the green curve + * @param b The brightness parameter for the blue curve + */ +#define libclut_cie_brightness(clut, max, type, r, g, b)\ + libclut_cie__(clut, max, type, libclut_eq__((r), (g)) && libclut_eq__((g), (b)),\ + !libclut_1__(r), !libclut_1__(g), !libclut_1__(b),\ + Y__ * (r), Y__ * (g), Y__ * (b)) + +/** + * Convert the curves from formatted in standard RGB to linear sRGB + * + * None of the parameter may have side-effects + * + * Requires linking with '-lclut', or '-lm' if + * `libclut_model_standard_to_linear1` is not undefined + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param r Whether to convert the red colour curve + * @param g Whether to convert the green colour curve + * @param b Whether to convert the blue colour curve + */ +#define libclut_linearise(clut, max, type, r, g, b)\ + do {\ + double m__ = (double)(max);\ + if (r) libclut__(clut, red, type, m__ * libclut_model_standard_to_linear1(LIBCLUT_VALUE / m__));\ + if (g) libclut__(clut, green, type, m__ * libclut_model_standard_to_linear1(LIBCLUT_VALUE / m__));\ + if (b) libclut__(clut, blue, type, m__ * libclut_model_standard_to_linear1(LIBCLUT_VALUE / m__));\ + } while (0) + +/** + * Convert the curves from formatted in linear sRGB to standard RGB + * + * None of the parameter may have side-effects + * + * Requires linking with '-lclut', or '-lm' if + * `libclut_model_linear_to_standard1` is not undefined + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param r Whether to convert the red colour curve + * @param g Whether to convert the green colour curve + * @param b Whether to convert the blue colour curve + */ +#define libclut_standardise(clut, max, type, r, g, b)\ + do {\ + double m__ = (double)(max);\ + if (r) libclut__(clut, red, type, m__ * libclut_model_linear_to_standard1(LIBCLUT_VALUE / m__));\ + if (g) libclut__(clut, green, type, m__ * libclut_model_linear_to_standard1(LIBCLUT_VALUE / m__));\ + if (b) libclut__(clut, blue, type, m__ * libclut_model_linear_to_standard1(LIBCLUT_VALUE / m__));\ + } while (0) + +/** + * Convert the curves between two RGB colour spaces + * + * Both RGB colour spaces must have same gamma functions as sRGB + * + * Requires that `clut->red_size`, `clut->green_size` + * and `clut->blue_size` are equal + * + * None of the parameter may have side-effects + * + * Requires linking with '-lclut', or '-lm' if + * `libclut_model_linear_to_standard1`, + * `libclut_model_standard_to_linear1`, or + * `libclut_model_convert_rgb` is not undefined + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param m Conversion matrix. Can be created with + * `libclut_model_get_rgb_conversion_matrix` + * @param trunc Truncate values that are out of gamut + */ +#define libclut_convert_rgb_inplace(clut, max, type, m, trunc)\ + do {\ + double m__ = (double)(max), r__, g__, b__;\ + size_t i__, n__ = (clut)->red_size;\ + for (i__ = 0; i__ < n__; i__++) {\ + r__ = (clut)->red[i__] / m__;\ + g__ = (clut)->green[i__] / m__;\ + b__ = (clut)->blue[i__] / m__;\ + libclut_model_convert_rgb(r__, g__, b__, m, &r__, &g__, &b__);\ + r__ *= m__;\ + g__ *= m__;\ + b__ *= m__;\ + if (trunc) {\ + if (r__ < 0)\ + r__ = 0;\ + else if (r__ > m__)\ + r__ = m__;\ + if (g__ < 0)\ + g__ = 0;\ + else if (g__ > m__)\ + g__ = m__;\ + if (b__ < 0)\ + b__ = 0;\ + else if (b__ > m__)\ + b__ = m__;\ + }\ + (clut)->red[i__] = (type)r__;\ + (clut)->green[i__] = (type)g__;\ + (clut)->blue[i__] = (type)b__;\ + }\ + } while (0) + +/** + * Convert the curves between two RGB colour spaces + * + * Both RGB colour spaces must have same gamma functions as sRGB + * + * None of the parameter may have side-effects + * + * Requires linking with '-lclut' if + * `libclut_model_linear_to_standard1`, + * `libclut_model_standard_to_linear1`, or + * `libclut_model_convert_rgb` is not undefined. + * Always requires linking with '-lm'. + * + * @param clut Pointer to the input gamma ramps, must have the + * arrays `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param m Conversion matrix. Can be created with + * `libclut_model_get_rgb_conversion_matrix` + * @param trunc Truncate values that are out of gamut + * @param out Pointer to the output gamma ramps, must have the + * arrays `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + */ +#define libclut_convert_rgb(clut, max, type, m, trunc, out)\ + do {\ + double m__ = (double)(max), r__, g__, b__, x__, y__;\ + size_t rn__ = (clut)->red_size;\ + size_t gn__ = (clut)->green_size;\ + size_t bn__ = (clut)->blue_size;\ + double w__;\ + size_t i__, j__, jj__;\ + for (i__ = 0; i__ < rn__; i__++) {\ + w__ = (double)i__ * gn__ / rn__;\ + j__ = (size_t)w__;\ + jj__ = j__ == gn__ ? j__ : (j__ + 1);\ + w__ = fmod(j__, (double)1);\ + x__ = (clut)->green[j__] / m__;\ + y__ = (clut)->green[jj__] / m__;\ + x__ = libclut_model_standard_to_linear1(x__);\ + y__ = libclut_model_standard_to_linear1(y__);\ + g__ = x__ * (1 - w__) + y__ * w__;\ + \ + w__ = (double)i__ * bn__ / rn__;\ + j__ = (size_t)w__;\ + jj__ = j__ == bn__ ? j__ : (j__ + 1);\ + w__ = fmod(j__, (double)1);\ + x__ = (clut)->blue[j__] / m__;\ + y__ = (clut)->blue[jj__] / m__;\ + x__ = libclut_model_standard_to_linear1(x__);\ + y__ = libclut_model_standard_to_linear1(y__);\ + b__ = x__ * (1 - w__) + y__ * w__;\ + \ + r__ = (M)[0][0] * r__ + (M)[0][1] * g__ + (M)[0][2] * b__;\ + r__ = libclut_model_linear_to_standard1(r__);\ + r__ *= m__;\ + if (trunc) {\ + if (r__ < 0)\ + r__ = 0;\ + else if (r__ > m__)\ + r__ = m__;\ + }\ + (out)->red[i__] = (type)r__;\ + }\ + for (i__ = 0; i__ < gn__; i__++) {\ + w__ = (double)i__ * rn__ / gn__;\ + j__ = (size_t)w__;\ + jj__ = j__ == rn__ ? j__ : (j__ + 1);\ + w__ = fmod(j__, (double)1);\ + x__ = (clut)->red[j__] / m__;\ + y__ = (clut)->red[jj__] / m__;\ + x__ = libclut_model_standard_to_linear1(x__);\ + y__ = libclut_model_standard_to_linear1(y__);\ + r__ = x__ * (1 - w__) + y__ * w__;\ + \ + w__ = (double)i__ * bn__ / gn__;\ + j__ = (size_t)w__;\ + jj__ = j__ == bn__ ? j__ : (j__ + 1);\ + w__ = fmod(j__, (double)1);\ + x__ = (clut)->blue[j__] / m__;\ + y__ = (clut)->blue[jj__] / m__;\ + x__ = libclut_model_standard_to_linear1(x__);\ + y__ = libclut_model_standard_to_linear1(y__);\ + b__ = x__ * (1 - w__) + y__ * w__;\ + \ + g__ = (M)[1][0] * r__ + (M)[0][1] * g__ + (M)[1][2] * b__;\ + g__ = libclut_model_linear_to_standard1(g__);\ + g__ *= m__;\ + if (trunc) {\ + if (g__ < 0)\ + g__ = 0;\ + else if (g__ > m__)\ + g__ = m__;\ + }\ + (out)->green[i__] = (type)g__;\ + }\ + for (i__ = 0; i__ < bn__; i__++) {\ + w__ = (double)i__ * rn__ / bn__;\ + j__ = (size_t)w__;\ + jj__ = j__ == rn__ ? j__ : (j__ + 1);\ + w__ = fmod(j__, (double)1);\ + x__ = (clut)->red[j__] / m__;\ + y__ = (clut)->red[jj__] / m__;\ + x__ = libclut_model_standard_to_linear1(x__);\ + y__ = libclut_model_standard_to_linear1(y__);\ + r__ = x__ * (1 - w__) + y__ * w__;\ + \ + w__ = (double)i__ * gn__ / bn__;\ + j__ = (size_t)w__;\ + jj__ = j__ == gn__ ? j__ : (j__ + 1);\ + w__ = fmod(j__, (double)1);\ + x__ = (clut)->green[j__] / m__;\ + y__ = (clut)->green[jj__] / m__;\ + x__ = libclut_model_standard_to_linear1(x__);\ + y__ = libclut_model_standard_to_linear1(y__);\ + g__ = x__ * (1 - w__) + y__ * w__;\ + \ + b__ = (M)[2][0] * r__ + (M)[2][1] * g__ + (M)[2][2] * b__;\ + b__ = libclut_model_linear_to_standard1(b__);\ + b__ *= m__;\ + if (trunc) {\ + if (b__ < 0)\ + b__ = 0;\ + else if (b__ > m__)\ + b__ = m__;\ + }\ + (out)->blue[i__] = (type)b__;\ + }\ + } while (0) + +/** + * Apply gamma correction on the colour curves + * + * None of the parameter may have side-effects + * + * Requires linking with '-lm' + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param r The gamma parameter the red colour curve + * @param g The gamma parameter the green colour curve + * @param b The gamma parameter the blue colour curve + */ +#define libclut_gamma(clut, max, type, r, g, b)\ + do {\ + double m__ = (double)(max);\ + if (!libclut_1__(r)) libclut__(clut, red, type, m__ * pow(LIBCLUT_VALUE / m__, 1 / (double)(r)));\ + if (!libclut_1__(g)) libclut__(clut, green, type, m__ * pow(LIBCLUT_VALUE / m__, 1 / (double)(g)));\ + if (!libclut_1__(b)) libclut__(clut, blue, type, m__ * pow(LIBCLUT_VALUE / m__, 1 / (double)(b)));\ + } while (0) + +/** + * Reverse the colour curves (negative image with gamma preservation) + * + * None of the parameter may have side-effects + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps. + * This parameter is not used, it is just a dummy, to unify + * the API with the other functions + * @param type The data type used for each stop in the ramps + * @param r Whether to invert the red colour curve + * @param g Whether to invert the green colour curve + * @param b Whether to invert the blue colour curve + */ +#define libclut_negative(clut, max, type, r, g, b)\ + do {\ + size_t i__, n__;\ + type t__;\ + if (r) {\ + for (i__ = 0, n__ = (clut)->red_size; i__ < (n__ >> 1); i__++) {\ + t__ = (clut)->red[i__];\ + (clut)->red[i__] = (clut)->red[n__ - i__ - 1];\ + (clut)->red[n__ - i__ - 1] = t__;\ + }\ + }\ + if (g) {\ + for (i__ = 0, n__ = (clut)->green_size; i__ < (n__ >> 1); i__++) {\ + t__ = (clut)->green[i__];\ + (clut)->green[i__] = (clut)->green[n__ - i__ - 1];\ + (clut)->green[n__ - i__ - 1] = t__;\ + }\ + }\ + if (b) {\ + for (i__ = 0, n__ = (clut)->blue_size; i__ < (n__ >> 1); i__++) {\ + t__ = (clut)->blue[i__];\ + (clut)->blue[i__] = (clut)->blue[n__ - i__ - 1];\ + (clut)->blue[n__ - i__ - 1] = t__;\ + }\ + }\ + } while (0) + +/** + * Invert the colour curves (negative image with gamma invertion), using sRGB + * + * None of the parameter may have side-effects + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param r Whether to invert the red colour curve + * @param g Whether to invert the green colour curve + * @param b Whether to invert the blue colour curve + */ +#define libclut_rgb_invert(clut, max, type, r, g, b)\ + do {\ + if (r) libclut__(clut, red, type, (max) - LIBCLUT_VALUE);\ + if (g) libclut__(clut, green, type, (max) - LIBCLUT_VALUE);\ + if (b) libclut__(clut, blue, type, (max) - LIBCLUT_VALUE);\ + } while (0) + +/** + * Invert the colour curves (negative image with gamma invertion), using CIE xyY + * + * None of the parameter may have side-effects + * + * Requires linking with '-lclut' + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param r Whether to invert the red colour curve + * @param g Whether to invert the green colour curve + * @param b Whether to invert the blue colour curve + */ +#define libclut_cie_invert(clut, max, type, r, g, b)\ + libclut_cie__(clut, max, type, (r) && (g) && (b), r, g, b, 1 - Y__, 1 - Y__, 1 - Y__) + +/** + * Apply S-curve correction on the colour curves. + * This is intended for fine tuning LCD monitors, + * 4.5 is good value start start testing at. + * You would probably like to use rgb_limits before + * this to adjust the blackpoint as that is the + * only way to adjust the blackpoint on many LCD + * monitors. + * + * None of the parameter may have side-effects + * + * Requires linking with '-lm' + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param rp Pointer to the sigmoid parameter for the red curve. `NULL` for no adjustment + * @param gp Pointer to the sigmoid parameter for the green curve. `NULL` for no adjustment + * @param bp Pointer to the sigmoid parameter for the blue curve. `NULL` for no adjustment + */ +#define libclut_sigmoid(clut, max, type, rp, gp, bp)\ + do {\ + double *gcc_6_1_1_workaround, m__ = (double)(max);\ + const double h__ = (double)5 / 10;\ + gcc_6_1_1_workaround = rp;\ + if (gcc_6_1_1_workaround)\ + libclut_sigmoid__(clut, max, type, red);\ + gcc_6_1_1_workaround = gp;\ + if (gcc_6_1_1_workaround)\ + libclut_sigmoid__(clut, max, type, green);\ + gcc_6_1_1_workaround = bp;\ + if (gcc_6_1_1_workaround)\ + libclut_sigmoid__(clut, max, type, blue);\ + }\ + while (0) + +/** + * Apply S-curve correction on the colour curves. + * This is intended for fine tuning LCD monitors, + * 4.5 is good value start start testing at. + * You would probably like to use rgb_limits before + * this to adjust the blackpoint as that is the + * only way to adjust the blackpoint on many LCD + * monitors. + * + * None of the parameter may have side-effects + * + * Requires linking with '-lm' + * + * Intended for internal use + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param channel The channel, must be either "red", "green", or "blue" + */ +#define libclut_sigmoid__(clut, max, type, channel)\ + do {\ + double s__ = *gcc_6_1_1_workaround, l__;\ + size_t i__;\ + for (i__ = 0; i__ < (clut)->channel##_size; i__++) {\ + l__ = log(m__ / (clut)->channel[i__] - 1);\ + if (isnan(l__) || isinf(l__))\ + l__ = 37.024483 * (isinf(l__) > 0 ? +1 : -1);\ + (clut)->channel[i__] = (type)(m__ * (h__ - l__ / s__));\ + }\ + } while (0) + +/** + * Changes the blackpoint and the whitepoint, using sRGB + * + * None of the parameter may have side-effects + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param rmin The red component value of the blackpoint + * @param rmax The red component value of the whitepoint + * @param gmin The green component value of the blackpoint + * @param gmax The green component value of the whitepoint + * @param bmin The blue component value of the blackpoint + * @param bmax The blue component value of the whitepoint + */ +#define libclut_rgb_limits(clut, max, type, rmin, rmax, gmin, gmax, bmin, bmax)\ + do {\ + double diff__;\ + if (!libclut_0__(rmin) || !libclut_1__(rmax)) {\ + diff__ = (double)(rmax) - (double)(rmin);\ + libclut__(clut, red, type, LIBCLUT_VALUE / (double)(max) * diff__ + (rmin));\ + }\ + if (!libclut_0__(gmin) || !libclut_1__(gmax)) {\ + diff__ = (double)(gmax) - (double)(gmin);\ + libclut__(clut, green, type, LIBCLUT_VALUE / (double)(max) * diff__ + (gmin));\ + }\ + if (!libclut_0__(bmin) || !libclut_1__(bmax)) {\ + diff__ = (double)(bmax) - (double)(bmin);\ + libclut__(clut, blue, type, LIBCLUT_VALUE / (double)(max) * diff__ + (bmin));\ + }\ + } while (0) + +/** + * Changes the blackpoint and the whitepoint, using CIE xyY + * + * None of the parameter may have side-effects + * + * Requires linking with '-lclut' + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param rmin The red component value of the blackpoint + * @param rmax The red component value of the whitepoint + * @param gmin The green component value of the blackpoint + * @param gmax The green component value of the whitepoint + * @param bmin The blue component value of the blackpoint + * @param bmax The blue component value of the whitepoint + */ +#define libclut_cie_limits(clut, max, type, rmin, rmax, gmin, gmax, bmin, bmax)\ + do {\ + double rd__ = (rmax) - (rmin), gd__ = (gmax) - (gmin), bd__ = (bmax) - (bmin);\ + libclut_cie__(clut, max, type,\ + libclut_eq__((rmin), (gmin)) && libclut_eq__((gmin), (bmin)) &&\ + libclut_eq__((rmax), (gmax)) && libclut_eq__((gmax), (bmax)),\ + !libclut_0__(rmin) || !libclut_1__(rmax),\ + !libclut_0__(gmin) || !libclut_1__(gmax),\ + !libclut_0__(bmin) || !libclut_1__(bmax),\ + Y__ * rd__ + (rmin), Y__ * gd__ + (gmin), Y__ * bd__ + (bmin));\ + } while (0) + +/** + * Manipulate the colour curves using a function on the sRGB colour space + * + * None of the parameter may have side-effects + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param r Function to manipulate the red colour curve, should either + * be `NULL` or map a [0, 1] `double` to a [0, 1] `double` + * @param g Function to manipulate the green colour curve, should either + * be `NULL` or map a [0, 1] `double` to a [0, 1] `double` + * @param b Function to manipulate the blue colour curve, should either + * be `NULL` or map a [0, 1] `double` to a [0, 1] `double` + */ +#define libclut_manipulate(clut, max, type, r, g, b)\ + do {\ + double m__ = (double)(max);\ + double (*gcc_6_1_1_workaround__)(double);\ + gcc_6_1_1_workaround__ = r;\ + if (gcc_6_1_1_workaround__)\ + libclut__(clut, red, type, m__ * (gcc_6_1_1_workaround__)(LIBCLUT_VALUE / m__));\ + gcc_6_1_1_workaround__ = g;\ + if (gcc_6_1_1_workaround__)\ + libclut__(clut, green, type, m__ * (gcc_6_1_1_workaround__)(LIBCLUT_VALUE / m__));\ + gcc_6_1_1_workaround__ = b;\ + if (gcc_6_1_1_workaround__)\ + libclut__(clut, blue, type, m__ * (gcc_6_1_1_workaround__)(LIBCLUT_VALUE / m__));\ + } while (0) + +/** + * Manipulate the colour curves using a function on the CIE xyY colour space + * + * None of the parameter may have side-effects + * + * Requires linking with '-lclut' + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param r Function to manipulate the red colour curve, should either + * be `NULL` or map a [0, 1] `double` to a [0, 1] `double` + * @param g Function to manipulate the green colour curve, should either + * be `NULL` or map a [0, 1] `double` to a [0, 1] `double` + * @param b Function to manipulate the blue colour curve, should either + * be `NULL` or map a [0, 1] `double` to a [0, 1] `double` + */ +#define libclut_cie_manipulate(clut, max, type, r, g, b)\ + libclut_cie__(clut, max, type, (r) && (g) && (b), r, g, b, (r)(Y__), (g)(Y__), (b)(Y__)) + +/** + * Resets colour curvers to linear mappings + * (Identity mapping if imaginged to map from [0, 1] to [0, 1]) + * + * None of the parameter may have side-effects + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param r Whether to reset the red colour curve + * @param g Whether to reset the green colour curve + * @param b Whether to reset the blue colour curve + */ +#define libclut_start_over(clut, max, type, r, g, b)\ + do {\ + size_t i__;\ + double m__, max__ = (double)(max);\ + if (r) {\ + m__ = (double)((clut)->red_size - 1);\ + for (i__ = 0; i__ < (clut)->red_size; i__++)\ + (clut)->red[i__] = (type)(((double)i__ / m__) * max__);\ + }\ + if (g) {\ + m__ = (double)((clut)->green_size - 1);\ + for (i__ = 0; i__ < (clut)->green_size; i__++)\ + (clut)->green[i__] = (type)(((double)i__ / m__) * max__);\ + }\ + if (b) {\ + m__ = (double)((clut)->blue_size - 1);\ + for (i__ = 0; i__ < (clut)->blue_size; i__++)\ + (clut)->blue[i__] = (type)(((double)i__ / m__) * max__);\ + }\ + } while (0) + +/** + * Clip colour curves to only map to values between the minimum and maximum. + * This should be done, before apply the curves, and before applying changes + * with limited domain. + * + * Values below 0 are set to 0, and values above `max` are set to `max` + * + * None of the parameter may have side-effects + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param r Whether to clip the red colour curve + * @param g Whether to clip the green colour curve + * @param b Whether to clip the blue colour curve + */ +#define libclut_clip(clut, max, type, r, g, b)\ + do {\ + if (r) libclut__(clut, red, type, libclut_clip__(0, LIBCLUT_VALUE, max));\ + if (g) libclut__(clut, green, type, libclut_clip__(0, LIBCLUT_VALUE, max));\ + if (b) libclut__(clut, blue, type, libclut_clip__(0, LIBCLUT_VALUE, max));\ + } while (0) + +/** + * Truncates a value to fit a boundary + * + * None of the parameter may have side-effects + * + * Intended for internal use + * + * @param min The minimum allowed value + * @param val The current value + * @param max The maximum allowed value + * @return The value truncated into its boundary + */ +#define libclut_clip__(min, val, max)\ + (LIBCLUT_VALUE < (min) ? (min) : LIBCLUT_VALUE > (max) ? (max) : LIBCLUT_VALUE) + +/** + * Emulates low colour resolution + * + * None of the parameter may have side-effects + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param rx The desired emulated red encoding resolution, 0 for unchanged + * @param ry The desired emulated red output resolution, 0 for unchanged + * @param gx The desired emulated green encoding resolution, 0 for unchanged + * @param gy The desired emulated green output resolution, 0 for unchanged + * @param bx The desired emulated blue encoding resolution, 0 for unchanged + * @param by The desired emulated blue output resolution, 0 for unchanged + */ +#define libclut_lower_resolution(clut, max, type, rx, ry, gx, gy, bx, by)\ + do {\ + libclut_lower_resolution__(clut, red, max, type, rx, ry);\ + libclut_lower_resolution__(clut, green, max, type, gx, gy);\ + libclut_lower_resolution__(clut, blue, max, type, bx, by);\ + } while (0) + +/** + * Emulates low colour resolution of a channel + * + * None of the parameter may have side-effects + * + * Intended for internal use + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param channel The channel, must be either "red", "green", or "blue" + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param x The desired emulated encoding resolution, 0 for unchanged + * @param y The desired emulated output resolution, 0 for unchanged + */ +#define libclut_lower_resolution__(clut, channel, max, type, x, y)\ + do {\ + if ((x) || (y)) {\ + size_t x__, y__, i__, n__ = (clut)->channel##_size;\ + double xm__ = (double)((x) - 1), ym__ = (double)((y) - 1);\ + double m__ = (double)(max), nm__ = (double)(n__ - 1);\ + type c__[n__]; /* Do not use alloca! */\ + const double h__ = (double)5 / 10;\ + for (i__ = 0; i__ < n__; i__++) {\ + if ((x__ = i__), (x)) {\ + x__ = (size_t)((double)i__ * (double)(x) / (double)n__);\ + x__ = (size_t)((double)x__ * nm__ / xm__);\ + }\ + if (!(y)) {\ + c__[i__] = (clut)->channel[x__];\ + } else {\ + y__ = (size_t)((double)((clut)->channel[x__]) / (max) * ym__ + h__);\ + c__[i__] = (type)((double)y__ / ym__ * m__);\ + }\ + }\ + memcpy((clut)->channel, c__, n__ * sizeof(type));\ + }\ + } while (0) + +/** + * Translates a gamma ramp structure to another gamma ramp structure type + * + * None of the parameter may have side-effects + * + * @param dclut Pointer to the desired gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars `red_size`, + * `green_size`, and `blue_size`. Ramp structures from + * libgamma or libcoopgamma can be used. + * @param dmax The maximum value on each stop in the ramps in `dclut` + * @param dtype The data type used for each stop in the ramps in `dclut` + * @param sclut Pointer to the set gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars `red_size`, + * `green_size`, and `blue_size`. Ramp structures from + * libgamma or libcoopgamma can be used + * @param smax The maximum value on each stop in the ramps in `sclut` + * @param stype The data type used for each stop in the ramps in `sclut` + * (Not actually used) + */ +#define libclut_translate(dclut, dmax, dtype, sclut, smax, stype)\ + do {\ + libclut_translate__(dclut, dmax, dtype, sclut, smax, stype, red);\ + libclut_translate__(dclut, dmax, dtype, sclut, smax, stype, green);\ + libclut_translate__(dclut, dmax, dtype, sclut, smax, stype, blue);\ + } while (0) + +/** + * Translates a gamma ramp structure to another gamma ramp structure type + * + * None of the parameter may have side-effects + * + * This is intended for internal use + * + * @param dclut Pointer to the desired gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars `red_size`, + * `green_size`, and `blue_size`. Ramp structures from + * libgamma or libcoopgamma can be used. + * @param dmax The maximum value on each stop in the ramps in `dclut` + * @param dtype The data type used for each stop in the ramps in `dclut` + * @param sclut Pointer to the set gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars `red_size`, + * `green_size`, and `blue_size`. Ramp structures from + * libgamma or libcoopgamma can be used. + * @param smax The maximum value on each stop in the ramps in `sclut` + * @param stype The data type used for each stop in the ramps in `sclut`. + * (Not actually used) + * @param channel The channel, must be either "red", "green", or "blue" + */ +#define libclut_translate__(dclut, dmax, dtype, sclut, smax, stype, channel)\ + do {\ + size_t di__, si__, sj__;\ + size_t dn__ = (dclut)->channel##_size;\ + size_t sn__ = (sclut)->channel##_size;\ + double dm__ = (double)(dmax);\ + double sm__ = (double)(smax);\ + double dmsm__ = dm__ / sm__;\ + double x__, y__;\ + if (dn__ == sn__) {\ + for (di__ = 0; di__ < dn__; di__++) {\ + y__ = (double)((sclut)->channel[di__]) * dmsm__;\ + (dclut)->channel[di__] = (dtype)y__;\ + }\ + } else {\ + for (di__ = 0; di__ < dn__; di__++) {\ + x__ = di__ / (dn__ - 1) * (sn__ - 1);\ + si__ = (size_t)(x__);\ + sj__ = si__ + (si__ != sn__);\ + x__ -= (double)si__;\ + y__ = (double)((sclut)->channel[si__]) * (1 - x__);\ + y__ += (double)((sclut)->channel[sj__]) * (x__);\ + y__ *= dmsm__;\ + (dclut)->channel[di__] = (dtype)y__;\ + }\ + }\ + } while (0) + +/** + * Applies a filter or calibration + * + * None of the parameter may have side-effects + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param filter Same as `clut`, but for the filter to apply + * @param fmax Same as `max`, but for the filter to apply + * @param ftype Same as `type`, but for the filter to apply (Not actually used) + * @param r Whether to apply the filter for the red curve + * @param g Whether to apply the filter for the green curve + * @param b Whether to apply the filter for the blue curve + */ +#define libclut_apply(clut, max, type, filter, fmax, ftype, r, g, b)\ + do {\ + if (r) libclut_apply__(clut, max, type, filter, fmax, ftype, red);\ + if (g) libclut_apply__(clut, max, type, filter, fmax, ftype, green);\ + if (b) libclut_apply__(clut, max, type, filter, fmax, ftype, blue);\ + } while (0) + +/** + * Applies a filter or calibration for one channel + * + * None of the parameter may have side-effects + * + * Intended for internal use + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param filter Same as `clut`, but for the filter to apply + * @param fmax Same as `max`, but for the filter to apply + * @param ftype Same as `type`, but for the filter to apply (Not actually used) + * @param channel The channel, must be either "red", "green", or "blue" + */ +#define libclut_apply__(clut, max, type, filter, fmax, ftype, channel)\ + do {\ + size_t i__, rn__ = (clut)->channel##_size, fn__ = (filter)->channel##_size - 1;\ + double x__, rm__ = (double)(max), m__ = (double)(max) / (double)(fmax);\ + for (i__ = 0; i__ < rn__; i__++) {\ + x__ = (double)((clut)->channel[i__]) / rm__ * (double)fn__;\ + (clut)->channel[i__] = (type)((double)((filter)->channel[(size_t)x__]) * m__);\ + }\ + } while (0) + +/** + * Applies a filter or calibration, using CIE xyY + * + * None of the parameter may have side-effects + * + * Requires linking with '-lclut' + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param filter Same as `clut`, but for the filter to apply + * @param fmax Same as `max`, but for the filter to apply + * @param ftype Same as `type`, but for the filter to apply (Not actually used) + * @param r Whether to apply the filter for the red curve + * @param g Whether to apply the filter for the green curve + * @param b Whether to apply the filter for the blue curve + */ +#define libclut_cie_apply(clut, max, type, filter, fmax, ftype, r, g, b)\ + do {\ + size_t rfn__ = (filter)->red_size - 1, gfn__ = (filter)->green_size - 1;\ + size_t bfn__ = (filter)->blue_size - 1, x__;\ + size_t rm__ = (double)(max), fm__ = (double)(fmax);\ + libclut_cie__(clut, max, type, 0, r, g, b,\ + (x__ = (size_t)(Y__ / rm__ * rfn__), (double)((filter)->red[x__]) / fm__),\ + (x__ = (size_t)(Y__ / rm__ * gfn__), (double)((filter)->green[x__]) / fm__),\ + (x__ = (size_t)(Y__ / rm__ * bfn__), (double)((filter)->blue[x__]) / fm__));\ + } while (0) + +/** + * Modify a ramp + * + * None of the parameter may have side-effects + * + * This is intended for internal use + * + * @param clut Pointer to the gamma ramps, must have and array + * named `channel` and a scalar named `channel` followed + * by "_size" + * @param channel The channel, must be either "red", "green", or "blue" + * @param type The data type used for each stop in the ramps + * @param expr Expression that evalutes the value a stop should have. + * It can use the variable `LIBCLUT_VALUE` to get the + * current value of the stop. + */ +#define libclut__(clut, channel, type, expr)\ + do {\ + size_t i__, n__ = (clut)->channel##_size;\ + type LIBCLUT_VALUE;\ + for (i__ = 0; i__ < n__; i__++) {\ + LIBCLUT_VALUE = (clut)->channel[i__];\ + (clut)->channel[i__] = (type)(expr);\ + }\ + } while (0) + +/** + * Modify a ramp set in CIE xyY + * + * None of the parameter may have side-effects + * + * Requires linking with '-lclut' + * + * This is intended for internal use + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param utest Whether all channels can be modified at the same time + * This test does not have to include the ramp size + * @param rtest Whether the red channel have to be modified + * @param gtest Whether the green channel have to be modified + * @param btest Whether the blue channel have to be modified + * @param rexpr Expression calculating the intensity of the red channel. + * The current value is stored in `Y__`. + * @param gexpr Expression calculating the intensity of the green channel. + * The current value is stored in `Y__`. + * @param bexpr Expression calculating the intensity of the blue channel. + * The current value is stored in `Y__`. + */ +#define libclut_cie__(clut, max, type, utest, rtest, gtest, btest, rexpr, gexpr, bexpr)\ + do {\ + size_t rn__ = (clut)->red_size;\ + size_t gn__ = (clut)->green_size;\ + size_t bn__ = (clut)->blue_size;\ + size_t i__;\ + double x__, y__, Y__, r__, g__, b__;\ + double m__ = (double)(max);\ + type* rs__ = (clut)->red;\ + type* gs__ = (clut)->green;\ + type* bs__ = (clut)->blue;\ + if ((rn__ == gn__) && (gn__ == bn__) && (utest)) {\ + if (!(rtest))\ + break;\ + for (i__ = 0; i__ < rn__; i__++) {\ + libclut_model_srgb_to_ciexyy(rs__[i__] / m__, gs__[i__] / m__,\ + bs__[i__] / m__, &x__, &y__, &Y__);\ + libclut_model_ciexyy_to_srgb(x__, y__, rexpr, &r__, &g__, &b__);\ + rs__[i__] = (type)(r__ * m__);\ + gs__[i__] = (type)(g__ * m__);\ + bs__[i__] = (type)(b__ * m__);\ + }\ + } else if ((rn__ == gn__) && (gn__ == bn__)) {\ + if (!(rtest) && !(gtest) && !(btest))\ + break;\ + for (i__ = 0; i__ < rn__; i__++) {\ + libclut_model_srgb_to_ciexyy(rs__[i__] / m__, gs__[i__] / m__,\ + bs__[i__] / m__, &x__, &y__, &Y__);\ + if (rtest) {\ + libclut_model_ciexyy_to_srgb(x__, y__, rexpr, &r__, &g__, &b__);\ + rs__[i__] = (type)(r__ * m__);\ + }\ + if (gtest) {\ + libclut_model_ciexyy_to_srgb(x__, y__, gexpr, &r__, &g__, &b__);\ + gs__[i__] = (type)(g__ * m__);\ + }\ + if (btest) {\ + libclut_model_ciexyy_to_srgb(x__, y__, bexpr, &r__, &g__, &b__);\ + bs__[i__] = (type)(b__ * m__);\ + }\ + }\ + } else {\ + if (rtest) {\ + for (i__ = 0; i__ < rn__; i__++) {\ + libclut_cie___(clut, max, type, r, rexpr, i__,\ + libclut_i__(i__, rn__, gn__),\ + libclut_i__(i__, rn__, bn__));\ + }\ + }\ + if (gtest) {\ + for (i__ = 0; i__ < rn__; i__++) {\ + libclut_cie___(clut, max, type, g, gexpr,\ + libclut_i__(i__, gn__, rn__), i__,\ + libclut_i__(i__, gn__, bn__));\ + }\ + }\ + if (btest) {\ + for (i__ = 0; i__ < rn__; i__++) {\ + libclut_cie___(clut, max, type, b, bexpr,\ + libclut_i__(i__, bn__, rn__),\ + libclut_i__(i__, bn__, gn__), i__);\ + }\ + }\ + }\ + } while (0) + +/** + * Modify a ramp stop in CIE xyY + * + * None of the parameter may have side-effects + * + * Requires linking with '-lclut' + * + * This is intended for internal use. + * Assumes the existence of variables defined in `libclut_cie__`. + * + * @param clut Pointer to the gamma ramps, must have the arrays + * `red`, `green`, and `blue`, and the scalars + * `red_size`, `green_size`, and `blue_size`. Ramp + * structures from libgamma or libcoopgamma can be used. + * @param max The maximum value on each stop in the ramps + * @param type The data type used for each stop in the ramps + * @param c Either "r" for red, "g" for green, or "b" for blue + * @param expr Expression calculating the intensity of the channel + * @param ri The index of the stop translated to the red channel + * @param gi The index of the stop translated to the green channel + * @param bi The index of the stop translated to the blue channel + */ +#define libclut_cie___(clut, max, type, c, expr, ri, gi, bi)\ + do {\ + for (i__ = 0; i__ < c##n__; i__++) {\ + libclut_model_srgb_to_ciexyy(rs__[(ri)] / m__, gs__[(gi)] / m__,\ + bs__[(bi)] / m__, &x__, &y__, &Y__);\ + libclut_model_ciexyy_to_srgb(x__, y__, expr, &r__, &g__, &b__);\ + c##s__[i__] = (type)(c##__ * m__);\ + }\ + } while (0) + +/** + * Translate an index from one channel to another + * + * @param i The index in the input channel + * @param in The size of the input channel + * @param out The size of the output channel + * @return The index in the output channel + */ +#define libclut_i__(i, in, out)\ + (size_t)((double)(i) * (double)(out) / (double)(in)) + +#if defined(__GNUC__) && !defined(__clang__) +# define LIBCLUT_GCC_ONLY__(x) x +#else +# define LIBCLUT_GCC_ONLY__(x) /* do nothing */ +#endif + +/** + * Convert one component from [0, 1] linear sRGB to [0, 1] sRGB + * + * If the macro variant is used, the argument must not have + * any side-effects. The macro variant requires linking with + * '-lm' + * + * @param c The linear sRGB value + * @return Corresponding sRGB value + */ +LIBCLUT_GCC_ONLY__(__attribute__((__const__, __leaf__))) +double (libclut_model_linear_to_standard1)(double); +#define libclut_model_linear_to_standard1(c)\ + (((double)(c) <= 0.0031308) ? (12.92 * (double)(c)) : ((1.055) * pow((double)(c), 1 / 2.4) - 0.055)) + +/** + * Convert [0, 1] linear sRGB to [0, 1] sRGB + * + * The macro variant requires linking with '-lm', + * if the 'libclut_model_linear_to_standard1' is defined, + * otherwise it requires linking with '-lclut' + * + * @param r Pointer to the linear red component, + * and output parameter for the red component + * @param g Pointer to the linear green component, + * and output parameter for the green component + * @param b Pointer to the linear blue component, + * and output parameter for the blue component + */ +void (libclut_model_linear_to_standard)(double *, double *, double *); +#define libclut_model_linear_to_standard(r, g, b)\ + do {\ + double *r__ = (r), *g__ = (g), *b__ = (b);\ + *r__ = libclut_model_linear_to_standard1(*r__);\ + *g__ = libclut_model_linear_to_standard1(*g__);\ + *b__ = libclut_model_linear_to_standard1(*b__);\ + } while (0) + +/** + * Convert one component from [0, 1] sRGB to [0, 1] linear sRGB + * + * If the macro variant is used, the argument must not have + * any side-effects. The macro variant requires linking with + * '-lm' + * + * @param c The sRGB value + * @return Corresponding linear sRGB value + */ +LIBCLUT_GCC_ONLY__(__attribute__((__const__, __leaf__))) +double (libclut_model_standard_to_linear1)(double); +#define libclut_model_standard_to_linear1(c) \ + (((double)(c) <= 0.04045) ? ((double)(c) / 12.92) : pow(((double)(c) + 0.055) / 1.055, 2.4)) + +/** + * Convert [0, 1] sRGB to [0, 1] linear sRGB + * + * The macro variant requires linking with '-lm', + * if the 'libclut_model_standard_to_linear1' is defined, + * otherwise it requires linking with '-lclut' + * + * @param r Pointer to the red component, and output + * parameter for the linear red component + * @param g Pointer to the green component, and output + * parameter for the linear green component + * @param b Pointer to the blue component, and output + * parameter for the linear blue component + */ +void (libclut_model_standard_to_linear)(double *, double *, double *); +#define libclut_model_standard_to_linear(r, g, b)\ + do {\ + double *r__ = (r), *g__ = (g), *b__ = (b);\ + *r__ = libclut_model_standard_to_linear1(*r__);\ + *g__ = libclut_model_standard_to_linear1(*g__);\ + *b__ = libclut_model_standard_to_linear1(*b__);\ + } while (0) + +/** + * Convert CIE xyY to CIE XYZ + * + * @param x The x parameter + * @param y The y parameter + * @param Y The Y parameter; this is also the Y (middle) parameter for the CIE XYZ colour + * @param X Output parameter for the X parameter + * @param Z Output parameter for the Z parameter + */ +LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) +void (libclut_model_ciexyy_to_ciexyz)(double, double, double, double *, double *); +#define libclut_model_ciexyy_to_ciexyz(x, y, Y, X, Z)\ + do {\ + double x__ = (x), y__ = (y), Y__ = (Y), *X__ = (X), *Z__ = (Z);\ + *X__ = libclut_0__(y__) ? Y__ : (Y__ * x__ / y__);\ + *Z__ = libclut_0__(y__) ? Y__ : (Y__ * (1 - x__ - y__) / y__);\ + } while (0) + +/** + * Convert CIE XYZ to CIE xyY + * + * @param X The X parameter + * @param Y The Y parameter; this is also the Y (last) parameter for the CIE xyY colour + * @param Z The Z parameter + * @param x Output parameter for the x parameter + * @param y Output parameter for the y parameter + */ +LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) +void (libclut_model_ciexyz_to_ciexyy)(double, double, double, double *, double *); +#define libclut_model_ciexyz_to_ciexyy(X, Y, Z, x, y)\ + do {\ + double X__ = (X), Y__ = (Y), Z__ = (Z), *x__ = (x), *y__ = (y);\ + double s__ = X__ + Y__ + Z__;\ + if (libclut_0__(s__))\ + *x__ = *y__ = 0;\ + else\ + *x__ = X__ / s__, *y__ = Y__ / s__;\ + } while (0) + +/** + * Convert CIE XYZ to [0, 1] linear sRGB + * + * @param X The X parameter + * @param Y The Y parameter + * @param Z The Z parameter + * @param r Output parameter for the red component + * @param g Output parameter for the green component + * @param b Output parameter for the blue component + */ +LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) +void (libclut_model_ciexyz_to_linear)(double, double, double, double *, double *, double *); +#define libclut_model_ciexyz_to_linear(X, Y, Z, r, g, b)\ + do {\ + double X__ = (X), Y__ = (Y), Z__ = (Z);\ + *(r) = ( 3.2404500 * X__) + (-1.537140 * Y__) + (-0.4985320 * Z__);\ + *(g) = (-0.9692660 * X__) + ( 1.876010 * Y__) + ( 0.0415561 * Z__);\ + *(b) = ( 0.0556434 * X__) + (-0.204026 * Y__) + ( 1.0572300 * Z__);\ + } while (0) + +/** + * Convert [0, 1] linear sRGB to CIE XYZ + * + * @param r The red component + * @param g The green component + * @param b The blue component + * @param X Output parameter for the X parameter + * @param Y Output parameter for the Y parameter + * @param Z Output parameter for the Z parameter + */ +LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) +void (libclut_model_linear_to_ciexyz)(double, double, double, double *, double *, double *); +#define libclut_model_linear_to_ciexyz(r, g, b, X, Y, Z)\ + do {\ + double r__ = (r), g__ = (g), b__ = (b);\ + *(X) = (0.4124564 * r__) + (0.3575761 * g__) + (0.1804375 * b__);\ + *(Y) = (0.2126729 * r__) + (0.7151522 * g__) + (0.0721750 * b__);\ + *(Z) = (0.0193339 * r__) + (0.1191920 * g__) + (0.9503041 * b__);\ + } while (0) + +/** + * Convert [0, 1] sRGB to CIE xyY + * + * The macro variant requires linking with '-lclut' + * if any of `libclut_model_ciexyz_to_ciexyy`, + * `libclut_model_linear_to_ciexyz`, and + * `libclut_model_standard_to_linear` are undefined. + * The macro variant requires linking with '-lm' if + * neither `libclut_model_standard_to_linear` nor + * `libclut_model_standard_to_linear1` are undefined. + * + * @param r The red component + * @param g The green component + * @param b The blue component + * @param x Output parameter for the x parameter + * @param y Output parameter for the y parameter + * @param Y Output parameter for the Y parameter + */ +void (libclut_model_srgb_to_ciexyy)(double, double, double, double *, double *, double *); +#define libclut_model_srgb_to_ciexyy(r, g, b, x, y, Y)\ + do {\ + double r___ = (r), g___ = (g), b___ = (b);\ + double *x___ = (x), *y___ = (y), *Y___ = (Y);\ + double X___, Z___;\ + libclut_model_standard_to_linear(&r___, &g___, &b___);\ + libclut_model_linear_to_ciexyz(r___, g___, b___, &X___, Y___, &Z___);\ + libclut_model_ciexyz_to_ciexyy(X___, *Y___, Z___, x___, y___);\ + } while (0) + +/** + * Convert CIE xyY to [0, 1] sRGB + * + * The macro variant requires linking with '-lclut' + * if any of `libclut_model_ciexyy_to_ciexyz`, + * `libclut_model_ciexyz_to_linear`, and + * `libclut_model_linear_to_standard` are undefined. + * The macro variant requires linking with '-lm' if + * neither `libclut_model_linear_to_standard` nor + * `libclut_model_linear_to_standard1` are undefined. + * + * @param x The x parameter + * @param y The y parameter + * @param Y The Y parameter + * @param r Output parameter for the red component + * @param g Output parameter for the green component + * @param b Output parameter for the blue component + */ +void (libclut_model_ciexyy_to_srgb)(double, double, double, double *, double *, double *); +#define libclut_model_ciexyy_to_srgb(x, y, Y, r, g, b)\ + do {\ + double x___ = (x), y___ = (y), Y___ = (Y);\ + double *r___ = (r), *g___ = (g), *b___ = (b);\ + double X___, Z___;\ + libclut_model_ciexyy_to_ciexyz(x___, y___, Y___, &X___, &Z___);\ + libclut_model_ciexyz_to_linear(X___, Y___, Z___, r___, g___, b___);\ + libclut_model_linear_to_standard(r___, g___, b___);\ + } while(0) + +/** + * Convert from CIE XYZ to CIE L*a*b* + * + * The macro variant requires linking with '-lm' + * + * @param X The X parameter + * @param Y The Y parameter + * @param Z The Z parameter + * @param L Output parameter for the L* component + * @param a Output parameter for the a* component + * @param b Output parameter for the b* component + */ +LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) +void (libclut_model_ciexyz_to_cielab)(double, double, double, double *, double *, double *); +#define libclut_model_ciexyz_to_cielab(X, Y, Z, L, a, b)\ + do {\ + double X__ = (X), Y__ = (Y), Z__ = (Z);\ + X__ /= 0.95047, Z__ /= 1.08883;\ + X__ = LIBCLUT_MODEL_CIEXYZ_TO_CIELAB__(X__);\ + Y__ = LIBCLUT_MODEL_CIEXYZ_TO_CIELAB__(Y__);\ + Z__ = LIBCLUT_MODEL_CIEXYZ_TO_CIELAB__(Z__);\ + *(L) = 116 * Y__ - 16;\ + *(a) = 500 * (X__ - Y__);\ + *(b) = 200 * (Y__ - Z__);\ + } while (0) +#define LIBCLUT_MODEL_CIEXYZ_TO_CIELAB__(C)\ + (((C) > 0.00885642) ? pow((C), 1.0 / 3) : ((7.78 + 703.0 / 99900) * (C) + 0.1379310)) + +/** + * Convert from CIE L*a*b* to CIE XYZ + * + * @param L The L* component + * @param a The a* component + * @param b The b* component + * @param X Output parameter for the X parameter + * @param Y Output parameter for the Y parameter + * @param Z Output parameter for the Z parameter + */ +LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) +void (libclut_model_cielab_to_ciexyz)(double, double, double, double *, double *, double *); +#define libclut_model_cielab_to_ciexyz(L, a, b, X, Y, Z)\ + do {\ + double L__ = (L), a__ = (a), b__ = (b);\ + double *X__ = (X), *Y__ = (Y), *Z__ = (Z);\ + *Y__ = (L__ + 16) / 116;\ + *X__ = a__ / 500 + *Y__;\ + *Z__ = *Y__ - b__ / 200;\ + *X__ = LIBCLUT_MODEL_CIELAB_TO_CIEXYZ__(*X__) * 0.95047;\ + *Y__ = LIBCLUT_MODEL_CIELAB_TO_CIEXYZ__(*Y__) * 1.08883;\ + *Z__ = LIBCLUT_MODEL_CIELAB_TO_CIEXYZ__(*Z__);\ + } while (0) +#define LIBCLUT_MODEL_CIELAB_TO_CIEXYZ__(C)\ + (((C)*(C)*(C) > 0.00885642) ? ((C)*(C)*(C)) : (((C) - 0.1379310) / (7.78 + 703.0 / 99900))) + +/** + * Convert from CIE XYZ to CIELUV + * + * Requires linking with `-lm` + * + * @param X The X component + * @param Y The Y component + * @param Z The Z component + * @param Xn The X component of the specified white object (white point) + * @param Yn The Y component of the specified white object (white point) + * @param Zn The Z component of the specified white object (white point) + * @param L Output parameter for the L* parameter + * @param u Output parameter for the u* parameter + * @param v Output parameter for the v* parameter + */ +LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) +void (libclut_model_ciexyz_to_cieluv)(double, double, double, double, double, double, double *, double *, double *); +#define libclut_model_ciexyz_to_cieluv(X, Y, Z, Xn, Yn, Zn, L, u, v)\ + do {\ + double xn__ = (Xn), yn__ = (Yn);\ + double t__ = xn__ + 15 * yn__ + 3 * (Zn);\ + double u__ = 4 * xn__ / t__;\ + double v__ = 9 * yn__ / t__;\ + double x__ = (X), y__ = (Y);\ + t__ = x__ + 15 * y__ + 3 * (Z);\ + u__ = 4 * x__ / t__ - u__;\ + v__ = 9 * y__ / t__ - v__;\ + y__ /= yn__;\ + if (y__ * 24389 <= (double)216)\ + y__ *= 24389, y__ /= 27;\ + else\ + y__ = cbrt(y__) * 116 - 16;\ + *(L) = y__;\ + y__ *= 13;\ + *(u) = y__ * u__;\ + *(v) = y__ * v__;\ + } while (0) + +/** + * Convert from CIELUV to CIE XYZ + * + * @param L The L* component + * @param u The u* component + * @param v The v* component + * @param Xn The X component of the specified white object (white point) + * @param Yn The Y component of the specified white object (white point) + * @param Zn The Z component of the specified white object (white point) + * @param X Output parameter for the X parameter + * @param Y Output parameter for the Y parameter + * @param Z Output parameter for the Z parameter + */ +LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) +void (libclut_model_cieluv_to_ciexyz)(double, double, double, double, double, double, double *, double *, double *); +#define libclut_model_cieluv_to_ciexyz(L, u, v, Xn, Yn, Zn, X, Y, Z)\ + do {\ + double x__ = (Xn), y__ = (Yn), l__ = (L), l13__ = l__ * 13;\ + double t__ = x__ + 15 * y__ + 3 * (Zn);\ + double u__ = 4 * x__ / t__;\ + double v__ = 9 * y__ / t__;\ + u__ = (u) / l13__ + u__;\ + v__ = (v) / l13__ + v__;\ + if (l__ <= (double)8) {\ + y__ *= l__ * 27 / 24389;\ + } else {\ + l__ += 16, l__ /= 116;\ + y__ *= l__ *= l__ * l__;\ + }\ + *(Y) = y__;\ + *(X) = y__ * 9 * u__ / (4 * v__);\ + *(Z) = y__ * (12 - 3 * u__ - 20 * v__) / (4 * v__);\ + } while (0) + +/** + * Convert from CIELCh to CIE L*u*v* + * + * Requires linking with `-lm` + * + * @param C The C*_uv component + * @param h The h_uv component + * @param u Output parameter for the u* parameter + * @param v Output parameter for the v* parameter + */ +LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) +void (libclut_model_cielch_to_cieluv)(double, double, double *, double *); +#define libclut_model_cielch_to_cieluv(C, h, u, v)\ + do {\ + double h__ = (h), C__ = (C);\ + *(v) = sin(h__) * C__;\ + *(u) = cos(h__) * C__;\ + } while (0) + +/** + * Convert from CIE L*u*v* to CIELCh + * + * Requires linking with `-lm` + * + * @param u The u* component + * @param v The v* component + * @param C Output parameter for the C*_uv parameter + * @param h Output parameter for the h_uv parameter + */ +LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) +void (libclut_model_cieluv_to_cielch)(double, double, double *, double *); +#define libclut_model_cieluv_to_cielch(u, v, C, h)\ + do {\ + double u__ = (u), v__ = (v);\ + *(C) = sqrt(u__ * u__ + v__ * v__);\ + *(h) = atan2(v__, u__); \ + } while (0) + +/** + * Convert from sRGB to YIQ + * + * Requires linking with '-lclut', or '-lm' if + * `libclut_model_standard_to_linear1` is not undefined + * + * @param r The R component + * @param g The G component + * @param b The B component + * @param y Output parameter for the Y parameter + * @param i Output parameter for the I parameter + * @param q Output parameter for the Q parameter + */ +void (libclut_model_srgb_to_yiq)(double, double, double, double *, double *, double *); +#define libclut_model_srgb_to_yiq(r, g, b, y, i, q)\ + do {\ + double r__ = libclut_model_standard_to_linear1(r) / 100000000000000000ULL;\ + double g__ = libclut_model_standard_to_linear1(g) / 10000000000000000ULL;\ + double b__ = libclut_model_standard_to_linear1(b) / 100000000000000000ULL;\ + *(y) = r__ * 29893602129377540ULL + g__ * 5870430744511212ULL + b__ * 11402090425510336ULL;\ + *(i) = r__ * 59594574307079930ULL - g__ * 2743886357457892ULL - b__ * 32155710732501010ULL;\ + *(q) = r__ * 21149734030682846ULL - g__ * 5229106903029739ULL + b__ * 31141334999614540ULL;\ + } while (0) + +/** + * Convert from YIQ to sRGB + * + * Requires linking with '-lclut', or '-lm' if + * `libclut_model_linear_to_standard1` is not undefined + * + * @param y The Y component + * @param i The I component + * @param q The Q component + * @param r Output parameter for the R parameter + * @param g Output parameter for the G parameter + * @param b Output parameter for the B parameter + */ +void (libclut_model_yiq_to_srgb)(double, double, double, double *, double *, double *); +#define libclut_model_yiq_to_srgb(y, i, q, r, g, b)\ + do {\ + double y__ = (y), i__ = (i), q__ = (q), r__, g__, b__;\ + r__ = y__ + i__ * 956 / 1000 + q__ * 621 / 1000;\ + g__ = y__ - i__ * 272 / 1000 - q__ * 647 / 1000;\ + b__ = y__ - i__ * 1106 / 1000 + q__ * 1703 / 1000;\ + *(r) = libclut_model_linear_to_standard1(r__);\ + *(g) = libclut_model_linear_to_standard1(g__);\ + *(b) = libclut_model_linear_to_standard1(b__);\ + } while (0) + +/** + * Convert from sRGB to YDbDr + * + * Requires linking with '-lclut', or '-lm' if + * `libclut_model_standard_to_linear1` is not undefined + * + * @param r The R component + * @param g The G component + * @param b The B component + * @param y Output parameter for the Y parameter + * @param db Output parameter for the Db parameter + * @param dr Output parameter for the Dr parameter + */ +void (libclut_model_srgb_to_ydbdr)(double, double, double, double *, double *, double *); +#define libclut_model_srgb_to_ydbdr(r, g, b, y, db, dr)\ + do {\ + double r__ = libclut_model_standard_to_linear1(r);\ + double g__ = libclut_model_standard_to_linear1(g);\ + double b__ = libclut_model_standard_to_linear1(b);\ + *(y) = r__ * 299 / 1000 + g__ * 587 / 1000 + b__ * 114 / 1000;\ + *(db) = -r__ * 450 / 1000 - g__ * 883 / 1000 + b__ * 1333 / 1000;\ + *(dr) = -r__ * 1333 / 1000 + g__ * 1116 / 1000 + b__ * 217 / 1000;\ + } while (0) + +/** + * Convert from YDbDr to sRGB + * + * Requires linking with '-lclut', or '-lm' if + * `libclut_model_linear_to_standard1` is not undefined + * + * @param y The Y component + * @param db The Db component + * @param dr The Dr component + * @param r Output parameter for the R parameter + * @param g Output parameter for the G parameter + * @param b Output parameter for the B parameter + */ +void (libclut_model_ydbdr_to_srgb)(double, double, double, double *, double *, double *); +#define libclut_model_ydbdr_to_srgb(y, db, dr, r, g, b)\ + do {\ + double y__ = (y), db__ = (db), dr__ = (dr), r__, g__, b__;\ + db__ /= 1000000000000000ULL;\ + dr__ /= 1000000000000000ULL;\ + r__ = y__ + db__ * 92303716148ULL - dr__ * 525912630661865ULL;\ + g__ = y__ - db__ * 129132898890509ULL + dr__ * 267899328207599ULL;\ + b__ = y__ + db__ * 664679059978955ULL - dr__ * 79202543533ULL;\ + *(r) = libclut_model_linear_to_standard1(r__);\ + *(g) = libclut_model_linear_to_standard1(g__);\ + *(b) = libclut_model_linear_to_standard1(b__);\ + } while (0) + +/** + * Convert from YUV to YDbDr + * + * @param u The U component + * @param v The V component + * @param db Output parameter for the Db parameter + * @param dr Output parameter for the Dr parameter + */ +LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) +void (libclut_model_yuv_to_ydbdr)(double, double, double *, double *); +#define libclut_model_yuv_to_ydbdr(u, v, db, dr)\ + do {\ + *(db) = 3069 * (u) / 1000;\ + *(dr) = -2169 * (v) / 1000;\ + } while (0) + +/** + * Convert from YDbDr to YUV + * + * @param db The Db component + * @param dr The Dr component + * @param u Output parameter for the U parameter + * @param v Output parameter for the V parameter + */ +LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) +void (libclut_model_ydbdr_to_yuv)(double, double, double *, double *); +#define libclut_model_ydbdr_to_yuv(db, dr, u, v)\ + do {\ + *(u) = (db) * 1000 / 3069;\ + *(v) = (dr) * 1000 / -2169;\ + } while (0) + +/** + * Convert from sRGB to YPbPr + * + * Requires linking with '-lclut', or '-lm' if + * `libclut_model_standard_to_linear1` is not undefined + * + * @param r The R component + * @param g The G component + * @param b The B component + * @param y Output parameter for the Y parameter + * @param pb Output parameter for the Pb parameter + * @param pr Output parameter for the Pr parameter + */ +void (libclut_model_srgb_to_ypbpr)(double, double, double, double *, double *, double *); +#define libclut_model_srgb_to_ypbpr(r, g, b, y, pb, pr)\ + do {\ + double r__ = libclut_model_standard_to_linear1(r);\ + double g__ = libclut_model_standard_to_linear1(g);\ + double b__ = libclut_model_standard_to_linear1(b);\ + double y__;\ + y__ = r__ * 2126 / 10000;\ + y__ += g__ * 7152 / 10000;\ + y__ += b__ * 722 / 10000;\ + *(y) = y__;\ + *(pb) = b__ - y__;\ + *(pr) = r__ - y__;\ + } while (0) + +/** + * Convert from YPbPr to sRGB + * + * Requires linking with '-lclut', or '-lm' if + * `libclut_model_linear_to_standard1` is not undefined + * + * @param y The Y component + * @param pb The Pb component + * @param pr The Pr component + * @param r Output parameter for the R parameter + * @param g Output parameter for the G parameter + * @param b Output parameter for the B parameter + */ +void (libclut_model_ypbpr_to_srgb)(double, double, double, double *, double *, double *); +#define libclut_model_ypbpr_to_srgb(y, pb, pr, r, g, b)\ + do {\ + double y__ = (y), r__ = (pr) + y__, g__, b__ = (pb) + y__;\ + y__ -= r__ * 2126 / 10000;\ + y__ -= b__ * 722 / 10000;\ + g__ = y__ * 10000 / 7152;\ + *(r) = libclut_model_linear_to_standard1(r__);\ + *(g) = libclut_model_linear_to_standard1(g__);\ + *(b) = libclut_model_linear_to_standard1(b__);\ + } while (0) + +/** + * Convert from sRGB to YCgCo + * + * Requires linking with '-lclut', or '-lm' if + * `libclut_model_standard_to_linear1` is not undefined + * + * @param r The R component + * @param g The G component + * @param b The B component + * @param y Output parameter for the Y parameter + * @param cg Output parameter for the Cg parameter + * @param co Output parameter for the Co parameter + */ +void (libclut_model_srgb_to_ycgco)(double, double, double, double *, double *, double *); +#define libclut_model_srgb_to_ycgco(r, g, b, y, cg, co)\ + do {\ + double r__ = libclut_model_standard_to_linear1(r);\ + double g__ = libclut_model_standard_to_linear1(g);\ + double b__ = libclut_model_standard_to_linear1(b);\ + *(y) = r__ / 4 + g__ / 2 + b__ / 4;\ + *(cg) = r__ / -4 + g__ / 2 - b__ / 4;\ + *(co) = r__ / 2 - b__ / 2;\ + } while (0) + +/** + * Convert from YCgCo to sRGB + * + * Requires linking with '-lclut', or '-lm' if + * `libclut_model_linear_to_standard1` is not undefined + * + * @param y The Y component + * @param cg The Cg component + * @param co The Co component + * @param r Output parameter for the R parameter + * @param g Output parameter for the G parameter + * @param b Output parameter for the B parameter + */ +void (libclut_model_ycgco_to_srgb)(double, double, double, double *, double *, double *); +#define libclut_model_ycgco_to_srgb(y, cg, co, r, g, b)\ + do {\ + double y__ = (y), cg__ = (cg), co__ = (co);\ + double r__ = y__ - cg__ + co__;\ + double g__ = y__ + cg__;\ + double b__ = y__ - cg__ - co__;\ + *(r) = libclut_model_linear_to_standard1(r__);\ + *(g) = libclut_model_linear_to_standard1(g__);\ + *(b) = libclut_model_linear_to_standard1(b__);\ + } while (0) + +/** + * Convert from CIE 1960 UCS to CIE XYZ + * + * @param u The u component + * @param v The v component + * @param Y The Y component + * @param x Output parameter for the X parameter + * @param y Output parameter for the Y parameter + * @param z Output parameter for the Z parameter + */ +LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) +void (libclut_model_cie_1960_ucs_to_ciexyz)(double, double, double, double *, double *, double *); +#define libclut_model_cie_1960_ucs_to_ciexyz(u, v, Y, x, y, z)\ + do {\ + double u__ = (u), v__ = (v), y__ = (Y);\ + *(y) = y__;\ + *(x) = 3 * y__ * u__ / (2 * v__);\ + *(z) = (4 * y__ - y__ * u__ - 10 * y__ * v__) / (2 * v__);\ + } while (0) + +/** + * Convert from CIE XYZ to CIE 1960 UCS + * + * @param x The X component + * @param y The Y component + * @param z The Z component + * @param u Output parameter for the u parameter + * @param v Output parameter for the v parameter + * @param Y Output parameter for the Y parameter + */ +LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) +void (libclut_model_ciexyz_to_cie_1960_ucs)(double, double, double, double *, double *, double *); +#define libclut_model_ciexyz_to_cie_1960_ucs(x, y, z, u, v, Y)\ + do {\ + double x__ = (x), y__ = (y);\ + double d__ = x__ + 15 * y__ + 3 * (z);\ + *(u) = 4 * x__ / d__;\ + *(v) = 6 * y__ / d__;\ + *(Y) = y__;\ + } while (0) + +/** + * Convert from CIEUVW to CIE 1960 UCS + * + * @param U:double The U* component + * @param V:double The V* component + * @param W:double The W* component + * @param u0:double The u parameter for the white point + * @param v0:double The v parameter for the white point + * @param u:double* Output parameter for the u parameter + * @param v:double* Output parameter for the v parameter + * @param Y:double* Output parameter for the Y parameter + */ +LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) +void (libclut_model_cieuvw_to_cie_1960_ucs)(double, double, double, double, double, double *, double *, double *); +#define libclut_model_cieuvw_to_cie_1960_ucs(U, V, W, u0, v0, u, v, Y)\ + do {\ + double w__ = (W), y__ = (w__ + 17) / 25;\ + *(Y) = y__ *= y__ * y__;\ + w__ *= 13;\ + *(u) = (U) / w__ + (u0);\ + *(v) = (V) / w__ + (v0);\ + } while (0) + +/** + * Convert from CIE 1960 UCS to CIEUVW + * + * Requires linking with `-lm` + * + * @param u:double The u component + * @param v:double The v component + * @param Y:double The Y component + * @param u0:double The u parameter for the white point + * @param v0:double The v parameter for the white point + * @param U:double* Output parameter for the U* parameter + * @param V:double* Output parameter for the V* parameter + * @param W:double* Output parameter for the W* parameter + */ +void (libclut_model_cie_1960_ucs_to_cieuvw)(double, double, double, double, double, double *, double *, double *); +#define libclut_model_cie_1960_ucs_to_cieuvw(u, v, Y, u0, v0, U, V, W)\ + do {\ + double w__ = 25 * cbrt(Y) - 17;\ + *(W) = w__;\ + w__ *= 13;\ + *(U) = w__ * ((u) - (u0));\ + *(V) = w__ * ((v) - (v0));\ + } while (0) + +/** + * Create a matrix for converting values between + * two RGB colour spaces + * + * @param from The input colour space, the Y-component is only necessary + * for the white point, `NULL` for CIE XYZ + * @param to The output colour space, the Y-component is only necessary + * for the white point, `NULL` for CIE XYZ + * @param M Output matrix for conversion from `from` to `to` + * @param Minv Output matrix for conversion from `to` to `from`, may be `NULL` + * @return Zero on success, -1 on error + * + * @throws EINVAL The colour space cannot be used + */ +int libclut_model_get_rgb_conversion_matrix(const libclut_rgb_colour_space_t *, const libclut_rgb_colour_space_t *, + libclut_colour_space_conversion_matrix_t, libclut_colour_space_conversion_matrix_t); + +/** + * Convert an RGB colour into another RGB colour space + * + * Both RGB colour spaces must have same gamma functions as sRGB + * + * Requires linking with '-lclut', or '-lm' if + * `libclut_model_standard_to_linear1` or + * `libclut_model_linear_to_standard1` is not undefined + * + * @param r The red component of the colour to convert + * @param g The green component of the colour to convert + * @param b The blue component of the colour to convert + * @param M Conversion matrix, create with `libclut_model_get_rgb_conversion_matrix`, + * must not have side-effects + * @param out_r Output parameter for the new red component + * @param out_g Output parameter for the new green component + * @param out_b Output parameter for the new blue component + */ +void (libclut_model_convert_rgb)(double, double, double, libclut_colour_space_conversion_matrix_t, double *, double *, double *); +#define libclut_model_convert_rgb(r, g, b, M, out_r, out_g, out_b)\ + do {\ + double r__ = libclut_model_standard_to_linear1(r);\ + double g__ = libclut_model_standard_to_linear1(g);\ + double b__ = libclut_model_standard_to_linear1(b);\ + *(out_r) = libclut_model_linear_to_standard1((M)[0][0] * r__ + (M)[0][1] * g__ + (M)[0][2] * b__);\ + *(out_g) = libclut_model_linear_to_standard1((M)[1][0] * r__ + (M)[1][1] * g__ + (M)[1][2] * b__);\ + *(out_b) = libclut_model_linear_to_standard1((M)[2][0] * r__ + (M)[2][1] * g__ + (M)[2][2] * b__);\ + } while (0) + +/** + * Convert an RGB colour of a custom RGB colour space to CIE XYZ + * + * The RGB colour space must have same gamma functions as sRGB + * + * Requires linking with '-lclut', or '-lm' if + * `libclut_model_standard_to_linear1` is not undefined + * + * @param r The red component + * @param g The green component + * @param b The blue component + * @param M Conversion matrix, create with `libclut_model_get_rgb_conversion_matrix`, + * must not have side-effects + * @param x Output parameter for the X component + * @param y Output parameter for the Y component + * @param z Output parameter for the Z component + */ +void (libclut_model_rgb_to_ciexyz)(double, double, double, libclut_colour_space_conversion_matrix_t, double *, double *, double *); +#define libclut_model_rgb_to_ciexyz(r, g, b, M, x, y, z)\ + do {\ + double r__ = libclut_model_standard_to_linear1(r);\ + double g__ = libclut_model_standard_to_linear1(g);\ + double b__ = libclut_model_standard_to_linear1(b);\ + *(x) = (M)[0][0] * r__ + (M)[0][1] * g__ + (M)[0][2] * b__;\ + *(y) = (M)[1][0] * r__ + (M)[1][1] * g__ + (M)[1][2] * b__;\ + *(z) = (M)[2][0] * r__ + (M)[2][1] * g__ + (M)[2][2] * b__;\ + } while (0) + +/** + * Convert a CIE XYZ colour to a custom RGB colour space + * + * The RGB colour space must have same gamma functions as sRGB + * + * Requires linking with '-lclut', or '-lm' if + * `libclut_model_linear_to_standard1` is not undefined + * + * @param x The X component + * @param y The Y component + * @param z The Z component + * @param M Conversion matrix, create with `libclut_model_get_rgb_conversion_matrix`, + * must not have side-effects. + * @param r Output parameter for the red component + * @param g Output parameter for the green component + * @param b Output parameter for the blue component + */ +void (libclut_model_ciexyz_to_rgb)(double, double, double, libclut_colour_space_conversion_matrix_t, double *, double *, double *); +#define libclut_model_ciexyz_to_rgb(x, y, z, M, r, g, b)\ + do {\ + double x__ = (x), y__ = (y), z__ = (z);\ + *(r) = libclut_model_linear_to_standard1((M)[0][0] * x__ + (M)[0][1] * y__ + (M)[0][2] * z__);\ + *(g) = libclut_model_linear_to_standard1((M)[1][0] * x__ + (M)[1][1] * y__ + (M)[1][2] * z__);\ + *(b) = libclut_model_linear_to_standard1((M)[2][0] * x__ + (M)[2][1] * y__ + (M)[2][2] * z__);\ + } while (0) + +#if defined(__clang__) +# pragma GCC diagnostic pop +#endif + +#endif diff --git a/mk/README b/mk/README deleted file mode 100644 index e79926d..0000000 --- a/mk/README +++ /dev/null @@ -1,71 +0,0 @@ -This is a collection of generic enough makefiles. -Please feel free to use them in your project. - -Usage: - Include all.mk from your makefile. - - Read the top of each file for details. - - Define the variables: - - _VERSION - This version of the package. - - _PROJECT - The name of the project. Must only include [a-z0-9_-]. - - _PROJECT_FULL - The name of the project. May include any character. - - _SRC - All source code files. This list is used when - generating the translation template file. - - _COPYRIGHT_HOLDER - The copyright holder's full name and e-mail address. - - COMMAND - The name of the command. Must not be declared if - the package does not include exactly one runnable - command. - - PKGNAME - The name of the package. - - Variables beginning with __ are used internally by - the files where they appear, or in rare cases, - internally between these files. - - Variables beginning with _ but not __ are set in the - makefile to specify for these files how they should - behave. They should not be changed by a user of the - package. - - Variables that do not begin with _ are configurable - by the user of the package. - - Do no use single character variables in your Makefile. - - To suppress pre-install, post-install, pre-uninstall, - and post-uninstall instructions, set N=true. - PRE_INSTALL, POST_INSTALL, PRE_UNINSTALL, and - POST_UNINSTALL are supportered as specified by the - GNU coding standardars. - - To figure out what pre-install commands to run in your package, run: - make -n a=% install | sed -e 's/\\$//' -e 's/^ *//' | sed -n '/^% /s/^..//p' - - To figure out what post-install commands to run in your package, run: - make -n z=% uninstall | sed -e 's/\\$//' -e 's/^ *//' | sed -n '/^% /s/^..//p' - - To figure out what pre-uninstall commands to run in your package, run: - make -n a=% uninstall | sed -e 's/\\$//' -e 's/^ *//' | sed -n '/^% /s/^..//p' - - To figure out what post-uninstall commands to run in your package, run: - make -n z=% uninstall | sed -e 's/\\$//' -e 's/^ *//' | sed -n '/^% /s/^..//p' - - To suppress verbatim which commands Make runs, - set Q=@. (Excluding the period.) - -Developers should use DEBUG=1 when running make, when possible. - diff --git a/mk/all.mk b/mk/all.mk deleted file mode 100644 index 032718d..0000000 --- a/mk/all.mk +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright (C) 2015, 2016 Mattias Andrée <maandree@member.fsf.org> -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without any warranty. - - -#=== This file includes all the other files in appropriate order. ===# - - -ifndef Q -A = \e[35m -Z = [m[D -endif - -include $(v)mk/path.mk -include .config.mk -include $(v)mk/path.mk -include $(v)mk/lowerpath.mk -include $(v)mk/empty.mk -include $(v)mk/tools.mk -include $(v)mk/copy.mk -include $(v)mk/lang-c.mk -include $(v)mk/texinfo.mk -include $(v)mk/man.mk -include $(v)mk/i18n.mk -include $(v)mk/clean.mk -include $(v)mk/dist.mk -include $(v)mk/tags.mk -include $(v)mk/prologue.mk - diff --git a/mk/clean.mk b/mk/clean.mk deleted file mode 100644 index 1ae4fdc..0000000 --- a/mk/clean.mk +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright (C) 2015, 2016 Mattias Andrée <maandree@member.fsf.org> -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without any warranty. - - -#=== These rules are used for cleaning the repository of generated files. ===# - - -# Delete all files are normally created during a build. -.PHONY: clean -clean: clean-dist - @$(PRINTF_INFO) '\e[00;01;31mCLEANING BUILT FILES\e[34m\e[00m\n' - -$(Q)$(RM) -r -- bin aux *.su src/*.su src/*/*.su src/*/*/*.su src/*/*/*/*.su - @$(ECHO) - -# Delete all files that are created during configuration or building. -.PHONY: distclean -distclean: clean - @$(PRINTF_INFO) '\e[00;01;31mCLEANING CONFIGURATIONS\e[34m\e[00m\n' - -$(Q)$(RM) -- .config.mk config.status Makefile - @$(ECHO) - -# Like `make clean` but do not remove massive binaries -# that are seldom recompiled. -.PHONY: mostlyclean -mostlyclean: clean - -# Delete everything except ./configure -.PHONY: maintainer-clean -maintainer-clean: clean distclean - @$(ECHO) - @$(ECHO) 'This command is intended for maintainers to use; it' - @$(ECHO) 'deletes files that may need special tools to rebuild.' - @$(ECHO) - -# Delete all files generated by `make dist` -.PHONY: clean-dist -clean-dist: - @$(PRINTF_INFO) '\e[00;01;31mCLEANING RELEASES\e[34m\e[00m\n' - -$(Q)$(RM) -r -- $(_PROJECT)-*.tar* $(_PROJECT)-*.checksums* $(_PROJECT)-* - @$(ECHO) - diff --git a/mk/configure b/mk/configure deleted file mode 100644 index 4b6e61a..0000000 --- a/mk/configure +++ /dev/null @@ -1,732 +0,0 @@ -# -*- shell-script -*- - -# Copyright (C) 2015, 2016 Mattias Andrée <maandree@member.fsf.org> -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without any warranty. - - -# Run './configure --help' for usage information. - - -# FOR DEVELOPERS USING THIS SCRIPT: -# This file is used by include this file, via the . builtin, -# in your ./configure. Before doing so, you must declare -# PKGNAME=the_name_of_your_package -# MAN_SECTION_SUFFIX=default_suffix_to_append_to_man_page_section # (usually empty) -# MAN_SECTION=the_section_your_man_page_is_in # (do no declare if you do not use exacly one section) -# Define the function list_optional_features_help, see the help output. -# Define the function unrecognised_argument to deal with any unrecognised argument. - - - -# Store command for rebuilding Makefile to config.status. -exec 10>config.status - -# Store configurations to .config.mk. -exec 20>.config.mk - - -# Print a quoted (if necessary) version of a string -quote () -{ - value="$1" - if ! test "${value%%\'*}" = "${value}"; then - value="'$(echo "${value}" | sed "s/'/'\\\\''/g")'" - elif ! test "$(printf '%s' ${value})" = "${value}"; then - value="'${value}'" - elif ! test "$(echo ${value}) | tr -d a-zA-Z0-9+_@%/=-" = ""; then - value="'${value}'" - fi - echo "${value}" -} - - -# Parse command line. -incomplete= -dashed= -f_help= -f_gnulinux= -f_bin_merger= -for option; do - if test -n "${incomplete}"; then - option="${incomplete}=${option}" - incomplete= - fi - - # For --{with{,out},{en,dis}able}-*. - feature="${option#--*}" - feature="${feature#*-}" - feature="$(echo "${feature}" | tr a-z- A-Z_)" - - # For directories and filename tweaks. - nodash=_novar - - case "${dashed}${option}" in -# general - (--) - dashed=yes ;; - (--help) - f_help=yes ;; - (--destdir | --destdir=* | --pkgdir | --pkgdir=*) - nodash=destdir ;; - (--srcdir | --srcdir) - nodash=srcdir ;; - -# directory automation - (--gnu-linux) - f_gnulinux=yes ;; - (--bin-merger) - f_bin_merger=yes ;; - -# directories and filenames - (--prefix | --prefix=*) - nodash=prefix ;; - (--exec-prefix | --exec-prefix=* | --exec_prefix | --exec_prefix=*) - nodash=exec_prefix ;; - (--bindir | --bindir=*) - nodash=bindir ;; - (--sbindir | --sbindir=*) - nodash=sbindir ;; - (--libexecdir | --libexecdir=*) - nodash=libexecdir ;; - (--libdir | --libdir=*) - nodash=libdir ;; - (--includedir | --includedir=*) - nodash=includedir ;; - (--oldincludedir | --oldincludedir=*) - nodash=oldincludedir ;; - (--datarootdir | --datarootdir=*) - nodash=datarootdir ;; - (--datadir | --datadir=*) - nodash=datadir ;; - (--libdatarootdir | --libdatarootdir=*) - nodash=libdatarootdir ;; - (--libdatadir | --libdatadir=*) - nodash=libdatadir ;; - (--sysconfdir | --sysconfdir=*) - nodash=sysconfdir ;; - (--sharedstatedir | --=sharedstatedir*) - nodash=sharedstatedir ;; - (--localstatedir | --localstatedir=*) - nodash=localstatedir ;; - (--runstatedir | --runstatedir=*) - nodash=runstatedir ;; - (--lispdir | --lispdir=*) - nodash=lispdir ;; - (--localedir | --localedir=*) - nodash=localedir ;; - (--licensedir | --licensedir=*) - nodash=licensedir ;; - (--emptydir | --emptydir=*) - nodash=emptydir ;; - (--cachedir | --cachedir=*) - nodash=cachedir ;; - (--spooldir | --spooldir=*) - nodash=spooldir ;; - (--logdir | --logdir=*) - nodash=logdir ;; - (--statedir | --statedir=*) - nodash=statedir ;; - (--gamedir | --gamedir=*) - nodash=gamedir ;; - (--sharedcachedir | --sharedcachedir=*) - nodash=sharedcachedir ;; - (--sharedspooldir | --sharedspooldir=*) - nodash=sharedspooldir ;; - (--sharedlogdir | --sharedlogdir=*) - nodash=sharedlogdir ;; - (--sharedstatedir | --sharedstatedir=*) - nodash=sharedstatedir ;; - (--sharedgamedir | --sharedgamedir=*) - nodash=sharedgamedir ;; - (--tmpdir | --tmpdir=*) - nodash=tmpdir ;; - (--localtmpdir | --localtmpdir=*) - nodash=localtmpdir ;; - (--sharedtmpdir | --sharedtmpdir=*) - nodash=sharedtmpdir ;; - (--lockdir | --lockdir=*) - nodash=lockdir ;; - (--skeldir | --skeldir=*) - nodash=skeldir ;; - (--devdir | --devdir=*) - nodash=devdir ;; - (--sysdir | --sysdir=*) - nodash=sysdir ;; - (--procdir | --procdir=*) - nodash=procdir ;; - (--selfprocdir | --selfprocdir=*) - nodash=selfprocdir ;; - (--docdir | --docdir=*) - nodash=docdir ;; - (--infodir | --infodir=*) - nodash=infodir ;; - (--dvidir | --dvidir=*) - nodash=dvidir ;; - (--pdfdir | --pdfdir=*) - nodash=pdfdir ;; - (--psdir | --psdir=*) - nodash=psdir ;; - (--htmldir | --htmldir=*) - nodash=htmldir ;; - (--mandir | --mandir=*) - nodash=mandir ;; - (--man0 | --man0=*) - nodash=man0 ;; - (--man1 | --man1=*) - nodash=man1 ;; - (--man2 | --man2=*) - nodash=man2 ;; - (--man3 | --man3=*) - nodash=man3 ;; - (--man4 | --man4=*) - nodash=man4 ;; - (--man5 | --man5=*) - nodash=man5 ;; - (--man6 | --man6=*) - nodash=man6 ;; - (--man7 | --man7=*) - nodash=man7 ;; - (--man8 | --man8=*) - nodash=man8 ;; - (--man9 | --man9=*) - nodash=man9 ;; - (--man0ext | --man0ext=*) - nodash=man0ext ;; - (--man1ext | --man1ext=*) - nodash=man1ext ;; - (--man2ext | --man2ext=*) - nodash=man2ext ;; - (--man3ext | --man3ext=*) - nodash=man3ext ;; - (--man4ext | --man4ext=*) - nodash=man4ext ;; - (--man5ext | --man5ext=*) - nodash=man5ext ;; - (--man6ext | --man6ext=*) - nodash=man6ext ;; - (--man7ext | --man7ext=*) - nodash=man7ext ;; - (--man8ext | --man8ext=*) - nodash=man8ext ;; - (--man9ext | --man9ext=*) - nodash=man9ext ;; - (--manext | --manext=*) - if test -n "${MAN_SECTION}"; then - nodash=manext - else - printf "\e[01;31m%s: warning: ignoring: %s\e[00m\n" "${0}" "${option}" >&2 - sleep 1 - fi - ;; - -# ignored - # Unrecognised directories, and settings that cannot be used with internationalisation. - (--*dir=* | --*dir | --man?dir | --man?dir=*) - printf "\e[01;31m%s: warning: ignoring: %s\e[00m\n" "${0}" "${option}" >&2 - sleep 1 - ;; - -# feature tweaking - (--with-*) - feature="WITH_${feature}" - echo "${feature}" = yes >&20 - export "${feature}"=yes - option="${option}=x" - ;; - - (--without-*) - feature="WITHOUT_${feature}" - echo "${feature}" = yes >&20 - export "${feature}"=yes - option="${option}=x" - ;; - - (--enable-*=*) - param="${feature#*=}" - feature="${feature%%=*}" - if ! test "${param}" = "no"; then - feature="ENABLE_${feature}" - else - feature="DISABLE_${feature}" - param=yes - fi - echo "${feature}" = "${param}" >&20 - export "${feature}"="${param}" - ;; - - (--enable-*) - feature="DISABLE_${feature}" - echo "${feature}" = yes >&20 - export "${feature}"=yes - option="${option}=x" - ;; - - (--disable-*) - feature="DISABLE_${feature}" - echo "${feature}" = yes >&20 - export "${feature}"=yes - option="${option}=x" - ;; - -# unrecognised - (${dashed}--*) - unrecognised_argument "${option}" - ;; - -# variables - (${dashed}*=*) - var="${option%%=*}" - val="${option#*=}" - if test -n "$(echo "${var}" | tr -d '[_a-zA-Z0-9-]')"; then - # Variable is not used and is potentially not - # formatted in a compatible way. - printf "\e[01;31m%s: warning: ignoring because of bad format: %s\e[00m\n" "${0}" "${option}" >&2 - sleep 1 - fi - echo "${var}" = "${val}" >&20 - ;; - -# unrecognised - (*) - unrecognised_argument "${option}" - ;; - esac - - if test "${option%%=*}" = "${option}"; then - incomplete="${option}" - else - eval "${nodash}=$(quote "${option#*=}")" - eval "have_${nodash}=yes" - fi -done - - -# Print usage information. This is parsed by -# the auto-completion script for ./configure. -if test -n "${f_help}"; then - cat <<EOF -Configure the package (${PKGNAME}) before building and installing. - -OPTIONS - -general - --help Print usage information. - --destdir=DIR Output directory for staged install. - --srcdir=DIR The directory for the sources being compiled. - VARIABLE=VALUE Override a variable in the Makefile. - -directory automation - --gnu-linux Use default configurations for GNU/Linux. - --bin-merger The OS distribution has symlinked sbin to bin for the select exec-prefix. - -tweaking of features -EOF - list_optional_features_help - cat <<EOF - -tweaking of directories and filenames - --prefix=DIR Prefix used for other directories than. - --exec-prefix=DIR Prefix used for /bin, /sbin, /libexec, and /lib. - --bindir=DIR Executable programs that users can run. - --sbindir=DIR Executable administrative programs. - --libexecdir=DIR Executable programs run by other programs and not be users. - --libdir=DIR Object files and libraries of object code. - --includedir=DIR Header files. - --oldincludedir=DIR Header files. Should have the prefix /usr if the canonical prefix is /usr/local. - --datarootdir=DIR Architecture-independent data files. - --datadir=DIR Architecture-independent resource files. - --libdatarootdir=DIR Architecture-dependent data files. - --libdatadir=DIR Architecture-dependent resource files. - --sysconfdir=DIR Machine-local configuration files. - --sharedstatedir=DIR Network-shared architecture-independent state files. - --localstatedir=DIR Machine-local architecture-independent state files. - --runstatedir=DIR Machine-local runtime state files. - --lispdir=DIR Emacs LISP files. - --localedir=DIR Locale-specific message catalogues. - --licensedir=DIR License files. - --emptydir=DIR An always empty directory. - --cachedir=DIR Machine-local cached files. - --spooldir=DIR Machine-local spooled files. - --logdir=DIR Machine-local log files - --statedir=DIR Machine-local persistent state files - --gamedir=DIR Machine-local highscore files. - --sharedcachedir=DIR Network-shared cached files. - --sharedspooldir=DIR Network-shared spooled files. - --sharedlogdir=DIR Network-shared log files - --sharedstatedir=DIR Network-shared persistent state files - --sharedgamedir=DIR Network-shared highscore files. - --tmpdir=DIR Machine-local volatile temporary files. - --localtmpdir=DIR Machine-local persistent temporary files. - --sharedtmpdir=DIR Network-shared temporary files. - --lockdir=DIR Lock files. - --skeldir=DIR User skeleton. - --devdir=DIR Devices and pseudo-devices. - --sysdir=DIR System-information logical file. - --procdir=DIR Process-information logical file. - --selfprocdir=DIR Process-information logical file for the process itself. - --docdir=DIR Documentation files, other then info manuals and man pages. - --infodir=DIR Info manuals. - --dvidir=DIR DVI manuals. - --pdfdir=DIR PDF manuals. - --psdir=DIR PostScript manuals. - --htmldir=DIR HTML manuals. - --mandir=DIR Top-level directory for man pages. - --man0=DIR Basename of the directory for section 0 man pages. - --man1=DIR Basename of the directory for section 1 man pages. - --man2=DIR Basename of the directory for section 2 man pages. - --man3=DIR Basename of the directory for section 3 man pages. - --man4=DIR Basename of the directory for section 4 man pages. - --man5=DIR Basename of the directory for section 5 man pages. - --man6=DIR Basename of the directory for section 6 man pages. - --man7=DIR Basename of the directory for section 7 man pages. - --man8=DIR Basename of the directory for section 8 man pages. - --man9=DIR Basename of the directory for section 9 man pages. -EOF - if test -n "${MAN_SECTION}"; then - cat <<EOF - --manext=EXT Filename suffix for the man page. -EOF - fi - cat <<EOF - --man0ext=EXT Filename suffix for section 0 man pages. - --man1ext=EXT Filename suffix for section 1 man pages. - --man2ext=EXT Filename suffix for section 2 man pages. - --man3ext=EXT Filename suffix for section 3 man pages. - --man4ext=EXT Filename suffix for section 4 man pages. - --man5ext=EXT Filename suffix for section 5 man pages. - --man6ext=EXT Filename suffix for section 6 man pages. - --man7ext=EXT Filename suffix for section 7 man pages. - --man8ext=EXT Filename suffix for section 8 man pages. - --man9ext=EXT Filename suffix for section 9 man pages. -EOF - exit 0 -fi - - -# Set unset directories to their default. -defdir () -{ - p="$(quote "${2}")" - if ! test -n "$(eval echo '${have_'"${1}"'}')"; then - eval "${1}=${p}" - fi -} -if test -n "${f_gnulinux}"; then - defdir prefix "/usr" - _prefix= - case ${prefix} in - ('' | / | /usr | /usr/ | /games | /games | /usr/games | /usr/games/) - _infix= - ;; - (/usr/local | /usr/local/ | /usr/local/games | /usr/local/games/) - _infix=/local - ;; - (/opt/*) - _infix=${prefix} - ;; - (*) - # This probably means somewhere in /home, we do not - # checked because we do not know what else to do. - _infix= - _prefix="${prefix}" - ;; - esac - defdir sysconfdir "${_prefix}/etc${_infix}" - defdir sharedstatedir "${_prefix}/com${_infix}" - defdir localstatedir "${_prefix}/var${_infix}" - defdir runstatedir "${_prefix}/run${_infix}" - defdir tmpdir "${_prefix}/tmp${_infix}" -else - defdir prefix "/usr/local" - defdir sysconfdir "${prefix}/etc" - defdir sharedstatedir "${prefix}/com" - defdir localstatedir "${prefix}/var" - defdir runstatedir "${localstatedir}/run" - defdir tmpdir "${prefix}/tmp" -fi -defdir exec_prefix "${prefix}" -defdir bindir "${exec_prefix}/bin" -if test -n "${f_bin_merger}"; then - defdir sbindir "${bindir}" -else - defdir sbindir "${exec_prefix}/sbin" -fi -defdir libexecdir "${exec_prefix}/libexec" -defdir libdir "${exec_prefix}/lib" -defdir includedir "${prefix}/include" -defdir oldincludedir "${includedir}" -defdir datarootdir "${prefix}/share" -defdir datadir "${datarootdir}" -defdir libdatarootdir "${libdir}" -defdir libdatadir "${libdir}" -defdir lispdir "${datarootdir}/emacs/site-lisp" -defdir localedir "${datarootdir}/locale" -defdir licensedir "${datarootdir}/licenses" -defdir cachedir "${localstatedir}/cache" -defdir spooldir "${localstatedir}/spool" -defdir emptydir "${localstatedir}/empty" -defdir logdir "${localstatedir}/log" -defdir statedir "${localstatedir}/lib" -defdir gamedir "${localstatedir}/games" -defdir sharedcachedir "${sharedstatedir}/cache" -defdir sharedpooldir "${sharedstatedir}/spool" -defdir sharedlogdir "${sharedstatedir}/log" -defdir sharedstatedir "${sharedstatedir}/lib" -defdir sharedgamedir "${sharedstatedir}/games" -defdir localtmpdir "${localstatedir}/tmp" -defdir sharedtmpdir "${sharedstatedir}/tmp" -defdir lockdir "${runstatedir}/lock" -defdir skeldir "${sysconfdir}/skel" -defdir devdir "/dev" -defdir sysdir "/sys" -defdir procdir "/proc" -defdir selfprocdir "${procdir}/self" -defdir docdir "${datarootdir}/doc/${PKGNAME}" -defdir infodir "${datarootdir}/info" -defdir dvidir "${docdir}" -defdir pdfdir "${docdir}" -defdir psdir "${docdir}" -defdir htmldir "${docdir}" -defdir mandir "${datarootdir}/man" -defdir man0 "man0${MAN_SECTION_SUFFIX}" -defdir man1 "man1${MAN_SECTION_SUFFIX}" -defdir man2 "man2${MAN_SECTION_SUFFIX}" -defdir man3 "man3${MAN_SECTION_SUFFIX}" -defdir man4 "man4${MAN_SECTION_SUFFIX}" -defdir man5 "man5${MAN_SECTION_SUFFIX}" -defdir man6 "man6${MAN_SECTION_SUFFIX}" -defdir man7 "man7${MAN_SECTION_SUFFIX}" -defdir man8 "man8${MAN_SECTION_SUFFIX}" -defdir man9 "man9${MAN_SECTION_SUFFIX}" -if test -n "${MAN_SECTION}" && ! test -n "$(eval echo '${man'"${MAN_SECTION}"'ext}')"; then - defdir "man${MAN_SECTION}ext" "$(eval echo '${man'"${MAN_SECTION}"'ext}')" -fi -defdir man0ext ".0" -defdir man1ext ".1" -defdir man2ext ".2" -defdir man3ext ".3" -defdir man4ext ".4" -defdir man5ext ".5" -defdir man6ext ".6" -defdir man7ext ".7" -defdir man8ext ".8" -defdir man9ext ".9" - -# Found source directory. -if ! test -n "${srcdir}"; then - if test -f "Makefile.in"; then - : - elif test -f "${PWD}/Makefile.in"; then - srcdir="${PWD}" - elif test -f "${PWD}/../Makefile.in"; then - srcdir="${PWD}/.." - fi -fi -if test -n "${srcdir}"; then - srcdir="$(realpath "${srcdir}")/" - srcdir_proper="${srcdir}" - srcdir="$(quote "${srcdir}")" -fi -if ! test -f "${srcdir_proper}Makefile.in"; then - echo "${0}: error: cannot found source directory." - exit 1 -fi - - -# Add shebang and "generated"-comment to config.status. -echo '#!/bin/sh' >&10 -echo >&10 -echo '# This file was generated by ./configure, its purpose is two-fold:' >&10 -echo '# 1) It lets you rebuild Makefile with the same configurations you' >&10 -echo '# used last time you run ./configure.' >&10 -echo '# 2) It lets Makefile rebuild itself transparently when out of date.' >&10 -echo >&10 - -# config.status should adjust CWD. -echo 'cd "$(dirname "${0}")"' >&10 - -# config.status calls ./configure with all arguments you called ./configure. -printf "exec %s" "${0}" >&10 -for option; do - printf " %s" "$(quote "${option}")" >&10 -done -echo >&10 - -# Close config.status. -exec 10>&- - - -# Store environment (with restrictions). -env | while read line; do - var="${line%%=*}" - val="${line#*=}" - if test "${var}" = "${line}"; then - # Malformated variables. (Can happen!, sigh...) - continue - elif test -n "$(echo "${var}" | tr -d '[_a-zA-Z0-9-]')"; then - # Variable is not used and is potentially not - # formatted in a compatible way. - continue - fi - case "${var}" in - (_ | PWD | SHELL | SHLVL | TERM | COLORTERM | MAKEFLAGS) - # We do not want to propagate these. - ;; - (*) - echo "${var}" = "${val}" >&20 - ;; - esac -done - -# Store directories and filenames. -if test -n "${destdir}"; then - echo DESTDIR = "${destdir}" >&20 -fi -echo PREFIX = "${prefix}" >&20 -echo SYSCONFDIR = "${sysconfdir}" >&20 -echo COMDIR = "${sharedstatedir}" >&20 -echo VARDIR = "${localstatedir}" >&20 -echo RUNDIR = "${runstatedir}" >&20 -echo TMPDIR = "${tmpdir}" >&20 -echo DEVDIR = "${devdir}" >&20 -echo SYSDIR = "${sysdir}" >&20 -echo PROCDIR = "${procdir}" >&20 -echo EXEC_PREFIX = "${exec_prefix}" >&20 -echo BINDIR = "${bindir}" >&20 -echo SBINDIR = "${sbindir}" >&20 -echo LIBEXECDIR = "${libexecdir}" >&20 -echo LIBDIR = "${libdir}" >&20 -echo INCLUDEDIR = "${includedir}" >&20 -echo OLDINCLUDEDIR = "${oldincludedir}" >&20 -echo DATADIR = "${datarootdir}" >&20 -echo RESDIR = "${datadir}" >&20 -echo SYSDEPDATADIR = "${libdatarootdir}" >&20 -echo SYSDEPRESDIR = "${libdatadir}" >&20 -echo LISPDIR = "${lispdir}" >&20 -echo LOCALEDIR = "${localedir}" >&20 -echo LICENSEDIR = "${licensedir}" >&20 -echo CACHEDIR = "${cachedir}" >&20 -echo SPOOLDIR = "${spooldir}" >&20 -echo EMPTYDIR = "${emptydir}" >&20 -echo LOGDIR = "${logdir}" >&20 -echo STATEDIR = "${statedir}" >&20 -echo GAMEDIR = "${gamedir}" >&20 -echo COMCACHEDIR = "${sharedcachedir}" >&20 -echo COMPOOLDIR = "${sharedpooldir}" >&20 -echo COMLOGDIR = "${sharedlogdir}" >&20 -echo COMSTATEDIR = "${sharedstatedir}" >&20 -echo COMGAMEDIR = "${sharedgamedir}" >&20 -echo LOCALTMPDIR = "${localtmpdir}" >&20 -echo SHAREDTMPDIR = "${sharedtmpdir}" >&20 -echo LOCKDIR = "${lockdir}" >&20 -echo SKELDIR = "${skeldir}" >&20 -echo SELFPROCDIR = "${selfprocdir}" >&20 -echo DOCDIR = "${docdir}" >&20 -echo INFODIR = "${infodir}" >&20 -echo DVIDIR = "${dvidir}" >&20 -echo PDFDIR = "${pdfdir}" >&20 -echo PSDIR = "${psdir}" >&20 -echo HTMLDIR = "${htmldir}" >&20 -echo MANDIR = "${mandir}" >&20 -echo MAN0 = "${man0}" >&20 -echo MAN1 = "${man1}" >&20 -echo MAN2 = "${man2}" >&20 -echo MAN3 = "${man3}" >&20 -echo MAN4 = "${man4}" >&20 -echo MAN5 = "${man5}" >&20 -echo MAN6 = "${man6}" >&20 -echo MAN7 = "${man7}" >&20 -echo MAN8 = "${man8}" >&20 -echo MAN9 = "${man9}" >&20 -echo MAN0EXT = "${man0ext}" >&20 -echo MAN1EXT = "${man1ext}" >&20 -echo MAN2EXT = "${man2ext}" >&20 -echo MAN3EXT = "${man3ext}" >&20 -echo MAN4EXT = "${man4ext}" >&20 -echo MAN5EXT = "${man5ext}" >&20 -echo MAN6EXT = "${man6ext}" >&20 -echo MAN7EXT = "${man7ext}" >&20 -echo MAN8EXT = "${man8ext}" >&20 -echo MAN9EXT = "${man9ext}" >&20 - -# Close .config.mk. -exec 20>&- - -# Now, make Makefile available. -if test -f Makefile; then - chmod u+w Makefile # This scripts makes it read-only. -fi -exec 30>Makefile -echo "# ----------------------------------------------------- #" >&30 -echo "# This file was created by ./configure from Makefile.in #" >&30 -echo "# ----------------------------------------------------- #" >&30 -echo >&30 -if test -n "${srcdir}"; then - echo v = "${srcdir}" >&30 -fi -cat "${srcdir_proper}"Makefile.in >&30 -exec 30>&- - - -# config.status should be executable. -chmod a+x config.status - -# Makefile should be read-only to ones does not edit it by mistake. -chmod a-w Makefile - - -# Help functions for the parent script. -test_with () -{ - with="$(eval echo '${WITH_'"${1}"'}')" - without="$(eval echo '${WITHOUT_'"${1}"'}')" - if ! test -n "${with}" && ! test -n "${without}"; then - echo "${2}" - elif ! test -n "${with}" && test -n "${without}"; then - echo "no" - elif test -n "${with}" && ! test -n "${without}"; then - echo "yes" - elif test "${2}" = yes; then - echo "no" - else - echo "yes" - fi -} -test_enable () -{ - enable="$(eval echo '${ENABLE_'"${1}"'}')" - disable="$(eval echo '${DISABLE_'"${1}"'}')" - if ! test -n "${enable}" && ! test -n "${disable}"; then - echo "${2}" - elif ! test -n "${enable}" && test -n "${disable}"; then - echo "no" - elif test -n "${enable}" && ! test -n "${disable}"; then - echo "${enable}" - elif test "${2}" = yes ; then - echo "no" - else - echo "${enable}" - fi -} - - -# After including this file, you may want -# to do something like: -# -# cat <<EOF -# -# Enabled features, see ${0} for more infomation: -# -# Internationalisation $(test_with GETTEXT yes) -# GNU Bash tab-completion $(test_with BASH yes) -# Fish tab-completion $(test_with FISH yes) -# Z shell tab-completion $(test_with ZSH yes) -# -# You can now run 'make && make install'. -# -# EOF - diff --git a/mk/copy.mk b/mk/copy.mk deleted file mode 100644 index c9067a4..0000000 --- a/mk/copy.mk +++ /dev/null @@ -1,78 +0,0 @@ -# Copyright (C) 2015, 2016 Mattias Andrée <maandree@member.fsf.org> -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without any warranty. - - -#=== These rules are used for legal files. ===# - - -# Enables the rules: -# install-copyright Install all files in _COPYING and _LICENSE -# install-copying Install all files in _COPYING -# install-license Install all files in _LICENSE - - -# WHEN TO BUILD, INSTALL, AND UNINSTALL: - -install-base: install-copyright -uninstall: uninstall-copyright - - -# INSTALL RULES: - -.PHONY: install-copyright -install-copyright: - -ifdef _COPYING -.PHONY: install-copyright -install-copyright: install-copying - -.PHONY: install-copying -install-copying: $(foreach F,$(_COPYING),$(v)$(F)) - @$(PRINTF_INFO) '\e[00;01;31mINSTALL\e[34m %s\e[00m\n' "$@" - $(Q)$(INSTALL_DIR) -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)" - $(Q)$(INSTALL_DATA) $^ -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)" - @$(ECHO_EMPTY) -endif - -ifdef _LICENSE -.PHONY: install-copyright -install-copyright: install-license - -.PHONY: install-license -install-license: $(foreach F,$(_LICENSE),$(v)$(F)) - @$(PRINTF_INFO) '\e[00;01;31mINSTALL\e[34m %s\e[00m\n' "$@" - $(Q)$(INSTALL_DIR) -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)" - $(Q)$(INSTALL_DATA) $^ -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)" - @$(ECHO_EMPTY) -endif - - -# UNINSTALL RULES: - -.PHONY: uninstall-copyright -uninstall-copyright: - -ifdef _COPYING -.PHONY: uninstall-copyright -uninstall-copyright: uninstall-copying - -.PHONY: uninstall-copying -uninstall-copying: - -$(Q)$(RM) -- $(foreach F,$(_COPYING),"$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)/$(F)") - -$(Q)$(RMDIR) -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)" -endif - -ifdef _LICENSE -.PHONY: uninstall-copyright -uninstall-copyright: uninstall-license - -.PHONY: uninstall-license -uninstall-license: - -$(Q)$(RM) -- $(foreach F,$(_LICENSE),"$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)/$(F)") - -$(Q)$(RMDIR) -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)" -endif - diff --git a/mk/dist.mk b/mk/dist.mk deleted file mode 100644 index 9f8c48b..0000000 --- a/mk/dist.mk +++ /dev/null @@ -1,189 +0,0 @@ -# Copyright (C) 2015, 2016 Mattias Andrée <maandree@member.fsf.org> -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without any warranty. - - -#=== These rules are used for making releases. ===# - - -# CONFIGURATIONS: - -# Formats for packages to generate. -DIST_FORMATS = tar tar.xz tar.bz2 tar.gz - -# Define DO_NOT_SIGN if you do not want sign the release. - -# You can select checksums to generate: -# Declaring NO_BSD_SUM will omit `sum -r`. -# Declaring NO_SYSV_SUM will omit `sum -s`. -# List all checksum programs, that do not require any flags, in DIST_CHECKSUMS. - -# Any missing flags for GnuPG? -GPG_FLAGS = - -# What key should be used for signing? -GPG_KEY ?= - -# You should define _EVERYTHING to enumerate all files that belong in -# the release tarball, lest 'git archive' will be used as a fallback. - - - -# HELP VARIALES: - -# You may use these to help list all files in _EVERYTHING -__EVERYTHING_COMMON = $(_COPYING) $(_LICENSE) README -__EVERYTHING_SRC = $(foreach F,$(_SRC),src/$(F)) -__EVERYTHING_LOCALE = $(foreach L,$(LOCALES),po/$(L).po) -__EVERYTHING_SHELL = $(foreach F,$(_AUTO_COMPLETE),src/$(F).auto-completion) \ - $(foreach F,$(_AUTO_COMPLETE),$(foreac F,$(_SHELL_LOCALES),src/$(F).$(L),auto-completion)) -__EVERYTHING_MK_ = all clean copy dist empty i18n lang-c lowerpath man path prologue shell tags texinfo tools -__EVERYTHING_MK = $(foreach F,$(__EVERYTHING_MK_),mk/$(F).mk) mk/configure mk/README configure Makefile.in -__EVERYTHING_MAN = $(foreach S,$(_MAN_PAGE_SECTIONS),$(foreach P,$(_MAN_$(S)),doc/man/$(P).$(S))) \ - $(foreach S,$(_MAN_PAGE_SECTIONS),$(foreach L,$(MAN_LOCALES),$(foreach P,$(_MAN_$(L)_$(S)),doc/man/$(P).$(L).$(S)))) -__EVERYTHING_ALL_COMMON = $(__EVERYTHING_COMMON) $(__EVERYTHING_MK) $(__EVERYTHING_MAN) \ - $(__EVERYTHING_LOCALE) $(__EVERYTHING_SRC) $(__EVERYTHING_SHELL) -# This one (__todo) if you have a todo file, but do not want it to be greped. -__TO__ = TO -__DO__ = DO -__todo = $(__TO__)$(__DO__) - - -# The packages and there detached signatures (if any.) -ifndef DO_NOT_SIGN -__DIST_FILES = $(foreach F,$(DIST_FORMATS),$(_PROJECT)-$(_VERSION).$(F) $(_PROJECT)-$(_VERSION).$(F).sig) -endif -ifdef DO_NOT_SIGN -__DIST_FILES = $(foreach F,$(DIST_FORMATS),$(_PROJECT)-$(_VERSION).$(F)) -endif - -# All known checksum programs that are unambiguous. -__DIST_CHECKSUMS_ALL = cksum md2sum md4sum md5sum md6sum sha0sum sha1sum sha224sum \ - sha256sum sha384sum sha512sum sha512-224sum sha512-256sum \ - sha3-224sum sha3-256sum sha3-384sum sha3-512sum shake256sum \ - shake512sum rawshake256sum rawshake512sum keccak-224sum \ - keccak-256sum keccak-384sum keccak-512sum keccaksum - -# All installed checksum programs that are unambiguous. -DIST_CHECKSUMS = $(foreach C,$(__DIST_CHECKSUMS_ALL),$(shell if command -v $(C) >/dev/null; then $(ECHO) $(C); fi)) - - - -# MAKE RULES: - -# Generate release files. (Tarballs, compressed and uncompressed; signatures; checksums.) -.PHONY: dist -dist: dist-balls dist-checksums - - - -# HELP MAKE RULES: - -# Generate tarballs, compressed and uncompressed, -.PHONY: dist-balls -dist-balls: $(__DIST_FILES) - -ifndef DO_NOT_SIGN -# Generate checksums and signature of checksums. -.PHONY: dist-checksums -dist-checksums: $(_PROJECT)-$(_VERSION).checksums $(_PROJECT)-$(_VERSION).checksums.sig - -# Generate uncompressed tarball and signature of it. -.PHONY: dist-tar -dist-tar: $(_PROJECT)-$(_VERSION).tar $(_PROJECT)-$(_VERSION).tar.sig - -# Generate xz-copressed tarball and signature of it. -.PHONY: dist-xz -dist-xz: $(_PROJECT)-$(_VERSION).tar.xz $(_PROJECT)-$(_VERSION).tar.xz.sig - -# Generate bz2-copressed tarball and signature of it. -.PHONY: dist-bzip2 -dist-bz2: $(_PROJECT)-$(_VERSION).tar.bz2 $(_PROJECT)-$(_VERSION).tar.bz2.sig - -# Generate gzip-copressed tarball and signature of it. -.PHONY: dist-gz -dist-gz: $(_PROJECT)-$(_VERSION).tar.gz $(_PROJECT)-$(_VERSION).tar.sig -endif -ifdef DO_NOT_SIGN -# Generate checksums, but no signature. -.PHONY: dist-checksums -dist-checksums: $(_PROJECT)-$(_VERSION).checksums - -# Generate uncompressed tarball, but no signature. -.PHONY: dist-tar -dist-tar: $(_PROJECT)-$(_VERSION).tar - -# Generate xz-compressed tarball, but no signature. -.PHONY: dist-xz -dist-xz: $(_PROJECT)-$(_VERSION).tar.xz - -# Generate bzip2-compressed tarball, but no signature. -.PHONY: dist-bz2 -dist-bz2: $(_PROJECT)-$(_VERSION).tar.bz2 - -# Generate gzip-compressed tarball, but no signature. -.PHONY: dist-gz -dist-gz: $(_PROJECT)-$(_VERSION).tar.gz -endif - -# Generate the tarball for the release. -ifdef v -__GIT_DIR = --git-dir=$(v) -endif -$(_PROJECT)-$(_VERSION).tar: $(foreach F,$(_EVERYTHING),$(v)$(F)) - @$(PRINTF_INFO) '\e[00;01;31mTAR\e[34m %s\e[00m$A\n' "$@" - @if $(TEST) -f $@; then $(RM) $@; fi -ifndef _EVERYTHING - $(Q)git archive --prefix=$(_PROJECT)-$(_VERSION)/ --format=tar $(__GIT_DIR) $(_VERSION) -o $@ #$Z -endif -ifdef _EVERYTHING - $(Q)$(LN) -s . $(_PROJECT)-$(_VERSION) - $(Q)$(TAR) c -- $(foreach F,$(_EVERYTHING),$(v)$(_PROJECT)-$(_VERSION)/$(F)) > $@ - $(Q)$(RM) $(_PROJECT)-$(_VERSION) -endif - @$(ECHO_EMPTY) - -# Compression rule for xz-compression. Used on the tarball. -%.xz: % - @$(PRINTF_INFO) '\e[00;01;31mXZ\e[34m %s\e[00m$A\n' "$@" - @if $(TEST) -f $@; then $(RM) $@; fi - $(Q)$(XZ_COMPRESS) $< #$Z - @$(ECHO_EMPTY) - -# Compression rule for bzip2-compression. Used on the tarball. -%.bz2: % - @$(PRINTF_INFO) '\e[00;01;31mBZIP2\e[34m %s\e[00m$A\n' "$@" - @if $(TEST) -f $@; then $(RM) $@; fi - $(Q)$(BZIP2_COMPRESS) $< #$Z - @$(ECHO_EMPTY) - -# Compression rule for gzip-compression. Used on the tarball. -%.gz: % - @$(PRINTF_INFO) '\e[00;01;31mGZIP\e[34m %s\e[00m$A\n' "$@" - @if $(TEST) -f $@; then $(RM) $@; fi - $(Q)$(GZIP_COMPRESS) $< #$Z - @$(ECHO_EMPTY) - -# Generate checksums of tarballs, compressed and uncompressed, and of their detached signatures. -$(_PROJECT)-$(_VERSION).checksums: $(__DIST_FILES) - @$(PRINTF_INFO) '\e[00;01;31mCHECKSUM\e[34m %s\e[00m\n' "$@" - @$(PRINTF) '' > $@ -ifndef NO_BSD_SUM - @if ! ($(ECHO) ':: sum -r ::' && sum -r $^ && $(ECHO)) >> $@ ; then $(PRINTF) '' > $@; fi -endif -ifndef NO_SYSV_SUM - @if ! ($(ECHO) ':: sum -s ::' && sum -s $^ && $(ECHO)) >> $@ ; then $(PRINTF) '' > $@; fi -endif - @$(foreach C,$(DIST_CHECKSUMS),$(ECHO) ':: $(C) ::' >> $@ && $(C) $^ | $(GREP) -v '^--' >> $@ && $(ECHO) >> $@ &&) $(TRUE) - @$(ECHO_EMPTY) - -# Signing rule. Used on the tarballs, compressed and uncompressed, and on the checksum file. -%.sig: % - @$(PRINTF_INFO) '\e[00;01;31mSIG\e[34m %s\e[00m$A\n' "$@" - @if $(TEST) -f $@; then $(RM) $@; fi - $(Q)$(GPG) $(GPG_FLAGS) --local-user $(GPG_KEY) --detach-sign --armor --output $@ < $< #$Z - @$(ECHO_EMPTY) - diff --git a/mk/empty.mk b/mk/empty.mk deleted file mode 100644 index fd684f6..0000000 --- a/mk/empty.mk +++ /dev/null @@ -1,103 +0,0 @@ -# Copyright (C) 2015, 2016 Mattias Andrée <maandree@member.fsf.org> -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without any warranty. - - -#=== This file includes empty rules that are filled by other files. ===# - - -.PHONY: all -all: - -.PHONY: everything -everything: - -.PHONY: base -base: - -.PHONY: cmd -cmd: - -.PHONY: lib -lib: - -.PHONY: doc -doc: - - -.PHONY: check -check: - - -.PHONY: install -install: - -.PHONY: install-everything -install-everything: - -.PHONY: install-base -install-base: - -.PHONY: install-cmd -install-cmd: - -.PHONY: install-lib -install-lib: - -.PHONY: install-doc -install-doc: - - -.PHONY: installcheck -installcheck: - - -.PHONY: uninstall -uninstall: - - - -.PHONY: all -all: base - -.PHONY: everything -everything: base - -.PHONY: base -base: cmd lib - - -.PHONY: install -install: install-base - -.PHONY: install-everything -install-everything: install-base - -.PHONY: install-base -install-base: install-cmd install-lib - - - -.PHONY: install-strip -install-strip: __STRIP = -s -install-strip: install - -.PHONY: install-everything-strip -install-everything-strip: __STRIP = -s -install-everything-strip: install-everything - -.PHONY: install-base-strip -install-base-strip: __STRIP = -s -install-base-strip: install-base - -.PHONY: install-cmd-strip -install-cmd-strip: __STRIP = -s -install-cmd-strip: install-cmd - -.PHONY: install-lib-strip -install-lib-strip: __STRIP = -s -install-lib-strip: install-lib - diff --git a/mk/i18n.mk b/mk/i18n.mk deleted file mode 100644 index ed6ec79..0000000 --- a/mk/i18n.mk +++ /dev/null @@ -1,111 +0,0 @@ -# Copyright (C) 2015, 2016 Mattias Andrée <maandree@member.fsf.org> -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without any warranty. - - -#=== These rules are used for internationalisation. ===# - - -# Enables the rules: -# locale Build all translations. -# update-po Update all .po files for further translation. -# install-locale Install all locales. -# -# "All locales" are those listed in LOCALES. -# If LOCALES is not defined, this file is ignored. -# -# If WITHOUT_GETTEXT is defined, `locale` and -# `install-locale` will not do anything. -# -# _SRC should list all sources files, excluding the src/ -# at the beginning of the pathnames. - - -ifdef LOCALES - - -# WHEN TO BUILD, INSTALL, AND UNINSTALL: - -all: locale -everything: locale -install: install-locale -install-everything: install-locale -uninstall: uninstall-locale - - -# BUILD RULES: - -# Build all translations. -ifdef WITHOUT_GETTEXT -.PHONY: locale -locale: -endif -ifndef WITHOUT_GETTEXT -.PHONY: locale -locale: $(foreach L,$(LOCALES),bin/mo/$(L)/messages.mo) -endif - -# Update all translation files for further translation. -.PHONY: update-po -update-po: $(foreach L,$(LOCALES),po/$(L).po) - -# Generate template for translations. -aux/$(_PROJECT).pot: $(foreach S,$(_SRC),$(v)src/$(S)) - @$(PRINTF_INFO) '\e[00;01;31mPOT\e[34m %s\e[00m$A\n' "$@" - @$(MKDIR) -p aux - $(Q)$(CPP) -DUSE_GETTEXT=1 $^ | \ - $(XGETTEXT) -o "$@" -Lc --from-code utf-8 --package-name "$(_PROJECT_FULL)" \ - --package-version $(_VERSION) --no-wrap --force-po \ - --copyright-holder '$(_COPYRIGHT_HOLDER)' - #$Z - @$(ECHO_EMPTY) - -# Create or update a translation file. -po/%.po: aux/$(_PROJECT).pot - @$(PRINTF_INFO) '\e[00;01;31mPO\e[34m %s\e[00m$A\n' "$@" - @$(MKDIR) -p po - $(Q)if ! $(TEST) -e $@; then \ - $(MSGINIT) --no-translator --no-wrap -i aux/$(_PROJECT).pot -o $@ -l $*; \ - else \ - $(MSGMERGE) --no-wrap -U $@ aux/$(_PROJECT).pot; \ - fi #$Z - @$(TOUCH) $@ - @$(ECHO_EMPTY) - -# Compile a translation file. -bin/mo/%/messages.mo: $(v)po/%.po - @$(PRINTF_INFO) '\e[00;01;31mMO\e[34m %s\e[00m$A\n' "$@" - @$(MKDIR) -p bin/mo/$* - $(Q)cd bin/mo/$* && $(MSGFMT) $(__back3unless_v)$< #$Z - @$(ECHO_EMPTY) - - -# INSTALL RULES: - -# Install all locales. -ifdef WITHOUT_GETTEXT -.PHONY: install-locale -install-locale: -endif -ifndef WITHOUT_GETTEXT -.PHONY: install-locale -install-locale: $(foreach L,$(LOCALES),bin/mo/$(L)/messages.mo) - @$(PRINTF_INFO) '\e[00;01;31mINSTALL\e[34m %s\e[00m\n' "$@" - $(Q)$(INSTALL) -dm755 -- $(foreach L,$(LOCALES),"$(DESTDIR)$(LOCALEDIR)/$(L)/LC_MESSAGES") - $(Q)$(foreach L,$(LOCALES),$(INSTALL_DATA) bin/mo/$(L)/messages.mo -- "$(DESTDIR)$(LOCALEDIR)/$(L)/LC_MESSAGES/$(PKGNAME).mo" &&) $(TRUE) - @$(ECHO_EMPTY) -endif - - -# UNINSTALL RULES: - -# Uninstall all locales. -.PHONY: uninstall-locale -uninstall-locale: - -$(Q)$(RM) -- $(foreach L,$(LOCALES),"$(DESTDIR)$(LOCALEDIR)/$(L)/LC_MESSAGES/$(PKGNAME).mo") - - -endif - diff --git a/mk/lang-c.mk b/mk/lang-c.mk deleted file mode 100644 index e96c0b3..0000000 --- a/mk/lang-c.mk +++ /dev/null @@ -1,307 +0,0 @@ -# Copyright (C) 2015, 2016 Mattias Andrée <maandree@member.fsf.org> -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without any warranty. - - -#=== This file includes rules for C programs. ===# - - -# This file is ignored unless _C_STD is defined. -# _C_STD should be set the the version of C that -# is used. -# -# If you want to compile with -pedantic, define -# the variable _PEDANTIC. -# -# Define _CPPFLAGS with any additional CPP -# flags to use, _CFLAGS with any additional CC -# flags to use, and _LDFLAGS with any additional -# LD flags to use. -# -# Defined in path.mk, you can change _ALL_DIRS -# if you do not want CPP definitions for all -# directories. -# -# Define _HEADER_DIRLEVELS to specify the directory -# nesting level in src. It is assumed that all -# directories contain header files. Set to '0' if -# there are no header files. -# -# _BIN shall list all commands to build. These -# should be the basenames. For each command -# you should be the variable _OBJ_$(COMMAND) -# that lists all objects files (without the -# suffix and without the aux/ prefix) that -# are required to build the command. -# -# Binary you want installed to /sbin rather than -# /bin shall be listed in _SBIN rather than in -# _BIN. _SBIN and _BIN may not list binaries -# with identical names. Analogically, you may -# add _LIBEXEC for binary to be installed to -# /libexec. -# -# If you only have one binary, you may select -# to define _BINDIR to name the variable with -# the pathname for the directory the binary -# shall be installed. For example, if you want -# the binary to be installed to /usr/sbin, -# define _BINDIR = SBINDIR. -# -# List libraries to compile in in _LIB. For each -# library, sould should also define -# _SO_VERSION_$(LIBRARY) and _SO_MAJOR_$(LIBRARY) -# with the full version number and the major -# version number, respectively. Additionally, -# list all header files that shall be installed -# in _H, these should not contain the 'src/' prefix -# or the '.h' suffix. - - -ifdef _C_STD - - - -# HELP VARIABLES: - -# Figure out whether the GCC is being used. -ifeq ($(shell $(PRINTF) '%s\n' ${CC} | $(HEAD) -n 1),gcc) -__USING_GCC = 1 -endif - -# Are there any commands? -ifdef _BIN -__HAVE_CMD_C = 1 -endif -ifdef _SBIN -__HAVE_CMD_C = 1 -endif -ifdef _LIBEXEC -__HAVE_CMD_C = 1 -endif - - -# WHEN TO BUILD, INSTALL, AND UNINSTALL: - -ifdef __HAVE_CMD_C -cmd: cmd-c -install-cmd: install-cmd-c -uninstall: uninstall-cmd-c -endif -ifdef _LIB -lib: lib-c -install-lib: install-lib-c -uninstall: uninstall-lib-c -endif - - -# BUILD VARIABLES: - -# Optimisation settings for C code compilation. -ifndef OPTIMISE -ifndef DEBUG -OPTIMISE = -O2 -g -endif -ifdef DEBUG -ifdef __USING_GCC -OPTIMISE = -Og -g -endif -ifndef __USING_GCC -OPTIMISE = -g -endif -endif -endif - -# Warning settings for C code compilation. -ifdef _PEDANTIC -_PEDANTIC = -pedantic -endif -ifndef WARN -ifndef DEBUG -WARN = -Wall -endif -ifdef DEBUG -ifdef __USING_GCC -WARN = -Wall -Wextra $(_PEDANTIC) -Wdouble-promotion -Wformat=2 -Winit-self -Wmissing-include-dirs \ - -Wtrampolines -Wmissing-prototypes -Wmissing-declarations -Wnested-externs \ - -Wno-variadic-macros -Wsync-nand -Wunsafe-loop-optimizations -Wcast-align \ - -Wdeclaration-after-statement -Wundef -Wbad-function-cast -Wwrite-strings -Wlogical-op \ - -Wstrict-prototypes -Wold-style-definition -Wpacked -Wvector-operation-performance \ - -Wunsuffixed-float-constants -Wsuggest-attribute=const -Wsuggest-attribute=noreturn \ - -Wsuggest-attribute=format -Wnormalized=nfkc -fstrict-aliasing -fipa-pure-const -ftree-vrp \ - -fstack-usage -funsafe-loop-optimizations -Wshadow -Wredundant-decls -Winline -Wcast-qual \ - -Wsign-conversion -Wstrict-overflow=5 -Wconversion -Wsuggest-attribute=pure -Wswitch-default \ - -Wstrict-aliasing=1 -fstrict-overflow -Wfloat-equal -Wpadded -Waggregate-return \ - -Wtraditional-conversion -endif -ifndef __USING_GCC -WARN = -Wall -Wextra $(_PEDANTIC) -endif -endif -endif - -# Support for internationalisation? -ifndef WITHOUT_GETTEXT -_CPPFLAGS += -D'USE_GETTEXT=1' -endif - -# Add CPP definitions for all directories. -_CPPFLAGS += $(foreach D,$(_ALL_DIRS),-D'$(D)="$($(D))"') - -# Compilation and linking flags, and command. -ifndef CPPFLAGS -CPPFLAGS = -endif -ifndef CFLAGS -CFLAGS = $(OPTIMISE) $(WARN) -endif -ifndef LDFLAGS -LDFLAGS = $(OPTIMISE) $(WARN) -endif -__CC = $(CC) -std=$(_C_STD) -c $(_CPPFLAGS) $(_CFLAGS) -__LD = $(CC) -std=$(_C_STD) $(_LDFLAGS) -__CC_POST = $(CPPFLAGS) $(CFLAGS) $(EXTRA_CPPFLAGS) $(EXTRA_CFLAGS) -__LD_POST = $(LDFLAGS) $(EXTRA_LDFLAGS) - -# Header files. -__H = -ifdef _HEADER_DIRLEVELS -ifeq ($(_HEADER_DIRLEVELS),1) -__H += src/*.h -endif -ifneq ($(_HEADER_DIRLEVELS),1) -ifeq ($(_HEADER_DIRLEVELS),2) -__H += src/*.h -__H += src/*/*.h -endif -ifneq ($(_HEADER_DIRLEVELS),2) -ifneq ($(_HEADER_DIRLEVELS),0) -__H += $(foreach W,$(shell $(SEQ) $(_HEADER_DIRLEVELS) | while read n; do $(ECHO) $$($(SEQ) $$n)" " | $(SED) 's/[^ ]* /\/\*/g'; done | $(XARGS) $(ECHO)),src$(W).h) -endif -endif -endif -endif - -# Directory for the binary if there is only one binary. -ifndef _BINDIR -_BINDIR = BINDIR -endif - - -# BUILD RULES: - -.PHONY: cmd-c -cmd-c: $(foreach B,$(_BIN) $(_SBIN) $(_LIBEXEC),bin/$(B)) - -.PHONY: lib-c -lib-c: $(foreach B,$(_LIB),bin/$(B).so) - -# Compile a C file into an object file for a command. -aux/%.o: $(v)src/%.c $(foreach H,$(__H),$(v)$(H)) - @$(PRINTF_INFO) '\e[00;01;31mCC\e[34m %s\e[00m$A\n' "$@" - @$(MKDIR) -p $(shell $(DIRNAME) $@) - $(Q)$(__CC) -o $@ $< $(__CC_POST) #$Z - @$(ECHO_EMPTY) - -# Compile a C file into an object file for a library. -aux/%.pic.o: $(v)src/%.c $(foreach H,$(__H),$(v)$(H)) - @$(PRINTF_INFO) '\e[00;01;31mCC\e[34m %s\e[00m$A\n' "$@" - @$(MKDIR) -p $(shell $(DIRNAME) $@) - $(Q)$(__CC) -fPIC -o $@ $< $(__CC_POST) #$Z - @$(ECHO_EMPTY) - -# Link object files into a library. -# Dependencies are declared below. -bin/%.so: - @$(PRINTF_INFO) '\e[00;01;31mLD\e[34m %s\e[00;32m$A\n' "$@" - @$(MKDIR) -p bin - $(Q)$(__LD) -shared -Wl,-soname,$*.so.$(_SO_MAJOR_$*) -o $@ $^ $(__LD_POST) #$Z - @$(ECHO_EMPTY) - -# Link object files into a command. -# Dependencies are declared below. -bin/%: - @$(PRINTF_INFO) '\e[00;01;31mLD\e[34m %s\e[00;32m$A\n' "$@" - @$(MKDIR) -p bin - $(Q)$(__LD) -o $@ $^ $(__LD_POST) #$Z - @$(ECHO_EMPTY) - -# Dependencies for the rule above. -include aux/lang-c.mk -aux/lang-c.mk: Makefile - @$(MKDIR) -p aux - @$(ECHO) > aux/lang-c.mk - @$(foreach B,$(_BIN) $(_SBIN) $(_LIBEXEC),$(ECHO) bin/$(B): $(foreach O,$(_OBJ_$(B)),aux/$(O).o) >> aux/lang-c.mk &&) $(TRUE) - @$(foreach B,$(_LIB),$(ECHO) bin/$(B).so: $(foreach O,$(_OBJ_$(B)),aux/$(O).pic.o) >> aux/lang-c.mk &&) $(TRUE) - - -# INSTALL RULES: - -.PHONY: install-cmd-c -install-cmd-c: $(foreach B,$(_BIN) $(_SBIN) $(_LIBEXEC),bin/$(B)) - @$(PRINTF_INFO) '\e[00;01;31mINSTALL\e[34m %s\e[00m\n' "$@" -ifndef COMMAND -ifdef _BIN - $(Q)$(INSTALL_DIR) -- "$(DESTDIR)$(BINDIR)" - $(Q)$(INSTALL_PROGRAM) $(__STRIP) $(foreach B,$(_BIN),bin/$(B)) -- "$(DESTDIR)$(BINDIR)" -endif -ifdef _SBIN - $(Q)$(INSTALL_DIR) -- "$(DESTDIR)$(SBINDIR)" - $(Q)$(INSTALL_PROGRAM) $(__STRIP) $(foreach B,$(_SBIN),bin/$(B)) -- "$(DESTDIR)$(SBINDIR)" -endif -ifdef _LIBEXEC - $(Q)$(INSTALL_DIR) -- "$(DESTDIR)$(LIBEXECDIR)/$(PKGNAME)" - $(Q)$(INSTALL_PROGRAM) $(__STRIP) $(foreach B,$(_LIBEXEC),bin/$(B)) -- "$(DESTDIR)$(LIBEXECDIR)/$(PKGNAME)" -endif -endif -ifdef COMMAND - $(Q)$(INSTALL_DIR) -- "$(DESTDIR)$($(_BINDIR))" - $(Q)$(INSTALL_PROGRAM) $(__STRIP) $^ -- "$(DESTDIR)$($(_BINDIR))/$(COMMAND)" -endif - @$(ECHO_EMPTY) - -.PHONY: install-lib-c -install-lib-c: $(foreach B,$(_LIB),bin/$(B).so) - @$(PRINTF_INFO) '\e[00;01;31mINSTALL\e[34m %s\e[00m\n' "$@" - $(Q)$(INSTALL_DIR) -- "$(DESTDIR)$(LIBDIR)" - $(Q)$(foreach B,$(_LIB),$(LN) -sf -- "$(B).so.$(_SO_VERSION_$(B))" "$(DESTDIR)$(LIBDIR)/$(B).so.$(_SO_MAJOR_$(B))" &&) $(TRUE) - $(Q)$(foreach B,$(_LIB),$(INSTALL_PROGRAM) $(foreach B,$(_LIB),bin/$(B).so) -- "$(DESTDIR)$(LIBDIR)/$(B).so.$(_SO_VERSION_$(B))" &&) $(TRUE) - $(Q)$(foreach B,$(_LIB),$(LN) -sf -- "$(B).so.$(_SO_VERSION_$(B))" "$(DESTDIR)$(LIBDIR)/$(B).so" &&) $(TRUE) - $(Q)$(INSTALL_DIR) -- $(foreach H,$(_H),"$(DESTDIR)$(INCLUDEDIR)/$(shell $(DIRNAME) "$(H)")") - $(Q)$(foreach H,$(_H),$(INSTALL_DATA) "src/$(H).h" -- "$(DESTDIR)$(INCLUDEDIR)/$(H).h" &&) $(TRUE) - @$(ECHO_EMPTY) - - -# UNINSTALL RULES: - -.PHONY: uninstall-cmd-c -uninstall-cmd-c: -ifdef COMMAND - -$(Q)$(RM) -- "$(DESTDIR)$($(_BINDIR))/$(COMMAND)" -endif -ifndef COMMAND -ifdef _BIN - -$(Q)$(RM) -- $(foreach B,$(_BIN),"$(DESTDIR)$(BINDIR)/$(B)") -endif -ifdef _SBIN - -$(Q)$(RM) -- $(foreach B,$(_SBIN),"$(DESTDIR)$(SBINDIR)/$(B)") -endif -ifdef _LIBEXEC - -$(Q)$(RM) -- $(foreach B,$(_LIBEXEC),"$(DESTDIR)$(LIBEXECDIR)/$(PKGNAME)/$(B)") - -$(Q)$(RMDIR) -- "$(DESTDIR)$(LIBEXECDIR)/$(PKGNAME)" -endif -endif - -.PHONY: uninstall-lib-c -uninstall-lib-c: - -$(Q)$(RM) -- $(foreach B,$(_LIB),"$(DESTDIR)$(LIBDIR)/$(B).so") - -$(Q)$(RM) -- $(foreach B,$(_LIB),"$(DESTDIR)$(LIBDIR)/$(B).so.$(_SO_MAJOR_$(B))") - -$(Q)$(RM) -- $(foreach B,$(_LIB),"$(DESTDIR)$(LIBDIR)/$(B).so.$(_SO_VERSION_$(B))") - -$(Q)$(RM) -- $(foreach H,$(_H),"$(DESTDIR)$(INCLUDEDIR)/$(H).h") - -$(Q)$(foreach H,$(_H),if ! $(TEST) "$(shell $(ECHO) "$(H)" | $(CUT) -d / -f 1)" = "$(H)"; then $(RMDIR) -- "$(DESTDIR)$(INCLUDEDIR)/$(shell $(DIRNAME) "$(H)")"; fi;) - -endif - diff --git a/mk/lowerpath.mk b/mk/lowerpath.mk deleted file mode 100644 index 77b3542..0000000 --- a/mk/lowerpath.mk +++ /dev/null @@ -1,279 +0,0 @@ -# Copyright (C) 2015, 2016 Mattias Andrée <maandree@member.fsf.org> -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without any warranty. - - -#=== This file overrides values uppercase path variables with values lowercase path variables. ===# - - -ifdef srcdir -VPATH = $(srcdir) -endif - -ifdef prefix -PREFIX = $(prefix) -endif - -ifdef sysconfdir -SYSCONFDIR = $(sysconfdir) -endif - -ifdef sharedstatedir -COMDIR = $(sharedstatedir) -endif - -ifdef localstatedir -VARDIR = $(localstatedir) -endif - -ifdef runstatedir -RUNDIR = $(runstatedir) -endif - -ifdef tmpdir -TMPDIR = $(tmpdir) -endif - -ifdef devdir -DEVDIR = $(devdir) -endif - -ifdef sysdir -SYSDIR = $(sysdir) -endif - -ifdef procdir -PROCDIR = $(procdir) -endif - -ifdef exec_prefix -EXEC_PREFIX = $(exec_prefix) -endif - -ifdef bindir -BINDIR = $(bindir) -endif - -ifdef sbindir -SBINDIR = $(sbindir) -endif - -ifdef libexecdir -LIBEXECDIR = $(libexecdir) -endif - -ifdef libdir -LIBDIR = $(libdir) -endif - -ifdef includedir -INCLUDEDIR = $(includedir) -endif - -ifdef oldincludedir -OLDINCLUDEDIR = $(oldincludedir) -endif - -ifdef datarootdir -DATADIR = $(datarootdir) -endif - -ifdef datadir -RESDIR = $(datadir) -endif - -ifdef libdatarootdir -SYSDEPDATADIR = $(libdatarootdir) -endif - -ifdef libdatadir -SYSDEPRESDIR = $(libdatadir) -endif - -ifdef lispdir -LISPDIR = $(lispdir) -endif - -ifdef localedir -LOCALEDIR = $(localedir) -endif - -ifdef licensedir -LICENSEDIR = $(licensedir) -endif - -ifdef cachedir -CACHEDIR = $(cachedir) -endif - -ifdef spooldir -SPOOLDIR = $(spooldir) -endif - -ifdef emptydir -EMPTYDIR = $(emptydir) -endif - -ifdef logdir -LOGDIR = $(logdir) -endif - -ifdef statedir -STATEDIR = $(statedir) -endif - -ifdef gamedir -GAMEDIR = $(gamedir) -endif - -ifdef sharedcachedir -COMCACHEDIR = $(sharedcachedir) -endif - -ifdef sharedpooldir -COMPOOLDIR = $(sharedpooldir) -endif - -ifdef sharedlogdir -COMLOGDIR = $(sharedlogdir) -endif - -ifdef sharedlogdir -COMSTATEDIR = $(sharedstatedir) -endif - -ifdef sharedgamedir -COMGAMEDIR = $(sharedgamedir) -endif - -ifdef localtmpdir -VARTMPDIR = $(localtmpdir) -endif - -ifdef sharedtmpdir -COMTMPDIR = $(sharedtmpdir) -endif - -ifdef lockdir -LOCKDIR = $(lockdir) -endif - -ifdef skeldir -SKELDIR = $(skeldir) -endif - -ifdef selfprocdir -SELFPROCDIR = $(selfprocdir) -endif - -ifdef docdir -DOCDIR = $(docdir) -endif - -ifdef infodir -INFODIR = $(infodir) -endif - -ifdef dvidir -DVIDIR = $(dvidir) -endif - -ifdef pdfdir -PDFDIR = $(pdfdir) -endif - -ifdef psdir -PSDIR = $(psdir) -endif - -ifdef htmldir -HTMLDIR = $(htmldir) -endif - -ifdef mandir -MANDIR = $(mandir) -endif - -ifdef man0 -MAN0 = $(man0) -endif - -ifdef man1 -MAN1 = $(man1) -endif - -ifdef man2 -MAN2 = $(man2) -endif - -ifdef man3 -MAN3 = $(man3) -endif - -ifdef man4 -MAN4 = $(man4) -endif - -ifdef man5 -MAN5 = $(man5) -endif - -ifdef man6 -MAN6 = $(man6) -endif - -ifdef man7 -MAN7 = $(man7) -endif - -ifdef man8 -MAN8 = $(man8) -endif - -ifdef man9 -MAN9 = $(man9) -endif - -ifdef man0ext -MAN0EXT = $(man0ext) -endif - -ifdef man1ext -MAN1EXT = $(man1ext) -endif - -ifdef man2ext -MAN2EXT = $(man2ext) -endif - -ifdef man3ext -MAN3EXT = $(man3ext) -endif - -ifdef man4ext -MAN4EXT = $(man4ext) -endif - -ifdef man5ext -MAN5EXT = $(man5ext) -endif - -ifdef man6ext -MAN6EXT = $(man6ext) -endif - -ifdef man7ext -MAN7EXT = $(man7ext) -endif - -ifdef man8ext -MAN8EXT = $(man8ext) -endif - -ifdef man9ext -MAN9EXT = $(man9ext) -endif - diff --git a/mk/man.mk b/mk/man.mk deleted file mode 100644 index acde35e..0000000 --- a/mk/man.mk +++ /dev/null @@ -1,111 +0,0 @@ -# Copyright (C) 2015, 2016 Mattias Andrée <maandree@member.fsf.org> -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without any warranty. - - -#=== These rules are used for man pages. ===# - - -# Enables the rules: -# install-man Install all man page -# install-man-untranslated Install untranslated man page -# install-man-locale Install translated man page -# -# This file is ignored unless _MAN_PAGE_SECTIONS -# is defined. _MAN_PAGE_SECTIONS should list all -# used man page sections. For all used sections -# there should also be a variable named -# _MAN_$(SECTION) that lists the suffixless -# basename of all man pages in that section. -# -# The pathname of a man page should look -# like this: doc/man/$(DOCUMENT).$(SECTION) -# Translations looks like this: -# doc/man/$(DOCUMENT).$(LANGUAGE).$(SECTION) -# -# For each language and section, there should -# be a variable _MAN_$(LANGUAGE)_$(SECTION) -# that lists all translated documents in that -# section and for that lanuage. These should -# be suffixless basenames. The lanuage counts -# as a suffix. -# -# The translations of the man pages to -# install should be specified, by language, -# in the variable MAN_LOCALES. - - -ifdef _MAN_PAGE_SECTIONS - - -# WHEN TO BUILD, INSTALL, AND UNINSTALL: - -install: install-man -install-everything: install-man -install-doc: install-man -uninstall: uninstall-man - - -# HELP VARIABLES - -# Customisable man page filename. -ifdef COMMAND -ifeq ($(shell $(PRINTF) '%s\n' $(COMMAND) | $(WC) -l),1) -ifeq ($(shell $(PRINTF) '%s\n' $(_MAN_PAGE_SECTIONS) | $(WC) -l),1) -ifeq ($(shell $(PRINTF) '%s\n' $(_MAN_$(_MAN_PAGE_SECTIONS)) | $(WC) -l),1) -__MAN_COMMAND = $(COMMAND)$(MAN$(_MAN_PAGE_SECTIONS)EXT) -endif -endif -endif -endif - - -# INSTALL RULES: - -.PHONY: install-man -install-man: install-man-untranslated install-man-locale - -.PHONY: install-man-untranslated -install-man-untranslated: - @$(PRINTF_INFO) '\e[00;01;31mINSTALL\e[34m %s\e[00m\n' "$@" - $(Q)$(INSTALL_DIR) -- $(foreach S,$(_MAN_PAGE_SECTIONS),"$(DESTDIR)$(MANDIR)/$(MAN$(S))") -ifndef __MAN_COMMAND - $(Q)$(foreach S,$(_MAN_PAGE_SECTIONS),$(foreach P,$(_MAN_$(S)),$(INSTALL_DATA) $(v)doc/man/$(P).$(S) -- "$(DESTDIR)$(MANDIR)/$(MAN$(S))/$(P)$(MAN$(S)EXT)" &&)) $(TRUE) -endif -ifdef __MAN_COMMAND - $(Q)$(foreach S,$(_MAN_PAGE_SECTIONS),$(foreach P,$(_MAN_$(S)),$(INSTALL_DATA) $(v)doc/man/$(P).$(S) -- "$(DESTDIR)$(MANDIR)/$(MAN$(S))/$(__MAN_COMMAND)" &&)) $(TRUE) -endif - @$(ECHO_EMPTY) - -.PHONY: install-man-locale -install-man-locale: - @$(PRINTF_INFO) '\e[00;01;31mINSTALL\e[34m %s\e[00m\n' "$@" - $(Q)$(foreach L,$(MAN_LOCALES),$(INSTALL_DIR) -- $(foreach S,$(_MAN_PAGE_SECTIONS),"$(DESTDIR)$(MANDIR)/$(L)/$(MAN$(S))") &&) $(TRUE) -ifndef __MAN_COMMAND - $(Q)$(foreach L,$(MAN_LOCALES),$(foreach S,$(_MAN_PAGE_SECTIONS),$(foreach P,$(_MAN_$(L)_$(S)),$(INSTALL_DATA) $(v)doc/man/$(P).$(L).$(S) -- "$(DESTDIR)$(MANDIR)/$(L)/$(MAN$(S))/$(P)$(MAN$(S)EXT)" &&))) $(TRUE) -endif -ifdef __MAN_COMMAND - $(Q)$(foreach L,$(MAN_LOCALES),$(foreach S,$(_MAN_PAGE_SECTIONS),$(foreach P,$(_MAN_$(L)_$(S)),$(INSTALL_DATA) $(v)doc/man/$(P).$(L).$(S) -- "$(DESTDIR)$(MANDIR)/$(L)/$(MAN$(S))/$(__MAN_COMMAND)" &&))) $(TRUE) -endif - @$(ECHO_EMPTY) - - -# UNINSTALL RULES: - -.PHONY: uninstall-man -uninstall-man: -ifndef __MAN_COMMAND - -$(Q)$(RM) -- $(foreach S,$(_MAN_PAGE_SECTIONS),$(foreach P,$(_MAN_$(S)),"$(DESTDIR)$(MANDIR)/$(MAN$(S))/$(P).$(MAN$(S)EXT)")) - -$(Q)$(RM) -- $(foreach L,$(MAN_LOCALES),$(foreach S,$(_MAN_PAGE_SECTIONS),$(foreach P,$(_MAN_$(L)_$(S)),"$(DESTDIR)$(MANDIR)/$(L)/$(MAN$(S))/$(P)$(MAN$(S)EXT)"))) -endif -ifdef __MAN_COMMAND - -$(Q)$(RM) -- "$(DESTDIR)$(MANDIR)/$(MAN$(_MAN_PAGE_SECTIONS))/$(__MAN_COMMAND)" - -$(Q)$(RM) -- $(foreach L,$(MAN_LOCALES),$(foreach S,$(_MAN_PAGE_SECTIONS),$(foreach P,$(_MAN_$(L)_$(S)),"$(DESTDIR)$(MANDIR)/$(L)/$(MAN$(S))/$(__MAN_COMMAND)"))) -endif - - -endif - diff --git a/mk/path.mk b/mk/path.mk deleted file mode 100644 index 9d9d855..0000000 --- a/mk/path.mk +++ /dev/null @@ -1,176 +0,0 @@ -# Copyright (C) 2015, 2016 Mattias Andrée <maandree@member.fsf.org> -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without any warranty. - - -#=== This file define path variables. ===# - - -ifndef __PATH_MK_INCLUDED -__PATH_MK_INCLUDED = 1 - - -# DIRECTORIES: - -# The package path prefix, if you want to install to another root, set DESTDIR to that root. -PREFIX = /usr -# The package path prefix for /bin, /sbin, /lib and /libexec. -EXEC_PREFIX = /usr -# The command path excluding prefix. -BIN = /bin -# The administration command path excluding prefix. -SBIN = /sbin -# The library path excluding prefix. -LIB = /lib -# The executable library path excluding prefix. -LIBEXEC = /libexec -# The header-file path excluding prefix. -INCLUDE = /include -# The resource path excluding prefix. -DATA = /share -# The man page sections path excluding prefix. -MAN0 = /man0 -MAN1 = /man1 -MAN2 = /man2 -MAN3 = /man3 -MAN4 = /man4 -MAN5 = /man5 -MAN6 = /man6 -MAN7 = /man7 -MAN8 = /man8 -MAN9 = /man9 - -# The command path including prefix. -BINDIR = $(EXEC_PREFIX)$(BIN) -# The administration command path including prefix. -SBINDIR = $(EXEC_PREFIX)$(SBIN) -# The library path including prefix. -LIBDIR = $(EXEC_PREFIX)$(LIB) -# The executable library path including prefix. -LIBEXECDIR = $(EXEC_PREFIX)$(LIBEXEC) -# The header-file path including prefix. -INCLUDEDIR = $(PREFIX)$(INCLUDE) -# The header-file path including prefix. Must not be /usr/local. -ifeq ($(PREFIX),/usr/lcoal) -OLDINCLUDEDIR = /usr$(INCLUDE) -endif -ifneq ($(PREFIX),/usr/lcoal) -OLDINCLUDEDIR = $(PREFIX)$(INCLUDE) -endif -# The data path including prefix. -DATADIR = $(PREFIX)$(DATA) -# The architecture-dependent data path including prefix. -SYSDEPDATADIR = $(DATADIR) -# The resource path including prefix. -RESDIR = $(DATADIR) -# The architecture-dependent resource path including prefix. -SYSDEPRESDIR = $(RESDIR) -# The generic documentation path including prefix. -DOCDIR = $(DATADIR)/doc/$(PKGNAME) -# The info manual documentation path including prefix. -INFODIR = $(DATADIR)/info -# The DVI documentation path including prefix. -DVIDIR = $(DOCDIR) -# The PDF documentation path including prefix. -PDFDIR = $(DOCDIR) -# The PostScript documentation path including prefix. -PSDIR = $(DOCDIR) -# The HTML documentation path including prefix. -HTMLDIR = $(DOCDIR) -# The man page documentation path including prefix. -MANDIR = $(DATADIR)/man -# The Emacs LISP path including prefix. -LISPDIR = $(DATADIR)/emacs/site-lisp -# The locale path including prefix. -LOCALEDIR = $(DATADIR)/locale -# The license base path including prefix. -LICENSEDIR = $(DATADIR)/licenses -# The persistent variable data directory. -VARDIR = /var -# The persistent directory for temporary files. -VARTMPDIR = $(VARDIR)/tmp -# The network-common persistent variable data directory. -COMDIR = /com -# The network-common persistent directory for temporary files. -COMTMPDIR = $(COMDIR)/tmp -# The transient directory for temporary files. -TMPDIR = /tmp -# The transient directory for runtime files. -RUNDIR = /run -# The directory for site-specific configurations. -SYSCONFDIR = /etc -# The directory for pseudo-devices. -DEVDIR = /dev -# The /sys directory. -SYSDIR = /sys -# The /proc directory -PROCDIR = /proc -# The /proc/self directory -SELFPROCDIR = $(PROCDIR)/self -# The cache directory. -CACHEDIR = $(VARDIR)/cache -# The spool directory. -SPOOLDIR = $(VARDIR)/spool -# The empty directory. -EMPTYDIR = $(VARDIR)/empty -# The logfile directory. -LOGDIR = $(VARDIR)/log -# The state directory. -STATEDIR = $(VARDIR)/lib -# The highscore directory. -GAMEDIR = $(VARDIR)/games -# The lockfile directory. -LOCKDIR = $(RUNDIR)/lock -# The user skeleton directory. -SKELDIR = $(SYSCONFDIR)/skel -# The network-common cache directory. -COMCACHEDIR = $(COMDIR)/cache -# The network-common spool directory. -COMSPOOLDIR = $(COMDIR)/spool -# The network-common logfile directory. -COMLOGDIR = $(COMDIR)/log -# The network-common state directory. -COMSTATEDIR = $(COMDIR)/lib -# The network-common highscore directory. -COMGAMEDIR = $(COMDIR)/games - - -# FILENAME SUFFIXES: - -# Filename suffixes for man pages by section. -MAN0EXT = .0 -MAN1EXT = .1 -MAN2EXT = .2 -MAN3EXT = .3 -MAN4EXT = .4 -MAN5EXT = .5 -MAN6EXT = .6 -MAN7EXT = .7 -MAN8EXT = .8 -MAN9EXT = .9 - - -# HELP VARIABLES: - -# All path variables that includes the prefix, -# or are unaffected by the prefix. -_ALL_DIRS = BINDIR SBINDIR LIBDIR LIBEXECDIR INCLUDEDIR DATADIR SYSDEPDATADIR DOCDIR \ - INFODIR DVIDIR PDFDIR PSDIR HTMLDIR MANDIR LOCALEDIR LICENSEDIR VARDIR \ - RESDIR VARTMPDIR COMDIR COMTMPDIR TMPDIR RUNDIR SYSCONFDIR DEVDIR SYSDIR \ - PROCDIR SELFPROCDIR CACHEDIR SPOOLDIR EMPTYDIR LOGDIR STATEDIR GAMEDIR \ - LOCKDIR SKELDIR COMCACHEDIR COMSPOOLDIR COMLOGDIR COMSTATEDIR COMGAMEDIR \ - SYSDEPRESDIR OLDINCLUDEDIR - -# ../, ../../, and ../../../, ignored if v is used, which if an absolute path. -ifndef v -__back1unless_v = ../ -__back2unless_v = ../../ -__back3unless_v = ../../../ -endif - - -endif - diff --git a/mk/prologue.mk b/mk/prologue.mk deleted file mode 100644 index 5d9a558..0000000 --- a/mk/prologue.mk +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright (C) 2015, 2016 Mattias Andrée <maandree@member.fsf.org> -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without any warranty. - - -#=== This file includes rules for automatically rebuilding the makefile. ===# - - -base: Makefile - -Makefile: $(v)Makefile.in config.status $(v)configure $(v)mk/configure - ./config.status - diff --git a/mk/shell.mk b/mk/shell.mk deleted file mode 100644 index 2747152..0000000 --- a/mk/shell.mk +++ /dev/null @@ -1,233 +0,0 @@ -# Copyright (C) 2015, 2016 Mattias Andrée <maandree@member.fsf.org> -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without any warranty. - - -#=== These rules are used for shell tab-completion using auto-auto-complete. ===# - - -# Enables the rules: -# shell Build tab-completion for all supported shells -# bash Build GNU Bash tab-completion -# fish Build fish tab-completion -# zhs Build Z shell tab-completion -# install-shell Install tab-completion for all supported shells -# install-bash Install GNU Bash tab-completion -# install-fish Install fish tab-completion -# install-zsh Install Z shell tab-completion -# -# This file is ignored unless -# _AUTO_COMPLETE is defined. -# -# _AUTO_COMPLETE shall list all commands that -# have an auto-auto-complete. These should be -# named src/$(COMMAND).auto-completion, where -# $(COMMAND) is the command with the script. -# If all auto-auto-complete scripts translations -# named src/$(COMMAND).$(LOCALE).auto-completion, -# SHELL_LOCALE can be set to install exactly -# on translation in place of the non-translated -# versions. -# -# Although not used by this file, you should -# define _SHELL_LOCALES that lists all available -# translations. (it is used by dist.mk.) -# -# You should also define _WITH_SHELL if you -# want shell tab-completion unless the user -# specifies otherwise. If you want it for -# just some shells, define _WITH_$(SHELL) -# for those shells instead of _WITH_SHELL. - - -ifdef _AUTO_COMPLETE - - -# HELP VARIABLES: - -# Include all that were not explicitly excluded? -ifdef _WITH_SHELL -_WITH_BASH = 1 -_WITH_FISH = 1 -_WITH_ZSH = 1 -endif - -# Include for GNU Bash? -ifdef WITH_BASH -__WITH_BASH = 1 -endif -ifndef WITH_BASH -ifndef WITHOUT_BASH -ifdef _WITH_BASH -__WITH_BASH = 1 -endif -endif -endif - -# Include for fish? -ifdef WITH_FISH -__WITH_FISH = 1 -endif -ifndef WITH_FISH -ifndef WITHOUT_FISH -ifdef _WITH_FISH -__WITH_FISH = 1 -endif -endif -endif - -# Include for Z Shell? -ifdef WITH_ZSH -__WITH_ZSH = 1 -endif -ifndef WITH_ZSH -ifndef WITHOUT_ZSH -ifdef _WITH_ZSH -__WITH_ZSH = 1 -endif -endif -endif - -# WHEN TO BUILD, INSTALL, AND UNINSTALL: - -all: shell -everything: shell -install: install-shell -install-doc: install-info install-dvi install-pdf install-ps install-html -uninstall: uninstall-shell - -shell: -install-shell: - -ifdef __WITH_BASH -shell: bash -install-shell: install-bash -endif -ifdef __WITH_FISH -shell: fish -install-shell: install-fish -endif -ifdef __WITH_ZSH -shell: zsh -install-shell: install-zsh -endif - - -# HELP VARIABLES: - -# Affixes on the source files. -ifdef SHELL_LOCALE -__AAC_L = .$(SHELL_LOCALE) -endif -__AAC = $(__AAC_L).auto-completion - -# Customised command name. -ifdef COMMAND -ifeq ($(shell $(PRINTF) '%s\n' $(COMMAND) | $(WC) -l),1) -ifeq ($(shell $(PRINTF) '%s\n' $(_AUTO_COMPLETE) | $(WC) -l),1) -__SHELL_COMMAND = "command=$(COMMAND)" -endif -endif -endif - - -# BUILD RULES: - -# Built tab-completion scripts for GNU Bash. -.PHONY: bash -bash: $(foreach F,$(_AUTO_COMPLETE),bin/$(F).bash-completion) - -# Built tab-completion scripts for fish. -.PHONY: fish -fish: $(foreach F,$(_AUTO_COMPLETE),bin/$(F).fish-completion) - -# Built tab-completion scripts for Z shell. -.PHONY: zsh -zsh: $(foreach F,$(_AUTO_COMPLETE),bin/$(F).zsh-completion) - -# Built a tab-completion script for GNU Bash. -bin/%.bash-completion: $(v)src/%$(__AAC) - @$(PRINTF_INFO) '\e[00;01;31mAUTO-AUTO-COMPLETE\e[34m %s\e[00m$A\n' "$@" - @$(MKDIR) -p bin - $(Q)$(AUTO_AUTO_COMPLETE) bash -o $@ -s $< $(__SHELL_COMMAND) #$Z - @$(ECHO_EMPTY) - -# Built a tab-completion script for fish. -bin/%.fish-completion: $(v)src/%$(__AAC) - @$(PRINTF_INFO) '\e[00;01;31mAUTO-AUTO-COMPLETE\e[34m %s\e[00m$A\n' "$@" - @$(MKDIR) -p bin - $(Q)$(AUTO_AUTO_COMPLETE) fish -o $@ -s $< $(__SHELL_COMMAND) #$Z - @$(ECHO_EMPTY) - -# Built a tab-completion script for Z shell. -bin/%.zsh-completion: $(v)src/%$(__AAC) - @$(PRINTF_INFO) '\e[00;01;31mAUTO-AUTO-COMPLETE\e[34m %s\e[00m$A\n' "$@" - @$(MKDIR) -p bin - $(Q)$(AUTO_AUTO_COMPLETE) zsh -o $@ -s $< $(__SHELL_COMMAND) #$Z - @$(ECHO_EMPTY) - - -# INSTALL RULES: - -# Install tab-completion scripts for GNU Bash. -.PHONY: install-bash -install-bash: $(foreach F,$(_AUTO_COMPLETE),bin/$(F).bash-completion) - @$(PRINTF_INFO) '\e[00;01;31mINSTALL\e[34m %s\e[00m\n' "$@" - $(Q)$(INSTALL_DIR) -- "$(DESTDIR)$(DATADIR)/bash-completion/completions" -ifndef __SHELL_COMMAND - $(Q)$(foreach F,$(_AUTO_COMPLETE),$(INSTALL_DATA) bin/$(F).bash-completion -- "$(DESTDIR)$(DATADIR)/bash-completion/completions/$(F)" &&) $(TRUE) -endif -ifdef __SHELL_COMMAND - $(Q)$(INSTALL_DATA) $^ -- "$(DESTDIR)$(DATADIR)/bash-completion/completions/$(COMMAND)" -endif - @$(ECHO_EMPTY) - -# Install tab-completion scripts for fish. -.PHONY: install-fish -install-fish: $(foreach F,$(_AUTO_COMPLETE),bin/$(F).fish-completion) - @$(PRINTF_INFO) '\e[00;01;31mINSTALL\e[34m %s\e[00m\n' "$@" - $(Q)$(INSTALL_DIR) -- "$(DESTDIR)$(DATADIR)/fish/completions" -ifndef __SHELL_COMMAND - $(Q)$(foreach F,$(_AUTO_COMPLETE),$(INSTALL_DATA) bin/$(F).fish-completion -- "$(DESTDIR)$(DATADIR)/fish/completions/$(F).fish" &&) $(TRUE) -endif -ifdef __SHELL_COMMAND - $(Q)$(INSTALL_DATA) $^ -- "$(DESTDIR)$(DATADIR)/fish/completions/$(COMMAND).fish" -endif - @$(ECHO_EMPTY) - -# Install tab-completion scripts for Z shell. -.PHONY: install-zsh -install-zsh: $(foreach F,$(_AUTO_COMPLETE),bin/$(F).zsh-completion) - @$(PRINTF_INFO) '\e[00;01;31mINSTALL\e[34m %s\e[00m\n' "$@" - $(Q)$(INSTALL_DIR) -- "$(DESTDIR)$(DATADIR)/zsh/site-functions" -ifndef __SHELL_COMMAND - $(Q)$(foreach F,$(_AUTO_COMPLETE),$(INSTALL_DATA) bin/$(F).zsh-completion -- "$(DESTDIR)$(DATADIR)/zsh/site-functions/_$(F)" &&) $(TRUE) -endif -ifdef __SHELL_COMMAND - $(Q)$(INSTALL_DATA) $^ -- "$(DESTDIR)$(DATADIR)/zsh/site-functions/_$(COMMAND)" -endif - @$(ECHO_EMPTY) - - -# UNINSTALL RULES: - -# Uninstall tab-completion. -.PHONY: uninstall-shell -uninstall-shell: -ifndef __SHELL_COMMAND - -$(Q)$(RM) -- $(foreach F,$(_AUTO_COMPLETE),"$(DESTDIR)$(DATADIR)/bash-completion/completions/$(F)") - -$(Q)$(RM) -- $(foreach F,$(_AUTO_COMPLETE),"$(DESTDIR)$(DATADIR)/fish/completions/$(F).fish") - -$(Q)$(RM) -- $(foreach F,$(_AUTO_COMPLETE),"$(DESTDIR)$(DATADIR)/zsh/site-functions/_$(F)") -endif -ifdef __SHELL_COMMAND - -$(Q)$(RM) -- "$(DESTDIR)$(DATADIR)/bash-completion/completions/$(COMMAND)" - -$(Q)$(RM) -- "$(DESTDIR)$(DATADIR)/fish/completions/$(COMMAND).fish" - -$(Q)$(RM) -- "$(DESTDIR)$(DATADIR)/zsh/site-functions/_$(COMMAND)" -endif - - -endif - diff --git a/mk/tags.mk b/mk/tags.mk deleted file mode 100644 index 926cb5d..0000000 --- a/mk/tags.mk +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (C) 2015, 2016 Mattias Andrée <maandree@member.fsf.org> -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without any warranty. - - -#=== These rules are used for generate etags- and ctags-tablse. ===# - - -# Generate etags-table. -.PHONY: TAGS -TAGS: - @$(ECHO) - @$(ECHO) "TAGS is not implemented. Did not see the need. Feel free to implement if you want." - @$(ECHO) - -# Generate ctags-table -.PHONY: tags -tags: - @$(ECHO) - @$(ECHO) "tags is not implemented. Did not see the need. Feel free to implement if you want." - @$(ECHO) - diff --git a/mk/texinfo.mk b/mk/texinfo.mk deleted file mode 100644 index e2ccb12..0000000 --- a/mk/texinfo.mk +++ /dev/null @@ -1,294 +0,0 @@ -# Copyright (C) 2015, 2016 Mattias Andrée <maandree@member.fsf.org> -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without any warranty. - - -# TODO ((support translations)) -#=== These rules are used for Texinfo manuals. ===# - - -# Enables the rules: -# info Build info manual -# dvi Build DVI manual -# pdf Build PDF manual -# ps Build PostScript manual -# html Build HTML manual -# install-info Install info manual -# install-dvi Install DVI manual -# install-pdf Install PDF manual -# install-ps Install PostScript manual -# install-html Install HTML manual -# -# This file is ignored unless -# _HAVE_TEXINFO_MANUAL is defined. -# -# This file can only build output for -# one Texinfo manual. This manual must -# be named doc/info/$(_PROJECT).texinfo. -# Additional sourced are set by specifing -# how man directories deep doc/info nests -# in the variable _TEXINFO_DIRLEVELS. -# -# If the info manual splits, specify the -# split-number, of the file with the highest -# split-number, in the variable _INFOPARTS. -# -# If the project has a logo, _LOGO should -# name the suffixless basename of the SVG -# files that contains the logo. This file -# must be located in doc/. -# -# _HTML_FILES should the basename (with -# suffix) of all files generated by `html`. -# -# The user may define TEXINFO_FLAGS that -# adds additional flags when compiling -# DVI, PDF, and PostScript manuals. The -# user may also define INFO_FLAGS that -# adds additional flags when compiling -# info and HTML manuals. - - -ifdef _HAVE_TEXINFO_MANUAL - - -# WHEN TO BUILD, INSTALL, AND UNINSTALL: - -all: info -everything: info dvi pdf ps html -doc: info dvi pdf ps html -install: install-info -install-everything: install-info install-dvi install-pdf install-ps install-html -install-doc: install-info install-dvi install-pdf install-ps install-html -uninstall: uninstall-info uninstall-dvi uninstall-pdf uninstall-ps uninstall-html - - -# HELP VARIABLES: - -# Files from which the Texinfo manuals are built. -ifdef _TEXINFO_DIRLEVELS -ifeq ($(_TEXINFO_DIRLEVELS),1) -__TEXI_SRC_ = *.texinfo -endif -ifeq ($(_TEXINFO_DIRLEVELS),2) -__TEXI_SRC_ = *.texinfo */*.texinfo -endif -ifeq ($(_TEXINFO_DIRLEVELS),3) -__TEXI_SRC_ = *.texinfo */*.texinfo */*/*.texinfo -endif -ifneq ($(_TEXINFO_DIRLEVELS),1) -ifneq ($(_TEXINFO_DIRLEVELS),2) -ifneq ($(_TEXINFO_DIRLEVELS),3) -__TEXI_SRC_ = $(foreach W,$(shell $(SEQ) $(_TEXINFO_DIRLEVELS) | while read n; do $(ECHO) $$($(SEQ) $$n)" " | $(SED) 's/[^ ]* /\/\*/g'; done | $(XARGS) $(ECHO)),$(shell $(ECHO) $(W).texinfo | $(SED) 's/^.//')) -endif -endif -endif -__TEXI_SRC = $(foreach S,$(__TEXI_SRC_),$(foreach F,$(shell cd $(v)doc/info && $(ECHO) $(S)),aux/doc/$(F))) -endif - -# Split parts of the info manual. -ifdef _INFOPARTS -ifneq ($(_INFOPARTS),0) -__INFOPARTS = $(shell $(SEQ)) -endif -endif - -# Flags for TeX processed output. -__TEXINFO_FLAGS = $(TEXINFO_FLAGS) -ifdef _LOGO -__TEXINFO_FLAGS += '--texinfo="@set LOGO $(_LOGO)"' -endif - - -# BUILD RULES: - -ifdef _LOGO -# Prepare conversion of logo. -aux/$(_LOGO).svg: $(v)doc/$(_LOGO).svg - @$(PRINTF_INFO) '\e[00;01;31mCP\e[34m %s\e[00m$A\n' "$@" - @$(MKDIR) -p aux - $(Q)$(CP) $^ $@ #$Z - @$(ECHO_EMPTY) - -# Intermediate format for the logo for DVI and PostScript manuals. -aux/$(_LOGO).ps: $(v)doc/$(_LOGO).svg - @$(PRINTF_INFO) '\e[00;01;31mPS\e[34m %s\e[00m$A\n' "$@" - @$(MKDIR) -p aux - $(Q)$(SVG2PS) $^ > $@ #$Z - @$(ECHO_EMPTY) - -# Logo for DVI and PostScript manuals. -aux/$(_LOGO).eps: aux/$(_LOGO).ps - @$(PRINTF_INFO) '\e[00;01;31mEPS\e[34m %s\e[00m$A\n' "$@" - $(Q)$(PS2EPS) $^ #$Z - @$(ECHO_EMPTY) - -# Logo for PDF manual. -aux/$(_LOGO).pdf: $(v)doc/$(_LOGO).svg - @$(PRINTF_INFO) '\e[00;01;31mPDF\e[34m %s\e[00m$A\n' "$@" - @$(MKDIR) -p aux - $(Q)$(SVG2PDF) $^ > $@ #$Z - @$(ECHO_EMPTY) -endif - -# Copy texinfo files to aux/doc. -aux/doc/%.texinfo: $(v)doc/info/%.texinfo - @$(PRINTF_INFO) '\e[00;01;31mCP\e[34m %s\e[00m$A\n' "$@" - @$(MKDIR) -p $(shell $(DIRNAME) $@) - $(Q)$(CP) $< $@ #$Z - @$(ECHO_EMPTY) - -# Build info manual. -.PHONY: info -info: $(__TEXI_SRC) bin/$(_PROJECT).info -bin/%.info $(foreach P,$(__INFOPARTS),bin/%.info-$(P)): aux/doc/%.texinfo $(__TEXI_SRC) - @$(PRINTF_INFO) '\e[00;01;31mTEXI\e[34m %s\e[00m$A\n' "$@" - @$(MKDIR) -p bin - $(Q)$(MAKEINFO) $(INFO_FLAGS) $< #$Z - @$(PRINTF_INFO) '$A' - $(Q)$(MV) $*.info $@ #$Z - @$(ECHO_EMPTY) - -# Build DVI manual. -.PHONY: dvi -dvi: $(__TEXI_SRC) bin/$(_PROJECT).dvi -bin/%.dvi: aux/doc/%.texinfo $(__TEXI_SRC) $(foreach L,$(_LOGO),aux/$(L).eps) - @$(PRINTF_INFO) '\e[00;01;31mTEXI\e[34m %s\e[00m$A\n' "$@" - @! $(TEST) -d aux/dvi/$* || $(RM) -rf aux/dvi/$* - @$(MKDIR) -p aux/dvi/$* bin - $(Q)cd aux/dvi/$* && $(TEXI2DVI) $(__back3unless_v)$< $(__TEXINFO_FLAGS) < /dev/null #$Z - @$(PRINTF_INFO) '$A' - $(Q)$(MV) aux/dvi/$*/$*.dvi $@ #$Z - @$(ECHO_EMPTY) - -# Build PDF manual. -.PHONY: pdf -pdf: $(__TEXI_SRC) bin/$(_PROJECT).pdf -bin/%.pdf: aux/doc/%.texinfo $(__TEXI_SRC) $(foreach L,$(_LOGO),aux/$(L).pdf) - @$(PRINTF_INFO) '\e[00;01;31mTEXI\e[34m %s\e[00m$A\n' "$@" - @! $(TEST) -d aux/pdf/$* || $(RM) -rf aux/pdf/$* - @$(MKDIR) -p aux/pdf/$* bin - $(Q)cd aux/pdf/$* && $(TEXI2PDF) $(__back3unless_v)$< $(__TEXINFO_FLAGS) < /dev/null #$Z - @$(PRINTF_INFO) '$A' - $(Q)$(MV) aux/pdf/$*/$*.pdf $@ #$Z - @$(ECHO_EMPTY) - -# Build PostScript manual. -.PHONY: ps -ps: $(__TEXI_SRC) bin/$(_PROJECT).ps -bin/%.ps: aux/doc/%.texinfo $(__TEXI_SRC) $(foreach L,$(_LOGO),aux/$(L).eps) - @$(PRINTF_INFO) '\e[00;01;31mTEXI\e[34m %s\e[00m$A\n' "$@" - @! $(TEST) -d aux/ps/$* || $(RM) -rf aux/ps/$* - @$(MKDIR) -p aux/ps/$* bin - $(Q)cd aux/ps/$* && $(TEXI2PS) $(__back3unless_v)$< $(__TEXINFO_FLAGS) < /dev/null #$Z - @$(PRINTF_INFO) '$A' - $(Q)$(MV) aux/ps/$*/$*.ps $@ #$Z - @$(ECHO_EMPTY) - -# Build HTML manual. -.PHONY: html -html: $(__TEXI_SRC) bin/html/$(_PROJECT)/index.html -bin/html/%/index.html: aux/doc/%.texinfo $(__TEXI_SRC) - @$(PRINTF_INFO) '\e[00;01;31mTEXI\e[34m %s\e[00m$A\n' "$@" - @! $(TEST) -d bin/html/$* || $(RM) -rf bin/html/$* - @$(MKDIR) -p bin/html - $(Q)cd bin/html && $(MAKEINFO_HTML) $(INFO_FLAGS) $(__back2unless_v)$< < /dev/null #$Z - @$(ECHO_EMPTY) - - -# INSTALL RULES: - -# Install info manual. -.PHONY: install-info -install-info: bin/$(_PROJECT).info $(foreach P,$(__INFOPARTS),bin/%.info-$(P)) - @$(PRINTF_INFO) '\e[00;01;31mINSTALL\e[34m %s\e[00m\n' "$@" - $(Q)$(INSTALL_DIR) -- "$(DESTDIR)$(INFODIR)" - $(Q)$(INSTALL_DATA) bin/$(_PROJECT).info -- "$(DESTDIR)$(INFODIR)/$(PKGNAME).info" - $(Q)$(forearch P,$(__INFOPARTS),$(INSTALL_DATA) bin/$*.info-$(P) -- "$(DESTDIR)$(INFODIR)/$(PKGNAME).info-$(P)" &&) $(TRUE) -ifdef POST_INSTALL - $(POST_INSTALL) -endif - $(Q)if $(SHELL) -c '$(N) $(INSTALL_INFO) --version' > /dev/null 2>&1; then \ - $(N)$(z) $(INSTALL_INFO) -- "${DESTDIR}${INFODIR}/$(PKGNAME).info" "${DESTDIR}${INFODIR}/dir"; \ - else \ - $(TRUE); \ - fi -ifdef POST_INSTALL - $(NORMAL_INSTALL) -endif - @$(ECHO_EMPTY) - -# Install DVI manual. -.PHONY: install-dvi -install-dvi: bin/$(_PROJECT).dvi - @$(PRINTF_INFO) '\e[00;01;31mINSTALL\e[34m %s\e[00m\n' "$@" - $(Q)$(INSTALL_DIR) -- "$(DESTDIR)$(DVIDIR)" - $(Q)$(INSTALL_DATA) $^ -- "$(DESTDIR)$(DVIDIR)/$(PKGNAME).dvi" - @$(ECHO_EMPTY) - -# Install PDF manual. -.PHONY: install-pdf -install-pdf: bin/$(_PROJECT).pdf - @$(PRINTF_INFO) '\e[00;01;31mINSTALL\e[34m %s\e[00m\n' "$@" - $(Q)$(INSTALL_DIR) -- "$(DESTDIR)$(PDFDIR)" - $(Q)$(INSTALL_DATA) $^ -- "$(DESTDIR)$(PDFDIR)/$(PKGNAME).pdf" - @$(ECHO_EMPTY) - -# Install PostScript manual. -.PHONY: install-ps -install-ps: bin/$(_PROJECT).ps - @$(PRINTF_INFO) '\e[00;01;31mINSTALL\e[34m %s\e[00m\n' "$@" - $(Q)$(INSTALL_DIR) -- "$(DESTDIR)$(PSDIR)" - $(Q)$(INSTALL_DATA) $^ -- "$(DESTDIR)$(PSDIR)/$(PKGNAME).ps" - @$(ECHO_EMPTY) - -# Install HTML manual. -.PHONY: install-html -install-html: $(foreach F,$(_HTML_FILES),bin/html/$(_PROJECT)/$(F)) - @$(PRINTF_INFO) '\e[00;01;31mINSTALL\e[34m %s\e[00m\n' "$@" - $(Q)$(INSTALL_DIR) -- "$(DESTDIR)$(HTMLDIR)/$(PKGNAME)" - $(Q)$(INSTALL_DATA) $^ -- "$(DESTDIR)$(HTMLDIR)/$(PKGNAME)/" - @$(ECHO_EMPTY) - - -# UNINSTALL RULES: - -# Uninstall info manual. -.PHONY: uninstall-info -uninstall-info: -ifdef PRE_UNINSTALL - $(PRE_UNINSTALL) -endif - -$(Q)$(N)$(a) $(INSTALL_INFO) --delete -- "${DESTDIR}${INFODIR}/$(PKGNAME).info" "${DESTDIR}${INFODIR}/dir" -ifdef PRE_UNINSTALL - $(NORMAL_UNINSTALL) -endif - -$(Q)$(RM) -- "$(DESTDIR)$(INFODIR)/$(PKGNAME).info" $(forearch P,$(__INFOPARTS),"$(DESTDIR)$(INFODIR)/$(PKGNAME).info-$(P)") - -# Uninstall DVI manual. -.PHONY: uninstall-dvi -uninstall-dvi: - -$(Q)$(RM) -- "$(DESTDIR)$(DVIDIR)/$(PKGNAME).dvi" - -# Uninstall PDF manual. -.PHONY: uninstall-pdf -uninstall-pdf: - -$(Q)$(RM) -- "$(DESTDIR)$(PDFDIR)/$(PKGNAME).pdf" - -# Uninstall PostScript manual. -.PHONY: uninstall-ps -uninstall-ps: - -$(Q)$(RM) -- "$(DESTDIR)$(PSDIR)/$(PKGNAME).ps" - -# Uninstall HTML manual. -.PHONY: uninstall-html -uninstall-html: - -$(Q)$(RM) -- $(foreach F,$(_HTML_FILES),"$(DESTDIR)$(HTMLDIR)/$(PKGNAME)/$(F)") - -$(Q)$(RM) -- "$(DESTDIR)$(HTMLDIR)/$(PKGNAME)" - - -endif - diff --git a/mk/tools.mk b/mk/tools.mk deleted file mode 100644 index e3d9bfe..0000000 --- a/mk/tools.mk +++ /dev/null @@ -1,163 +0,0 @@ -# Copyright (C) 2015, 2016 Mattias Andrée <maandree@member.fsf.org> -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without any warranty. - - -#=== This file defines variables for all used commands. ===# - - -# Part of GNU Coreutils: -BASENAME ?= basename -CHGRP ?= chgrp -CHMOD ?= chmod -CHOWN ?= chown -CP ?= cp -CPLIT ?= cplit -CUT ?= cut -DATE ?= date -DIRNAME ?= dirname -ECHO ?= echo -ENV ?= env -EXPAND ?= expand -EXPR ?= expr -FALS ?= false -FMT ?= fmt -FOLD ?= fold -HEAD ?= head -INSTALL ?= install -INSTALL_DATA ?= $(INSTALL) -m644 -INSTALL_DIR ?= $(INSTALL) -dm755 -INSTALL_PROGRAM ?= $(INSTALL) -m755 -JOIN ?= join -LN ?= ln -MKDIR ?= mkdir -MKFIFO ?= mkfifo -MKNOD ?= mknod -MV ?= mv -NL ?= nl -NPROC ?= nproc -NUMFMT ?= numfmt -OD ?= od -PASTE ?= paste -PATHCHK ?= pathchk -PR ?= pr -PRINTF ?= printf -READLINK ?= readlink -REALPATH ?= realpath -RM ?= rm -RMDIR ?= rmdir -SEQ ?= seq -SLEEP ?= sleep -SORT ?= sort -SPLIT ?= split -STAT ?= stat -TAC ?= tac -TAIL ?= tail -TEE ?= tee -TEST ?= test -TOUCH ?= touch -TR ?= tr -TRUE ?= true -TRUNCATE ?= truncate -TSORT ?= tsort -UNAME ?= uname -UNEXPAND ?= unexpand -UNIQ ?= uniq -WC ?= wc -YES ?= yes - -# Part of GNU help2man: -HELP2MAN ?= help2man - -# Part of GNU tar: -TAR ?= tar - -# Part of GNU Findutils: -FIND ?= find -XARGS ?= xargs - -# Part of GNU Grep: -GREP ?= grep -EGREP ?= egrep -FGREP ?= fgrep - -# Part of GNU Sed: -SED ?= sed - -# Part of GNU Privacy Guard: -GPG ?= gpg - -# Part of Texinfo: -MAKEINFO ?= makeinfo -MAKEINFO_HTML ?= $(MAKEINFO) --html -INSTALL_INFO ?= install-info - -# Part of Texlive-plainextra: -TEXI2PDF ?= texi2pdf -TEXI2DVI ?= texi2dvi -TEXI2PS ?= texi2pdf --ps - -# Part of Texlive-core: -PS2EPS ?= ps2eps - -# Part of librsvg: -RSVG_CONVERT ?= rsvg-convert -SVG2PS ?= $(RSVG_CONVERT) --format=ps -SVG2PDF ?= $(RSVG_CONVERT) --format=pdf - -# Part of GNU Compiler Collection: -CC ?= cc -CPP ?= cpp -CXX ?= c++ - -# Part of GNU Binutils: -AR ?= ar -LD ?= ld -RANLIB ?= ranlib - -# Part of GNU Bison: -BISON ?= bison -YACC ?= yacc - -# Part of Flex: -FLEX ?= FLEX -LEX ?= lex - -# Part of GNU C Library: -LDCONFIG ?= ldconfig - -# Part of GNU Gettext: -XGETTEXT ?= xgettext -MSGFMT ?= msgfmt -MSGMERGE ?= msgmerge -MSGINIT ?= msginit - -# Part of gzip: -GZIP ?= gzip -GZIP_COMPRESS ?= $(GZIP) -k9 - -# Part of bzip2: -BZIP2 ?= bzip2 -BZIP2_COMPRESS ?= $(BZIP2) -k9 - -# Part of xz: -XZ ?= xz -XZ_COMPRESS ?= $(XZ) -ke9 - -# Part of auto-auto-complete: -AUTO_AUTO_COMPLETE ?= auto-auto-complete - - -# Change to $(TRUE) to suppress the bold red and blue output. -ifndef PRINTF_INFO -PRINTF_INFO = $(PRINTF) -endif - -# Change to $(TRUE) to suppress empty lines -ifndef ECHO_EMPTY -ECHO_EMPTY = $(ECHO) -endif - diff --git a/src/libclut.c b/src/libclut.c deleted file mode 100644 index 934ed88..0000000 --- a/src/libclut.c +++ /dev/null @@ -1,775 +0,0 @@ -/** - * Copyright © 2016 Mattias Andrée <maandree@member.fsf.org> - * - * 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 "libclut.h" - -#include <errno.h> - - - -/** - * Convert one component from [0, 1] linear sRGB to [0, 1] sRGB. - * - * @param c The linear sRGB value. - * @return Corresponding sRGB value. - */ -double (libclut_model_linear_to_standard1)(double c) -{ - return libclut_model_linear_to_standard1(c); -} - - -/** - * Convert [0, 1] linear sRGB to [0, 1] sRGB. - * - * @param r Pointer to the linear red component, - * and output parameter for the red component. - * @param g Pointer to the linear green component, - * and output parameter for the green component. - * @param b Pointer to the linear blue component, - * and output parameter for the blue component. - */ -void (libclut_model_linear_to_standard)(double* r, double* g, double* b) -{ - libclut_model_linear_to_standard(r, g, b); -} - - -/** - * Convert one component from [0, 1] sRGB to [0, 1] linear sRGB. - * - * @param c The sRGB value. - * @return Corresponding linear sRGB value. - */ -double (libclut_model_standard_to_linear1)(double c) -{ - return libclut_model_standard_to_linear1(c); -} - - -/** - * Convert [0, 1] sRGB to [0, 1] linear sRGB. - * - * @param r Pointer to the red component, and output - * parameter for the linear red component. - * @param g Pointer to the green component, and output - * parameter for the linear green component. - * @param b Pointer to the blue component, and output - * parameter for the linear blue component. - */ -void (libclut_model_standard_to_linear)(double* r, double* g, double* b) -{ - libclut_model_standard_to_linear(r, g, b); -} - - -/** - * Convert CIE xyY to CIE XYZ. - * - * @param x The x parameter. - * @param y The y parameter. - * @param Y The Y parameter. This is also the Y (middle) parameter for the CIE XYZ colour. - * @param X Output parameter for the X parameter. - * @param Z Output parameter for the Z parameter. - */ -void (libclut_model_ciexyy_to_ciexyz)(double x, double y, double Y, double* X, double* Z) -{ - libclut_model_ciexyy_to_ciexyz(x, y, Y, X, Z); -} - - -/** - * Convert CIE XYZ to CIE xyY. - * - * @param X The X parameter. - * @param Y The Y parameter. This is also the Y (last) parameter for the CIE xyY colour. - * @param Z The Z parameter. - * @param x Output parameter for the x parameter. - * @param y Output parameter for the y parameter. - */ -void (libclut_model_ciexyz_to_ciexyy)(double X, double Y, double Z, double* x, double* y) -{ - libclut_model_ciexyz_to_ciexyy(X, Y, Z, x, y); -} - - -/** - * Convert CIE XYZ to [0, 1] linear sRGB. - * - * @param X The X parameter. - * @param Y The Y parameter. - * @param Z The Z parameter. - * @param r Output parameter for the red component. - * @param g Output parameter for the green component. - * @param b Output parameter for the blue component. - */ -void (libclut_model_ciexyz_to_linear)(double X, double Y, double Z, double* r, double* g, double* b) -{ - libclut_model_ciexyz_to_linear(X, Y, Z, r, g, b); -} - - -/** - * Convert [0, 1] linear sRGB to CIE XYZ. - * - * @param r The red component. - * @param g The green component. - * @param b The blue component. - * @param X Output parameter for the X parameter. - * @param Y Output parameter for the Y parameter. - * @param Z Output parameter for the Z parameter. - */ -void (libclut_model_linear_to_ciexyz)(double r, double g, double b, double* X, double* Y, double* Z) -{ - libclut_model_linear_to_ciexyz(r, g, b, X, Y, Z); -} - - -/** - * Convert [0, 1] linear sRGB to CIE xyY. - * - * @param r The red component. - * @param g The green component. - * @param b The blue component. - * @param x Output parameter for the x parameter. - * @param y Output parameter for the y parameter. - * @param Y Output parameter for the Y parameter. - */ -void (libclut_model_srgb_to_ciexyy)(double r, double g, double b, double* x, double* y, double* Y) -{ - libclut_model_srgb_to_ciexyy(r, g, b, x, y, Y); -} - - -/** - * Convert CIE xyY to [0, 1] sRGB. - * - * @param x The x parameter. - * @param y The y parameter. - * @param Y The Y parameter. - * @param r Output parameter for the red component. - * @param g Output parameter for the green component. - * @param b Output parameter for the blue component. - */ -void (libclut_model_ciexyy_to_srgb)(double x, double y, double Y, double* r, double* g, double* b) -{ - libclut_model_ciexyy_to_srgb(x, y, Y, r, g, b); -} - - -/** - * Convert from CIE XYZ to CIE L*a*b*. - * - * @param X The X parameter. - * @param Y The Y parameter. - * @param Z The Z parameter. - * @param L Output parameter for the L* component. - * @param a Output parameter for the a* component. - * @param b Output parameter for the b* component. - */ -void (libclut_model_ciexyz_to_cielab)(double X, double Y, double Z, double* L, double* a, double* b) -{ - libclut_model_ciexyz_to_cielab(X, Y, Z, L, a, b); -} - - -/** - * Convert from CIE L*a*b* to CIE XYZ. - * - * @param L The L* component. - * @param a The a* component. - * @param b The b* component. - * @param X Output parameter for the X parameter. - * @param Y Output parameter for the Y parameter. - * @param Z Output parameter for the Z parameter. - */ -void (libclut_model_cielab_to_ciexyz)(double L, double a, double b, double* X, double* Y, double* Z) -{ - libclut_model_cielab_to_ciexyz(L, a, b, X, Y, Z); -} - - -/** - * Convert from CIE XYZ to CIE L*u*v*. - * - * @param X The X parameter. - * @param Y The Y parameter. - * @param Z The Z parameter. - * @param Xn The X component of the specified white object (white point). - * @param Yn The Y component of the specified white object (white point). - * @param Zn The Z component of the specified white object (white point). - * @param L Output parameter for the L* component. - * @param u Output parameter for the u* component. - * @param v Output parameter for the v* component. - */ -void (libclut_model_ciexyz_to_cieluv)(double X, double Y, double Z, double Xn, double Yn, double Zn, - double* L, double* u, double* v) -{ - libclut_model_ciexyz_to_cieluv(X, Y, Z, Xn, Yn, Zn, L, u, v); -} - - -/** - * Convert from CIE L*u*v* to CIE XYZ. - * - * @param L The L* component. - * @param u The u* component. - * @param v The v* component. - * @param Xn The X component of the specified white object (white point). - * @param Yn The Y component of the specified white object (white point). - * @param Zn The Z component of the specified white object (white point). - * @param X Output parameter for the X parameter. - * @param Y Output parameter for the Y parameter. - * @param Z Output parameter for the Z parameter. - */ -void (libclut_model_cieluv_to_ciexyz)(double L, double u, double v, double Xn, double Yn, double Zn, - double* X, double* Y, double* Z) -{ - libclut_model_cieluv_to_ciexyz(L, u, v, Xn, Yn, Zn, X, Y, Z); -} - - -/** - * Convert from CIELCh to CIE L*u*v*. - * - * @param L The L* component. - * @param C The C*_uv component. - * @param h The h_uv component. - * @param u Output parameter for the u* parameter. - * @param v Output parameter for the v* parameter. - */ -void (libclut_model_cielch_to_cieluv)(double C, double h, double* u, double* v) -{ - libclut_model_cielch_to_cieluv(C, h, u, v); -} - - -/** - * Convert from CIE L*u*v* to CIELCh. - * - * @param L The L* component. - * @param u The u* component. - * @param v The v* component. - * @param C Output parameter for the C*_uv parameter. - * @param h Output parameter for the h_uv parameter. - */ -void (libclut_model_cieluv_to_cielch)(double u, double v, double* C, double* h) -{ - libclut_model_cieluv_to_cielch(u, v, C, h); -} - - -/** - * Convert from sRGB to YIQ. - * - * @param r The R component. - * @param g The G component. - * @param b The B component. - * @param y Output parameter for the Y parameter. - * @param i Output parameter for the I parameter. - * @param q Output parameter for the Q parameter. - */ -void (libclut_model_srgb_to_yiq)(double r, double g, double b, double* y, double* i, double* q) -{ - libclut_model_srgb_to_yiq(r, g, b, y, i, q); -} - - -/** - * Convert from YIQ to sRGB. - * - * @param y The Y component. - * @param i The I component. - * @param q The Q component. - * @param r Output parameter for the R parameter. - * @param g Output parameter for the G parameter. - * @param b Output parameter for the B parameter. - */ -void (libclut_model_yiq_to_srgb)(double y, double i, double q, double* r, double* g, double* b) -{ - libclut_model_yiq_to_srgb(y, i, q, r, g, b); -} - - -/** - * Convert from sRGB to YDbDr. - * - * @param r The R component. - * @param g The G component. - * @param b The B component. - * @param y Output parameter for the Y parameter. - * @param db Output parameter for the Db parameter. - * @param dr Output parameter for the Dr parameter. - */ -void (libclut_model_srgb_to_ydbdr)(double r, double g, double b, double* y, double* db, double* dr) -{ - libclut_model_srgb_to_ydbdr(r, g, b, y, db, dr); -} - - -/** - * Convert from YDbDr to sRGB. - * - * @param y The Y component. - * @param db The Db component. - * @param dr The Dr component. - * @param r Output parameter for the R parameter. - * @param g Output parameter for the G parameter. - * @param b Output parameter for the B parameter. - */ -void (libclut_model_ydbdr_to_srgb)(double y, double db, double dr, double* r, double* g, double* b) -{ - libclut_model_ydbdr_to_srgb(y, db, dr, r, g, b); -} - -/** - * Convert from YUV to YDbDr. - * - * @param u The U component. - * @param v The V component. - * @param db Output parameter for the Db parameter. - * @param dr Output parameter for the Dr parameter. - */ -void (libclut_model_yuv_to_ydbdr)(double u, double v, double* db, double* dr) -{ - libclut_model_yuv_to_ydbdr(u, v, db, dr); -} - - -/** - * Convert from YDbDr to YUV. - * - * @param db The Db component. - * @param dr The Dr component. - * @param u Output parameter for the U parameter. - * @param v Output parameter for the V parameter. - */ -void (libclut_model_ydbdr_to_yuv)(double db, double dr, double* u, double* v) -{ - libclut_model_ydbdr_to_yuv(db, dr, u, v); -} - - -/** - * Convert from sRGB to YPbPr. - * - * @param r The R component. - * @param g The G component. - * @param b The B component. - * @param y Output parameter for the Y parameter. - * @param pb Output parameter for the Pb parameter. - * @param pr Output parameter for the Pr parameter. - */ -void (libclut_model_srgb_to_ypbpr)(double r, double g, double b, double* y, double* pb, double* pr) -{ - libclut_model_srgb_to_ypbpr(r, g, b, y, pb, pr); -} - - -/** - * Convert from YPbPr to sRGB. - * - * @param y The Y component. - * @param pb The Pb component. - * @param pr The Pr component. - * @param r Output parameter for the R parameter. - * @param g Output parameter for the G parameter. - * @param b Output parameter for the B parameter. - */ -void (libclut_model_ypbpr_to_srgb)(double y, double pb, double pr, double* r, double* g, double* b) -{ - libclut_model_ypbpr_to_srgb(y, pb, pr, r, g, b); -} - - -/** - * Convert from sRGB to YCgCo. - * - * @param r The R component. - * @param g The G component. - * @param b The B component. - * @param y Output parameter for the Y parameter. - * @param cg Output parameter for the Cg parameter. - * @param co Output parameter for the Co parameter. - */ -void (libclut_model_srgb_to_ycgco)(double r, double g, double b, double* y, double* cg, double* co) -{ - libclut_model_srgb_to_ycgco(r, g, b, y, cg, co); -} - - -/** - * Convert from YCgCo to sRGB. - * - * @param y The Y component. - * @param cg The Cg component. - * @param co The Co component. - * @param r Output parameter for the R parameter. - * @param g Output parameter for the G parameter. - * @param b Output parameter for the B parameter. - */ -void (libclut_model_ycgco_to_srgb)(double y, double cg, double co, double* r, double* g, double* b) -{ - libclut_model_ycgco_to_srgb(y, cg, co, r, g, b); -} - - -/** - * Convert from CIE 1960 UCS to CIE XYZ. - * - * @param u The u component. - * @param v The v component. - * @param Y The Y component. - * @param x Output parameter for the X parameter. - * @param y Output parameter for the Y parameter. - * @param z Output parameter for the Z parameter. - */ -void (libclut_model_cie_1960_ucs_to_ciexyz)(double u, double v, double Y, double* x, double* y, double* z) -{ - libclut_model_cie_1960_ucs_to_ciexyz(u, v, Y, x, y, z); -} - - -/** - * Convert from CIE XYZ to CIE 1960 UCS. - * - * @param x The X component. - * @param y The Y component. - * @param z The Z component. - * @param u Output parameter for the u parameter. - * @param v Output parameter for the v parameter. - * @param Y Output parameter for the Y parameter. - */ -void (libclut_model_ciexyz_to_cie_1960_ucs)(double x, double y, double z, double* u, double* v, double* Y) -{ - libclut_model_ciexyz_to_cie_1960_ucs(x, y, z, u, v, Y); -} - - -/** - * Convert from CIEUVW to CIE 1960 UCS. - * - * @param U The U* component. - * @param V The V* component. - * @param W The W* component. - * @param u0 The u parameter for the white point. - * @param v0 The v parameter for the white point. - * @param u Output parameter for the u parameter. - * @param v Output parameter for the v parameter. - * @param Y Output parameter for the Y parameter. - */ -void (libclut_model_cieuvw_to_cie_1960_ucs)(double U, double V, double W, double u0, double v0, - double* u, double* v, double* Y) -{ - libclut_model_cieuvw_to_cie_1960_ucs(U, V, W, u0, v0, u, v, Y); -} - - -/** - * Convert from CIE 1960 UCS to CIEUVW. - * - * Requires linking with `-lm`. - * - * @param u The u component. - * @param v The v component. - * @param Y The Y component. - * @param u0 The u parameter for the white point. - * @param v0 The v parameter for the white point. - * @param U Output parameter for the U* parameter. - * @param V Output parameter for the V* parameter. - * @param W Output parameter for the W* parameter. - */ -void (libclut_model_cie_1960_ucs_to_cieuvw)(double u, double v, double Y, double u0, double v0, - double* U, double* V, double* W) -{ - libclut_model_cie_1960_ucs_to_cieuvw(u, v, Y, u0, v0, U, V, W); -} - - - -/** - * Divide all values in a row by a divisor. - * - * @param m The first part of the row. - * @param a The second part of the row. - * @param d The divisor. - */ -static void divrow(double m[3], double a[3], double d) -{ - m[0] /= d, m[1] /= d, m[2] /= d; - a[0] /= d, a[1] /= d, a[2] /= d; -} - -/** - * Subtract all values in a row by corresponding value - * in another row multiplied by a common value. - * - * @param a1 The first part of the minuend/difference row. - * @param a2 The second part of the minuend/difference row. - * @param b1 The first part of the subtrahend row. - * @param b2 The second part of the subtrahend row. - * @param m The multiplier. - */ -static void subrow(double a1[3], double a2[3], double b1[3], double b2[3], double m) -{ - a1[0] -= b1[0] * m, a1[1] -= b1[1] * m, a1[2] -= b1[2] * m; - a2[0] -= b2[0] * m, a2[1] -= b2[1] * m, a2[2] -= b2[2] * m; -} - - -/** - * Invert a matrix. - * - * @param M The matrix to invert, will be modified to an - * identity matrix, possibly with reordered rows. - * @param A The inversion of M (as input). - * @return 1 on success, 0 if the matrix is not invertible. - */ -static int invert(libclut_colour_space_conversion_matrix_t M, libclut_colour_space_conversion_matrix_t A) -{ - int r0 = 0, r1 = 1, r2 = 2, t, swapped = 0; - libclut_colour_space_conversion_matrix_t T; - - A[0][0] = A[1][1] = A[2][2] = 1; - A[0][1] = A[0][2] = A[1][0] = A[1][2] = A[2][0] = A[2][1] = 0; - - if (libclut_0__(M[r0][0])) - { - if (libclut_0__(M[r1][0])) - { - if (libclut_0__(M[r2][0])) - return 0; - t = r0, r0 = r2, r2 = t; - } - else - t = r0, r0 = r1, r1 = t; - swapped = 1; - } - - divrow(M[r0], A[r0], M[r0][0]); - subrow(M[r1], A[r1], M[r0], A[r0], M[r1][0]); - subrow(M[r2], A[r2], M[r0], A[r0], M[r2][0]); - - if (libclut_0__(M[r1][1])) - { - if (libclut_0__(M[r2][1])) - return 0; - t = r1, r1 = r2, r2 = t; - swapped = 1; - } - - divrow(M[r1], A[r1], M[r1][1]); - subrow(M[r2], A[r2], M[r1], A[r1], M[r2][1]); - - if (libclut_0__(M[r2][2])) - return 0; - - divrow(M[r2], A[r2], M[r2][2]); - - subrow(M[r1], A[r1], M[r2], A[r2], M[r1][2]); - subrow(M[r0], A[r0], M[r2], A[r2], M[r0][2]); - - subrow(M[r0], A[r0], M[r1], A[r1], M[r0][1]); - - if (swapped) - { - memcpy(T, A, sizeof(T)); - memcpy(A[0], T[r0], sizeof(*T)); - memcpy(A[1], T[r1], sizeof(*T)); - memcpy(A[2], T[r2], sizeof(*T)); - } - - return 1; -} - - -/** - * Create an RGB to CIE XYZ conversion matrix. - * - * @param cs The colour space. - * @param M The output matrix. - * @return Zero on success, -1 on error. - * - * @throws EINVAL The colour space cannot be used. - */ -static int get_conversion_matrix(const libclut_rgb_colour_space_t* cs, libclut_colour_space_conversion_matrix_t M) -{ -#define XYY_TO_XYZ(x, y, Y, Xp, Yp, Zp) \ - (libclut_0__(Y)) ? \ - (*(Xp) = *(Zp) = *(Yp) = (Y)) : \ - (*(Xp) = (x) * (Y) / (y), \ - *(Yp) = (Y), \ - *(Zp) = (1 - (x) - (y)) * (Y) / (y)) - - double Xr, Yr, Zr, Xg, Yg, Zg, Xb, Yb, Zb, Xw, Yw, Zw, Sr, Sg, Sb; - libclut_colour_space_conversion_matrix_t M2; - - XYY_TO_XYZ(cs->red_x, cs->red_y, 1, &Xr, &Yr, &Zr); - XYY_TO_XYZ(cs->green_x, cs->green_y, 1, &Xg, &Yg, &Zg); - XYY_TO_XYZ(cs->blue_x, cs->blue_y, 1, &Xb, &Yb, &Zb); - XYY_TO_XYZ(cs->white_x, cs->white_y, cs->white_Y, &Xw, &Yw, &Zw); - - M2[0][0] = Xr, M2[0][1] = Xg, M2[0][2] = Xb; - M2[1][0] = Yr, M2[1][1] = Yg, M2[1][2] = Yb; - M2[2][0] = Zr, M2[2][1] = Zg, M2[2][2] = Zb; - - if (!invert(M2, M)) - return errno = EINVAL, -1; - - Sr = M[0][0] * Xw + M[0][1] * Yw + M[0][2] * Zw; - Sg = M[1][0] * Xw + M[1][1] * Yw + M[1][2] * Zw; - Sb = M[2][0] * Xw + M[2][1] * Yw + M[2][2] * Zw; - - M[0][0] = Sr * Xr, M[0][1] = Sg * Xg, M[0][2] = Sb * Xb; - M[1][0] = Sr * Yr, M[1][1] = Sg * Yg, M[1][2] = Sb * Yb; - M[2][0] = Sr * Zr, M[2][1] = Sg * Zg, M[2][2] = Sb * Zb; - - return 0; - -#undef XYY_TO_XYZ -} - - -/** - * Create a matrix for converting values between - * two RGB colour spaces. - * - * @param from The input colour space, the Y-component is only necessary - * for the white point, `NULL` for CIE XYZ. - * @param to The output colour space, the Y-component is only necessary - * for the white point, `NULL` for CIE XYZ. - * @param M Output matrix for conversion from `from` to `to`. - * @param Minv Output matrix for conversion from `to` to `from`, may be `NULL`. - * @return Zero on success, -1 on error. - * - * @throws EINVAL The colour space cannot be used. - */ -int libclut_model_get_rgb_conversion_matrix(const libclut_rgb_colour_space_t* from, - const libclut_rgb_colour_space_t* to, - libclut_colour_space_conversion_matrix_t M, - libclut_colour_space_conversion_matrix_t Minv) -{ - libclut_colour_space_conversion_matrix_t A, B; - - if (from != NULL) - { - if (get_conversion_matrix(from, A)) - return -1; - } - else - { - A[0][0] = A[1][1] = A[2][2] = 1; - A[0][1] = A[1][0] = A[2][0] = 0; - A[0][2] = A[1][2] = A[2][1] = 0; - } - - if (to != NULL) - { - if (get_conversion_matrix(to, M)) - return -1; - if (!invert(M, B)) - return errno = EINVAL, -1; - - if (from != NULL) - { - M[0][0] = B[0][0] * A[0][0] + B[0][1] * A[1][0] + B[0][2] * A[2][0]; - M[0][1] = B[0][0] * A[0][1] + B[0][1] * A[1][1] + B[0][2] * A[2][1]; - M[0][2] = B[0][0] * A[0][2] + B[0][1] * A[1][2] + B[0][2] * A[2][2]; - - M[1][0] = B[1][0] * A[0][0] + B[1][1] * A[1][0] + B[1][2] * A[2][0]; - M[1][1] = B[1][0] * A[0][1] + B[1][1] * A[1][1] + B[1][2] * A[2][1]; - M[1][2] = B[1][0] * A[0][2] + B[1][1] * A[1][2] + B[1][2] * A[2][2]; - - M[2][0] = B[2][0] * A[0][0] + B[2][1] * A[1][0] + B[2][2] * A[2][0]; - M[2][1] = B[2][0] * A[0][1] + B[2][1] * A[1][1] + B[2][2] * A[2][1]; - M[2][2] = B[2][0] * A[0][2] + B[2][1] * A[1][2] + B[2][2] * A[2][2]; - } - else - memcpy(M, B, sizeof(B)); - } - else - memcpy(M, A, sizeof(A)); - - if (Minv != NULL) - { - memcpy(A, M, sizeof(A)); - if (!invert(A, Minv)) - return errno = EINVAL, -1; - } - - return 0; -} - - -/** - * Convert an RGB colour into another RGB colour space. - * - * Both RGB colour spaces must have same gamma functions as sRGB. - * - * @param r The red component of the colour to convert. - * @param g The green component of the colour to convert. - * @param b The blue component of the colour to convert. - * @param M Conversion matrix, create with `libclut_model_get_rgb_conversion_matrix`. - * @param out_r Output parameter for the new red component. - * @param out_g Output parameter for the new green component. - * @param out_b Output parameter for the new blue component. - */ -void (libclut_model_convert_rgb)(double r, double g, double b, libclut_colour_space_conversion_matrix_t M, - double* out_r, double* out_g, double* out_b) -{ - libclut_model_convert_rgb(r, g, b, M, out_r, out_g, out_b); -} - - -/** - * Convert an RGB colour of a custom RGB colour space to CIE XYZ. - * - * The RGB colour space must have same gamma functions as sRGB. - * - * @param r The red component. - * @param g The green component. - * @param b The blue component. - * @param M Conversion matrix, create with `libclut_model_get_rgb_conversion_matrix`. - * @param x Output parameter for the X component. - * @param y Output parameter for the Y component. - * @param z Output parameter for the Z component. - */ -void (libclut_model_rgb_to_ciexyz)(double r, double g, double b, libclut_colour_space_conversion_matrix_t M, - double* x, double* y, double* z) -{ - libclut_model_rgb_to_ciexyz(r, g, b, M, x, y, z); -} - - -/** - * Convert a CIE XYZ colour to a custom RGB colour space. - * - * The RGB colour space must have same gamma functions as sRGB. - * - * @param x The X component. - * @param y The Y component. - * @param z The Z component. - * @param M Conversion matrix, create with `libclut_model_get_rgb_conversion_matrix`. - * @param r Output parameter for the red component. - * @param g Output parameter for the green component - * @param b Output parameter for the blue component. - */ -void (libclut_model_ciexyz_to_rgb)(double x, double y, double z, libclut_colour_space_conversion_matrix_t M, - double* r, double* g, double* b) -{ - libclut_model_ciexyz_to_rgb(x, y, z, M, r, g, b); -} - diff --git a/src/libclut.h b/src/libclut.h deleted file mode 100644 index 6daec11..0000000 --- a/src/libclut.h +++ /dev/null @@ -1,2704 +0,0 @@ -/** - * Copyright © 2016 Mattias Andrée <maandree@member.fsf.org> - * - * 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 LIBCLUT_H -#define LIBCLUT_H - -#include <stddef.h> -#include <string.h> -#include <math.h> - - - -/* Not documented, may be removed or modified in the future. */ -#define LIBCLUT_ILLUMINANT_A .white_x = 0.44757, .white_y = 0.40745, .white_Y = 1 -#define LIBCLUT_ILLUMINANT_B .white_x = 0.34842, .white_y = 0.35161, .white_Y = 1 -#define LIBCLUT_ILLUMINANT_C .white_x = 0.31006, .white_y = 0.31616, .white_Y = 1 -#define LIBCLUT_ILLUMINANT_D50 .white_x = 0.34567, .white_y = 0.35850, .white_Y = 1 -#define LIBCLUT_ILLUMINANT_D55 .white_x = 0.33242, .white_y = 0.34743, .white_Y = 1 -#define LIBCLUT_ILLUMINANT_D65 .white_x = 0.31271, .white_y = 0.32902, .white_Y = 1 -#define LIBCLUT_ILLUMINANT_D75 .white_x = 0.29902, .white_y = 0.31485, .white_Y = 1 -#define LIBCLUT_ILLUMINANT_E .white_x = 1. / 3, .white_y = 1. / 3, .white_Y = 1 -#define LIBCLUT_ILLUMINANT_F1 .white_x = 0.31310, .white_y = 0.33727, .white_Y = 1 -#define LIBCLUT_ILLUMINANT_F2 .white_x = 0.37208, .white_y = 0.37529, .white_Y = 1 -#define LIBCLUT_ILLUMINANT_F3 .white_x = 0.40910, .white_y = 0.39430, .white_Y = 1 -#define LIBCLUT_ILLUMINANT_F4 .white_x = 0.44018, .white_y = 0.40329, .white_Y = 1 -#define LIBCLUT_ILLUMINANT_F5 .white_x = 0.31379, .white_y = 0.34531, .white_Y = 1 -#define LIBCLUT_ILLUMINANT_F6 .white_x = 0.37790, .white_y = 0.38835, .white_Y = 1 -#define LIBCLUT_ILLUMINANT_F7 .white_x = 0.31292, .white_y = 0.32933, .white_Y = 1 -#define LIBCLUT_ILLUMINANT_F8 .white_x = 0.34588, .white_y = 0.35875, .white_Y = 1 -#define LIBCLUT_ILLUMINANT_F9 .white_x = 0.37417, .white_y = 0.37281, .white_Y = 1 -#define LIBCLUT_ILLUMINANT_F10 .white_x = 0.34609, .white_y = 0.35986, .white_Y = 1 -#define LIBCLUT_ILLUMINANT_F11 .white_x = 0.38052, .white_y = 0.37713, .white_Y = 1 -#define LIBCLUT_ILLUMINANT_F12 .white_x = 0.43695, .white_y = 0.40441, .white_Y = 1 - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the sRGB colour space. - * - * sRGB does not use a regular gamma function, but rather two different - * functions. `libclut_model_linear_to_standard1` and - * and `libclut_model_standard_to_linear1` can be used so to convert - * between sRGB and linear sRGB. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_SRGB_INITIALISER \ - { \ - .red_x = 0.6400, .red_y = 0.3300, .red_Y = 0.212656, \ - .green_x = 0.3000, .green_y = 0.6000, .green_Y = 0.715158, \ - .blue_x = 0.1500, .blue_y = 0.0600, .blue_Y = 0.072186, \ - LIBCLUT_ILLUMINANT_D65 \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the Adobe RGB (1998) colour space. - * - * This colour space's gamma is 2.2. It cannot be used with - * RGB colour space conversion unless the values are tranlated into - * using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_ADOBE_RGB_INITIALISER \ - { \ - .red_x = 0.6400, .red_y = 0.3300, .red_Y = 0.297361, \ - .green_x = 0.2100, .green_y = 0.7100, .green_Y = 0.627355, \ - .blue_x = 0.1500, .blue_y = 0.0600, .blue_Y = 0.075285, \ - LIBCLUT_ILLUMINANT_D65 \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the Apple RGB colour space. - * - * This colour space's gamma is 1.8. It cannot be used with - * RGB colour space conversion unless the values are tranlated into - * using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_APPLE_RGB_INITIALISER \ - { \ - .red_x = 0.6250, .red_y = 0.3400, .red_Y = 0.244634, \ - .green_x = 0.2800, .green_y = 0.5950, .green_Y = 0.672034, \ - .blue_x = 0.1550, .blue_y = 0.0700, .blue_Y = 0.083332, \ - LIBCLUT_ILLUMINANT_D65 \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the Best RGB colour space. - * - * This colour space's gamma is 2.2. It cannot be used with - * RGB colour space conversion unless the values are tranlated into - * using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_BEST_RGB_INITIALISER \ - { \ - .red_x = 0.7347, .red_y = 0.2653, .red_Y = 0.228457, \ - .green_x = 0.2150, .green_y = 0.7750, .green_Y = 0.737352, \ - .blue_x = 0.1300, .blue_y = 0.0350, .blue_Y = 0.034191, \ - LIBCLUT_ILLUMINANT_D50 \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the Beta RGB colour space. - * - * This colour space's gamma is 2.2. It cannot be used with - * RGB colour space conversion unless the values are tranlated into - * using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_BETA_RGB_INITIALISER \ - { \ - .red_x = 0.6888, .red_y = 0.3112, .red_Y = 0.303273, \ - .green_x = 0.1986, .green_y = 0.7551, .green_Y = 0.663786, \ - .blue_x = 0.1265, .blue_y = 0.0352, .blue_Y = 0.032941, \ - LIBCLUT_ILLUMINANT_D50 \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the Bruce RGB colour space. - * - * This colour space's gamma is 2.2. It cannot be used with - * RGB colour space conversion unless the values are tranlated into - * using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_BRUCE_RGB_INITIALISER \ - { \ - .red_x = 0.6400, .red_y = 0.3300, .red_Y = 0.240995, \ - .green_x = 0.2800, .green_y = 0.6500, .green_Y = 0.683554, \ - .blue_x = 0.1500, .blue_y = 0.0600, .blue_Y = 0.075452, \ - LIBCLUT_ILLUMINANT_D65 \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the CIE RGB colour space. - * - * This colour space's gamma is 2.2. It cannot be used with - * RGB colour space conversion unless the values are tranlated into - * using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_CIE_RGB_INITIALISER \ - { \ - .red_x = 0.7350, .red_y = 0.2650, .red_Y = 0.176204, \ - .green_x = 0.2740, .green_y = 0.7170, .green_Y = 0.812985, \ - .blue_x = 0.1670, .blue_y = 0.0090, .blue_Y = 0.010811, \ - LIBCLUT_ILLUMINANT_E \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the ColorMatch RGB colour space. - * - * This colour space's gamma is 1.8. It cannot be used with - * RGB colour space conversion unless the values are tranlated into - * using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_COLORMATCH_RGB_INITIALISER \ - { \ - .red_x = 0.6300, .red_y = 0.3400, .red_Y = 0.274884, \ - .green_x = 0.2950, .green_y = 0.6050, .green_Y = 0.658132, \ - .blue_x = 0.1500, .blue_y = 0.0750, .blue_Y = 0.066985, \ - LIBCLUT_ILLUMINANT_D50 \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the DCI-P3 D65 colour space. - * - * This colour space's gamma is 2.6. It cannot be used with - * RGB colour space conversion unless the values are tranlated into - * using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_DCI_P3_D65_INITIALISER \ - { \ - .red_x = 0.680, .red_y = 0.320, .red_Y = 0.22897344, \ - .green_x = 0.265, .green_y = 0.690, .green_Y = 0.69175166, \ - .blue_x = 0.150, .blue_y = 0.060, .blue_Y = 0.07927490, \ - LIBCLUT_ILLUMINANT_D50 \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the DCI-P3 Theater colour space. - * - * This colour space's gamma is 2.6. It cannot be used with - * RGB colour space conversion unless the values are tranlated into - * using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_DCI_P3_THEATER_INITIALISER \ - { \ - .red_x = 0.680, .red_y = 0.320, .red_Y = 0.20949168, \ - .green_x = 0.265, .green_y = 0.690, .green_Y = 0.72159525, \ - .blue_x = 0.150, .blue_y = 0.060, .blue_Y = 0.06891307, \ - .white_x = 0.314, .white_y = 0.351, .white_Y = 1 \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the Don RGB 4 colour space. - * - * This colour space's gamma is 2.2. It cannot be used with - * RGB colour space conversion unless the values are tranlated into - * using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_DON_RGB_4_INITIALISER \ - { \ - .red_x = 0.6960, .red_y = 0.3000, .red_Y = 0.278350, \ - .green_x = 0.2150, .green_y = 0.7650, .green_Y = 0.687970, \ - .blue_x = 0.1300, .blue_y = 0.0350, .blue_Y = 0.033680, \ - LIBCLUT_ILLUMINANT_D50 \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the ECI RGB v2 colour space. - * - * This colour space's used the L* gamma function. It cannot - * be used with RGB colour space conversion unless the values are - * tranlated into using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_ECI_RGB_V2_INITIALISER \ - { \ - .red_x = 0.6700, .red_y = 0.3300, .red_Y = 0.320250, \ - .green_x = 0.2100, .green_y = 0.7100, .green_Y = 0.602071, \ - .blue_x = 0.1400, .blue_y = 0.0800, .blue_Y = 0.077679, \ - LIBCLUT_ILLUMINANT_D50 \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the Ekta Space PS5 colour space. - * - * This colour space's gamma is 2.2. It cannot be used with - * RGB colour space conversion unless the values are tranlated into - * using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_EKTA_SPACE_PS5_INITIALISER \ - { \ - .red_x = 0.6950, .red_y = 0.3050, .red_Y = 0.260629, \ - .green_x = 0.2600, .green_y = 0.7000, .green_Y = 0.734946, \ - .blue_x = 0.1100, .blue_y = 0.0050, .blue_Y = 0.004425, \ - LIBCLUT_ILLUMINANT_D50 \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the ITU-R Recommendation BT.601 (ITU-R BT.601), 625 line colour - * space. - * - * This colour space uses a custom gamma function. It cannot be used - * with RGB colour space conversion unless the values are tranlated - * into using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_ITU_R_BT_601_625_LINE_INITIALISER \ - { \ - .red_x = 0.640, .red_y = 0.330, .red_Y = 0.2220023, \ - .green_x = 0.290, .green_y = 0.600, .green_Y = 0.7066689, \ - .blue_x = 0.150, .blue_y = 0.060, .blue_Y = 0.0713288, \ - LIBCLUT_ILLUMINANT_D65 \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the ITU-R Recommendation BT.601 (ITU-R BT.601), 525 line colour - * space. - * - * This colour space uses a custom gamma function. It cannot be used - * with RGB colour space conversion unless the values are tranlated - * into using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_ITU_R_BT_601_525_LINE_INITIALISER \ - { \ - .red_x = 0.630, .red_y = 0.340, .red_Y = 0.2220023, \ - .green_x = 0.310, .green_y = 0.595, .green_Y = 0.7066689, \ - .blue_x = 0.155, .blue_y = 0.070, .blue_Y = 0.0713288, \ - LIBCLUT_ILLUMINANT_D65 \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the ITU-R Recommendation BT.709 (ITU-R BT.709) colour space. - * - * This colour space's gamma is 2._. It cannot be used with - * RGB colour space conversion unless the values are tranlated into - * using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_ITU_R_BT_709_INITIALISER \ - { \ - .red_x = 0.6400, .red_y = 0.3300, .red_Y = 0.212656, \ - .green_x = 0.3000, .green_y = 0.6000, .green_Y = 0.715158, \ - .blue_x = 0.1500, .blue_y = 0.0600, .blue_Y = 0.072186, \ - LIBCLUT_ILLUMINANT_D65 \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the ITU-R Recommendation BT.2020 (ITU-R BT.2020) colour space. - * - * This colour space uses a custom gamma function. It cannot be used - * with RGB colour space conversion unless the values are tranlated - * into using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_ITU_R_BT_2020_INITIALISER \ - { \ - .red_x = 0.7080, .red_y = 0.2920, .red_Y = 0.2627296, \ - .green_x = 0.1700, .green_y = 0.7970, .green_Y = 0.6767483, \ - .blue_x = 0.1310, .blue_y = 0.0460, .blue_Y = 0.0605221, \ - LIBCLUT_ILLUMINANT_D65 \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the ITU-R Recommendation BT.2100 (ITU-R BT.2100) colour space. - * - * This colour space uses a custom gamma function. It cannot be used - * with RGB colour space conversion unless the values are tranlated - * into using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_ITU_R_BT_2100_INITIALISER \ - { \ - .red_x = 0.7080, .red_y = 0.2920, .red_Y = 0.2627296, \ - .green_x = 0.1700, .green_y = 0.7970, .green_Y = 0.6767483, \ - .blue_x = 0.1310, .blue_y = 0.0460, .blue_Y = 0.0605221, \ - LIBCLUT_ILLUMINANT_D65 \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the Lightroom RGB colour space. - * - * This colour space's gamma is 1 (linear). It cannot be used with - * RGB colour space conversion unless the values are tranlated into - * using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_LIGHTROOM_RGB_INITIALISER \ - { \ - .red_x = 0.7347, .red_y = 0.2653, .red_Y = 0.288040, \ - .green_x = 0.1596, .green_y = 0.8404, .green_Y = 0.711874, \ - .blue_x = 0.0366, .blue_y = 0.0001, .blue_Y = 0.000086, \ - LIBCLUT_ILLUMINANT_D50 \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the NTSC RGB colour space. - * - * This colour space's gamma is 2.2. It cannot be used with - * RGB colour space conversion unless the values are tranlated into - * using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_NTSC_RGB_INITIALISER \ - { \ - .red_x = 0.6700, .red_y = 0.3300, .red_Y = 0.298839, \ - .green_x = 0.2100, .green_y = 0.7100, .green_Y = 0.586811, \ - .blue_x = 0.1400, .blue_y = 0.0800, .blue_Y = 0.114350, \ - LIBCLUT_ILLUMINANT_C \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the PAL/SECAM RGB colour space. - * - * This colour space's gamma is 2.2. It cannot be used with - * RGB colour space conversion unless the values are tranlated into - * using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_PAL_SECAM_RGB_INITIALISER \ - { \ - .red_x = 0.6400, .red_y = 0.3300, .red_Y = 0.222021, \ - .green_x = 0.2900, .green_y = 0.6000, .green_Y = 0.706645, \ - .blue_x = 0.1500, .blue_y = 0.0600, .blue_Y = 0.071334, \ - LIBCLUT_ILLUMINANT_D65 \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the ProPhoto RGB colour space. - * - * This colour space's gamma is 1.8. It cannot be used with - * RGB colour space conversion unless the values are tranlated into - * using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_PROPHOTO_RGB_INITIALISER \ - { \ - .red_x = 0.7347, .red_y = 0.2653, .red_Y = 0.288040, \ - .green_x = 0.1596, .green_y = 0.8404, .green_Y = 0.711874, \ - .blue_x = 0.0366, .blue_y = 0.0001, .blue_Y = 0.000086, \ - LIBCLUT_ILLUMINANT_D50 \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the SMPTE-C RGB colour space. - * - * This colour space's gamma is 2.2. It cannot be used with - * RGB colour space conversion unless the values are tranlated into - * using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_SMPTE_C_RGB_INITIALISER \ - { \ - .red_x = 0.6300, .red_y = 0.3400, .red_Y = 0.212395, \ - .green_x = 0.3100, .green_y = 0.5950, .green_Y = 0.701049, \ - .blue_x = 0.1550, .blue_y = 0.0700, .blue_Y = 0.086556, \ - LIBCLUT_ILLUMINANT_D65 \ - } - -/** - * Initialiser for `struct libclut_rgb_colour_space` with the values - * of the Wide Gamut RGB colour space. - * - * This colour space's gamma is 2.2. It cannot be used with - * RGB colour space conversion unless the values are tranlated into - * using the sRGB gamma function. - */ -#define LIBCLUT_RGB_COLOUR_SPACE_WIDE_GAMUT_RGB_INITIALISER \ - { \ - .red_x = 0.7350, .red_y = 0.2650, .red_Y = 0.258187, \ - .green_x = 0.1150, .green_y = 0.8260, .green_Y = 0.724938, \ - .blue_x = 0.1570, .blue_y = 0.0180, .blue_Y = 0.016875, \ - LIBCLUT_ILLUMINANT_D50 \ - } - -/* - * TODO gamma functions: - * https://en.wikipedia.org/wiki/Rec._2020#Transfer_characteristics - * http://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.2100-0-201607-I!!PDF-E.pdf - * https://en.wikipedia.org/wiki/Rec._601 - */ - - - -/** - * RGB colour space structure. - */ -typedef struct libclut_rgb_colour_space -{ - /** - * The x-component of the red colour's xyY value. - */ - double red_x; - - /** - * The y-component of the red colour's xyY value. - */ - double red_y; - - /** - * The Y-component of the red colour's xyY value. - */ - double red_Y; - - /** - * The x-component of the green colour's xyY value. - */ - double green_x; - - /** - * The y-component of the green colour's xyY value. - */ - double green_y; - - /** - * The Y-component of the green colour's xyY value. - */ - double green_Y; - - /** - * The x-component of the blue colour's xyY value. - */ - double blue_x; - - /** - * The y-component of the blue colour's xyY value. - */ - double blue_y; - - /** - * The Y-component of the blue colour's xyY value. - */ - double blue_Y; - - /** - * The x-component of the white point's xyY value. - */ - double white_x; - - /** - * The y-component of the white point's xyY value. - */ - double white_y; - - /** - * The Y-component of the white point's xyY value. - */ - double white_Y; -} libclut_rgb_colour_space_t; - - - -/** - * Matrix date-type for colour space conversion. - */ -typedef double libclut_colour_space_conversion_matrix_t[3][3]; - - - -/* This is to avoid warnings about comparing double, These are only - * used when it is safe, for example to test whether optimisations - * are possible. { */ -#if defined(__GNUC__) || defined(__clang__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wfloat-equal" -#endif -static inline int libclut_eq__(double a, double b) { return a == b; } -static inline int libclut_1__(double x) { return libclut_eq__(x, 1); } -static inline int libclut_0__(double x) { return libclut_eq__(x, 0); } -#if defined(__GNUC__) || defined(__clang__) -# pragma GCC diagnostic pop -#endif -/* } */ - - -#if defined(__clang__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wdocumentation" -#endif - - - -/** - * Apply contrast correction on the colour curves using sRGB. - * - * In this context, contrast is a measure of difference between - * the whitepoint and blackpoint, if the difference is 0 than - * they are both grey. - * - * None of the parameter may have side-effects. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param r The contrast parameter for the red curve. - * @param g The contrast parameter for the green curve. - * @param b The contrast parameter for the blue curve. - */ -#define libclut_rgb_contrast(clut, max, type, r, g, b) \ - do \ - { \ - const double h__ = (double)5 / 10; \ - if (!libclut_1__(r)) \ - libclut__(clut, red, type, (LIBCLUT_VALUE - (max) * h__) * (r) + (max) * h__); \ - if (!libclut_1__(g)) \ - libclut__(clut, green, type, (LIBCLUT_VALUE - (max) * h__) * (g) + (max) * h__); \ - if (!libclut_1__(b)) \ - libclut__(clut, blue, type, (LIBCLUT_VALUE - (max) * h__) * (b) + (max) * h__); \ - } \ - while (0) - - -/** - * Apply contrast correction on the colour curves using CIE xyY. - * - * In this context, contrast is a measure of difference between - * the whitepoint and blackpoint, if the difference is 0 than - * they are both grey. - * - * None of the parameter may have side-effects. - * - * Requires linking with '-lclut'. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param r The contrast parameter for the red curve. - * @param g The contrast parameter for the green curve. - * @param b The contrast parameter for the blue curve. - */ -#define libclut_cie_contrast(clut, max, type, r, g, b) \ - do \ - { \ - const double h__ = (double)5 / 10; \ - libclut_cie__(clut, max, type, libclut_eq__((r), (g)) && libclut_eq__((g), (b)), \ - !libclut_1__(r), !libclut_1__(g), !libclut_1__(b), \ - (Y__ - h__) * (r) + h__, (Y__ - h__) * (g) + h__, (Y__ - h__) * (b) + h__); \ - } \ - while (0) - - -/** - * Apply brightness correction on the colour curves using sRGB. - * - * In this context, brightness is a measure of the whiteness of the whitepoint. - * - * None of the parameter may have side-effects. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param r The brightness parameter for the red curve. - * @param g The brightness parameter for the green curve. - * @param b The brightness parameter for the blue curve. - */ -#define libclut_rgb_brightness(clut, max, type, r, g, b) \ - do \ - { \ - if (!libclut_1__(r)) libclut__(clut, red, type, LIBCLUT_VALUE * (r)); \ - if (!libclut_1__(g)) libclut__(clut, green, type, LIBCLUT_VALUE * (g)); \ - if (!libclut_1__(b)) libclut__(clut, blue, type, LIBCLUT_VALUE * (b)); \ - } \ - while (0) - - -/** - * Apply brightness correction on the colour curves using CIE xyY. - * - * In this context, brightness is a measure of the whiteness of the whitepoint. - * - * None of the parameter may have side-effects. - * - * Requires linking with '-lclut'. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param r The brightness parameter for the red curve. - * @param g The brightness parameter for the green curve. - * @param b The brightness parameter for the blue curve. - */ -#define libclut_cie_brightness(clut, max, type, r, g, b) \ - libclut_cie__(clut, max, type, libclut_eq__((r), (g)) && libclut_eq__((g), (b)), \ - !libclut_1__(r), !libclut_1__(g), !libclut_1__(b), \ - Y__ * (r), Y__ * (g), Y__ * (b)) - - -/** - * Convert the curves from formatted in standard RGB to linear sRGB. - * - * None of the parameter may have side-effects. - * - * Requires linking with '-lclut', or '-lm' if - * `libclut_model_standard_to_linear1` is not undefined. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param r Whether to convert the red colour curve. - * @param g Whether to convert the green colour curve. - * @param b Whether to convert the blue colour curve. - */ -#define libclut_linearise(clut, max, type, r, g, b) \ - do \ - { \ - double m__ = (double)(max); \ - if (r) \ - libclut__(clut, red, type, m__ * libclut_model_standard_to_linear1(LIBCLUT_VALUE / m__)); \ - if (g) \ - libclut__(clut, green, type, m__ * libclut_model_standard_to_linear1(LIBCLUT_VALUE / m__)); \ - if (b) \ - libclut__(clut, blue, type, m__ * libclut_model_standard_to_linear1(LIBCLUT_VALUE / m__)); \ - } \ - while (0) - - -/** - * Convert the curves from formatted in linear sRGB to standard RGB. - * - * None of the parameter may have side-effects. - * - * Requires linking with '-lclut', or '-lm' if - * `libclut_model_linear_to_standard1` is not undefined. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param r Whether to convert the red colour curve. - * @param g Whether to convert the green colour curve. - * @param b Whether to convert the blue colour curve. - */ -#define libclut_standardise(clut, max, type, r, g, b) \ - do \ - { \ - double m__ = (double)(max); \ - if (r) \ - libclut__(clut, red, type, m__ * libclut_model_linear_to_standard1(LIBCLUT_VALUE / m__)); \ - if (g) \ - libclut__(clut, green, type, m__ * libclut_model_linear_to_standard1(LIBCLUT_VALUE / m__)); \ - if (b) \ - libclut__(clut, blue, type, m__ * libclut_model_linear_to_standard1(LIBCLUT_VALUE / m__)); \ - } \ - while (0) - - -/** - * Convert the curves between two RGB colour spaces. - * - * Both RGB colour spaces must have same gamma functions as sRGB. - * - * Requires that `clut->red_size`, `clut->green_size` - * and `clut->blue_size` are equal. - * - * None of the parameter may have side-effects. - * - * Requires linking with '-lclut', or '-lm' if - * `libclut_model_linear_to_standard1`, - * `libclut_model_standard_to_linear1`, or - * `libclut_model_convert_rgb` is not undefined. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param m Conversion matrix. Can be created with - * `libclut_model_get_rgb_conversion_matrix`. - * @param trunc Truncate values that are out of gamut. - */ -#define libclut_convert_rgb_inplace(clut, max, type, m, trunc) \ - do \ - { \ - double m__ = (double)(max), r__, g__, b__; \ - size_t i__, n__ = (clut)->red_size; \ - for (i__ = 0; i__ < n__; i__++) \ - { \ - r__ = (clut)->red[i__] / m__; \ - g__ = (clut)->green[i__] / m__; \ - b__ = (clut)->blue[i__] / m__; \ - libclut_model_convert_rgb(r__, g__, b__, m, &r__, &g__, &b__); \ - r__ *= m__; \ - g__ *= m__; \ - b__ *= m__; \ - if (trunc) \ - { \ - if (r__ < 0) \ - r__ = 0; \ - else if (r__ > m__) \ - r__ = m__; \ - if (g__ < 0) \ - g__ = 0; \ - else if (g__ > m__) \ - g__ = m__; \ - if (b__ < 0) \ - b__ = 0; \ - else if (b__ > m__) \ - b__ = m__; \ - } \ - (clut)->red[i__] = (type)r__; \ - (clut)->green[i__] = (type)g__; \ - (clut)->blue[i__] = (type)b__; \ - } \ - } \ - while (0) - - -/** - * Convert the curves between two RGB colour spaces. - * - * Both RGB colour spaces must have same gamma functions as sRGB. - * - * None of the parameter may have side-effects. - * - * Requires linking with '-lclut' if - * `libclut_model_linear_to_standard1`, - * `libclut_model_standard_to_linear1`, or - * `libclut_model_convert_rgb` is not undefined. - * Always requires linking with '-lm'. - * - * @param clut Pointer to the input gamma ramps, must have the - * arrays `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param m Conversion matrix. Can be created with - * `libclut_model_get_rgb_conversion_matrix`. - * @param trunc Truncate values that are out of gamut. - * @param out Pointer to the output gamma ramps, must have the - * arrays `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - */ -#define libclut_convert_rgb(clut, max, type, m, trunc, out) \ - do \ - { \ - double m__ = (double)(max), r__, g__, b__, x__, y__; \ - size_t rn__ = (clut)->red_size; \ - size_t gn__ = (clut)->green_size; \ - size_t bn__ = (clut)->blue_size; \ - double w__; \ - size_t i__, j__, jj__; \ - for (i__ = 0; i__ < rn__; i__++) \ - { \ - w__ = (double)i__ * gn__ / rn__; \ - j__ = (size_t)w__; \ - jj__ = j__ == gn__ ? j__ : (j__ + 1); \ - w__ = fmod(j__, (double)1); \ - x__ = (clut)->green[j__] / m__; \ - y__ = (clut)->green[jj__] / m__; \ - x__ = libclut_model_standard_to_linear1(x__); \ - y__ = libclut_model_standard_to_linear1(y__); \ - g__ = x__ * (1 - w__) + y__ * w__; \ - \ - w__ = (double)i__ * bn__ / rn__; \ - j__ = (size_t)w__; \ - jj__ = j__ == bn__ ? j__ : (j__ + 1); \ - w__ = fmod(j__, (double)1); \ - x__ = (clut)->blue[j__] / m__; \ - y__ = (clut)->blue[jj__] / m__; \ - x__ = libclut_model_standard_to_linear1(x__); \ - y__ = libclut_model_standard_to_linear1(y__); \ - b__ = x__ * (1 - w__) + y__ * w__; \ - \ - r__ = (M)[0][0] * r__ + (M)[0][1] * g__ + (M)[0][2] * b__; \ - r__ = libclut_model_linear_to_standard1(r__); \ - r__ *= m__; \ - if (trunc) \ - { \ - if (r__ < 0) \ - r__ = 0; \ - else if (r__ > m__) \ - r__ = m__; \ - } \ - (out)->red[i__] = (type)r__; \ - } \ - for (i__ = 0; i__ < gn__; i__++) \ - { \ - w__ = (double)i__ * rn__ / gn__; \ - j__ = (size_t)w__; \ - jj__ = j__ == rn__ ? j__ : (j__ + 1); \ - w__ = fmod(j__, (double)1); \ - x__ = (clut)->red[j__] / m__; \ - y__ = (clut)->red[jj__] / m__; \ - x__ = libclut_model_standard_to_linear1(x__); \ - y__ = libclut_model_standard_to_linear1(y__); \ - r__ = x__ * (1 - w__) + y__ * w__; \ - \ - w__ = (double)i__ * bn__ / gn__; \ - j__ = (size_t)w__; \ - jj__ = j__ == bn__ ? j__ : (j__ + 1); \ - w__ = fmod(j__, (double)1); \ - x__ = (clut)->blue[j__] / m__; \ - y__ = (clut)->blue[jj__] / m__; \ - x__ = libclut_model_standard_to_linear1(x__); \ - y__ = libclut_model_standard_to_linear1(y__); \ - b__ = x__ * (1 - w__) + y__ * w__; \ - \ - g__ = (M)[1][0] * r__ + (M)[0][1] * g__ + (M)[1][2] * b__; \ - g__ = libclut_model_linear_to_standard1(g__); \ - g__ *= m__; \ - if (trunc) \ - { \ - if (g__ < 0) \ - g__ = 0; \ - else if (g__ > m__) \ - g__ = m__; \ - } \ - (out)->green[i__] = (type)g__; \ - } \ - for (i__ = 0; i__ < bn__; i__++) \ - { \ - w__ = (double)i__ * rn__ / bn__; \ - j__ = (size_t)w__; \ - jj__ = j__ == rn__ ? j__ : (j__ + 1); \ - w__ = fmod(j__, (double)1); \ - x__ = (clut)->red[j__] / m__; \ - y__ = (clut)->red[jj__] / m__; \ - x__ = libclut_model_standard_to_linear1(x__); \ - y__ = libclut_model_standard_to_linear1(y__); \ - r__ = x__ * (1 - w__) + y__ * w__; \ - \ - w__ = (double)i__ * gn__ / bn__; \ - j__ = (size_t)w__; \ - jj__ = j__ == gn__ ? j__ : (j__ + 1); \ - w__ = fmod(j__, (double)1); \ - x__ = (clut)->green[j__] / m__; \ - y__ = (clut)->green[jj__] / m__; \ - x__ = libclut_model_standard_to_linear1(x__); \ - y__ = libclut_model_standard_to_linear1(y__); \ - g__ = x__ * (1 - w__) + y__ * w__; \ - \ - b__ = (M)[2][0] * r__ + (M)[2][1] * g__ + (M)[2][2] * b__; \ - b__ = libclut_model_linear_to_standard1(b__); \ - b__ *= m__; \ - if (trunc) \ - { \ - if (b__ < 0) \ - b__ = 0; \ - else if (b__ > m__) \ - b__ = m__; \ - } \ - (out)->blue[i__] = (type)b__; \ - } \ - } \ - while (0) - - -/** - * Apply gamma correction on the colour curves. - * - * None of the parameter may have side-effects. - * - * Requires linking with '-lm'. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param r The gamma parameter the red colour curve. - * @param g The gamma parameter the green colour curve. - * @param b The gamma parameter the blue colour curve. - */ -#define libclut_gamma(clut, max, type, r, g, b) \ - do \ - { \ - double m__ = (double)(max); \ - if (!libclut_1__(r)) \ - libclut__(clut, red, type, m__ * pow(LIBCLUT_VALUE / m__, 1 / (double)(r))); \ - if (!libclut_1__(g)) \ - libclut__(clut, green, type, m__ * pow(LIBCLUT_VALUE / m__, 1 / (double)(g))); \ - if (!libclut_1__(b)) \ - libclut__(clut, blue, type, m__ * pow(LIBCLUT_VALUE / m__, 1 / (double)(b))); \ - } \ - while (0) - - -/** - * Reverse the colour curves (negative image with gamma preservation.) - * - * None of the parameter may have side-effects. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * This parameter is not used, it is just a dummy, to unify - * the API with the other functions. - * @param type The data type used for each stop in the ramps. - * @param r Whether to invert the red colour curve. - * @param g Whether to invert the green colour curve. - * @param b Whether to invert the blue colour curve. - */ -#define libclut_negative(clut, max, type, r, g, b) \ - do \ - { \ - size_t i__, n__; \ - type t__; \ - if (r) \ - for (i__ = 0, n__ = (clut)->red_size; i__ < (n__ >> 1); i__++) \ - { \ - t__ = (clut)->red[i__]; \ - (clut)->red[i__] = (clut)->red[n__ - i__ - 1]; \ - (clut)->red[n__ - i__ - 1] = t__; \ - } \ - if (g) \ - for (i__ = 0, n__ = (clut)->green_size; i__ < (n__ >> 1); i__++) \ - { \ - t__ = (clut)->green[i__]; \ - (clut)->green[i__] = (clut)->green[n__ - i__ - 1]; \ - (clut)->green[n__ - i__ - 1] = t__; \ - } \ - if (b) \ - for (i__ = 0, n__ = (clut)->blue_size; i__ < (n__ >> 1); i__++) \ - { \ - t__ = (clut)->blue[i__]; \ - (clut)->blue[i__] = (clut)->blue[n__ - i__ - 1]; \ - (clut)->blue[n__ - i__ - 1] = t__; \ - } \ - } \ - while (0) - - -/** - * Invert the colour curves (negative image with gamma invertion), using sRGB. - * - * None of the parameter may have side-effects. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param r Whether to invert the red colour curve. - * @param g Whether to invert the green colour curve. - * @param b Whether to invert the blue colour curve. - */ -#define libclut_rgb_invert(clut, max, type, r, g, b) \ - do \ - { \ - if (r) libclut__(clut, red, type, (max) - LIBCLUT_VALUE); \ - if (g) libclut__(clut, green, type, (max) - LIBCLUT_VALUE); \ - if (b) libclut__(clut, blue, type, (max) - LIBCLUT_VALUE); \ - } \ - while (0) - - -/** - * Invert the colour curves (negative image with gamma invertion), using CIE xyY. - * - * None of the parameter may have side-effects. - * - * Requires linking with '-lclut'. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param r Whether to invert the red colour curve. - * @param g Whether to invert the green colour curve. - * @param b Whether to invert the blue colour curve. - */ -#define libclut_cie_invert(clut, max, type, r, g, b) \ - libclut_cie__(clut, max, type, (r) && (g) && (b), r, g, b, 1 - Y__, 1 - Y__, 1 - Y__) - - -/** - * Apply S-curve correction on the colour curves. - * This is intended for fine tuning LCD monitors, - * 4.5 is good value start start testing at. - * You would probably like to use rgb_limits before - * this to adjust the blackpoint as that is the - * only way to adjust the blackpoint on many LCD - * monitors. - * - * None of the parameter may have side-effects. - * - * Requires linking with '-lm'. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param rp Pointer to the sigmoid parameter for the red curve. `NULL` for no adjustment. - * @param gp Pointer to the sigmoid parameter for the green curve. `NULL` for no adjustment. - * @param bp Pointer to the sigmoid parameter for the blue curve. `NULL` for no adjustment. - */ -#define libclut_sigmoid(clut, max, type, rp, gp, bp) \ - do \ - { \ - double *gcc_6_1_1_workaround, m__ = (double)(max); \ - const double h__ = (double)5 / 10; \ - gcc_6_1_1_workaround = rp; \ - if (gcc_6_1_1_workaround) \ - libclut_sigmoid__(clut, max, type, red); \ - gcc_6_1_1_workaround = gp; \ - if (gcc_6_1_1_workaround) \ - libclut_sigmoid__(clut, max, type, green); \ - gcc_6_1_1_workaround = bp; \ - if (gcc_6_1_1_workaround) \ - libclut_sigmoid__(clut, max, type, blue); \ - } \ - while (0) - - -/** - * Apply S-curve correction on the colour curves. - * This is intended for fine tuning LCD monitors, - * 4.5 is good value start start testing at. - * You would probably like to use rgb_limits before - * this to adjust the blackpoint as that is the - * only way to adjust the blackpoint on many LCD - * monitors. - * - * None of the parameter may have side-effects. - * - * Requires linking with '-lm'. - * - * Intended for internal use. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param channel The channel, must be either "red", "green", or "blue". - */ -#define libclut_sigmoid__(clut, max, type, channel) \ - do \ - { \ - double s__ = *gcc_6_1_1_workaround, l__; \ - size_t i__; \ - for (i__ = 0; i__ < (clut)->channel##_size; i__++) \ - { \ - l__ = log(m__ / (clut)->channel[i__] - 1); \ - if (isnan(l__) || isinf(l__)) \ - l__ = 37.024483 * (isinf(l__) > 0 ? +1 : -1); \ - (clut)->channel[i__] = (type)(m__ * (h__ - l__ / s__)); \ - } \ - } \ - while (0) - - -/** - * Changes the blackpoint and the whitepoint, using sRGB. - * - * None of the parameter may have side-effects. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param rmin The red component value of the blackpoint. - * @param rmax The red component value of the whitepoint. - * @param gmin The green component value of the blackpoint. - * @param gmax The green component value of the whitepoint. - * @param bmin The blue component value of the blackpoint. - * @param bmax The blue component value of the whitepoint. - */ -#define libclut_rgb_limits(clut, max, type, rmin, rmax, gmin, gmax, bmin, bmax) \ - do \ - { \ - double diff__; \ - if (!libclut_0__(rmin) || !libclut_1__(rmax)) \ - { \ - diff__ = (double)(rmax) - (double)(rmin); \ - libclut__(clut, red, type, LIBCLUT_VALUE / (double)(max) * diff__ + (rmin)); \ - } \ - if (!libclut_0__(gmin) || !libclut_1__(gmax)) \ - { \ - diff__ = (double)(gmax) - (double)(gmin); \ - libclut__(clut, green, type, LIBCLUT_VALUE / (double)(max) * diff__ + (gmin)); \ - } \ - if (!libclut_0__(bmin) || !libclut_1__(bmax)) \ - { \ - diff__ = (double)(bmax) - (double)(bmin); \ - libclut__(clut, blue, type, LIBCLUT_VALUE / (double)(max) * diff__ + (bmin)); \ - } \ - } \ - while (0) - - -/** - * Changes the blackpoint and the whitepoint, using CIE xyY. - * - * None of the parameter may have side-effects. - * - * Requires linking with '-lclut'. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param rmin The red component value of the blackpoint. - * @param rmax The red component value of the whitepoint. - * @param gmin The green component value of the blackpoint. - * @param gmax The green component value of the whitepoint. - * @param bmin The blue component value of the blackpoint. - * @param bmax The blue component value of the whitepoint. - */ -#define libclut_cie_limits(clut, max, type, rmin, rmax, gmin, gmax, bmin, bmax) \ - do \ - { \ - double rd__ = (rmax) - (rmin), gd__ = (gmax) - (gmin), bd__ = (bmax) - (bmin); \ - libclut_cie__(clut, max, type, \ - libclut_eq__((rmin), (gmin)) && libclut_eq__((gmin), (bmin)) && \ - libclut_eq__((rmax), (gmax)) && libclut_eq__((gmax), (bmax)), \ - !libclut_0__(rmin) || !libclut_1__(rmax), \ - !libclut_0__(gmin) || !libclut_1__(gmax), \ - !libclut_0__(bmin) || !libclut_1__(bmax), \ - Y__ * rd__ + (rmin), Y__ * gd__ + (gmin), Y__ * bd__ + (bmin)); \ - } \ - while (0) - - -/** - * Manipulate the colour curves using a function on the sRGB colour space. - * - * None of the parameter may have side-effects. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param r Function to manipulate the red colour curve, should either - * be `NULL` or map a [0, 1] `double` to a [0, 1] `double`. - * @param g Function to manipulate the green colour curve, should either - * be `NULL` or map a [0, 1] `double` to a [0, 1] `double`. - * @param b Function to manipulate the blue colour curve, should either - * be `NULL` or map a [0, 1] `double` to a [0, 1] `double`. - */ -#define libclut_manipulate(clut, max, type, r, g, b) \ - do \ - { \ - double m__ = (double)(max); \ - double (*gcc_6_1_1_workaround__)(double); \ - gcc_6_1_1_workaround__ = r; \ - if (gcc_6_1_1_workaround__) \ - libclut__(clut, red, type, m__ * (gcc_6_1_1_workaround__)(LIBCLUT_VALUE / m__)); \ - gcc_6_1_1_workaround__ = g; \ - if (gcc_6_1_1_workaround__) \ - libclut__(clut, green, type, m__ * (gcc_6_1_1_workaround__)(LIBCLUT_VALUE / m__)); \ - gcc_6_1_1_workaround__ = b; \ - if (gcc_6_1_1_workaround__) \ - libclut__(clut, blue, type, m__ * (gcc_6_1_1_workaround__)(LIBCLUT_VALUE / m__)); \ - } \ - while (0) - - -/** - * Manipulate the colour curves using a function on the CIE xyY colour space. - * - * None of the parameter may have side-effects. - * - * Requires linking with '-lclut'. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param r Function to manipulate the red colour curve, should either - * be `NULL` or map a [0, 1] `double` to a [0, 1] `double`. - * @param g Function to manipulate the green colour curve, should either - * be `NULL` or map a [0, 1] `double` to a [0, 1] `double`. - * @param b Function to manipulate the blue colour curve, should either - * be `NULL` or map a [0, 1] `double` to a [0, 1] `double`. - */ -#define libclut_cie_manipulate(clut, max, type, r, g, b) \ - libclut_cie__(clut, max, type, (r) && (g) && (b), r, g, b, (r)(Y__), (g)(Y__), (b)(Y__)) - - -/** - * Resets colour curvers to linear mappings. - * (Identity mapping if imaginged to map from [0, 1] to [0, 1].) - * - * None of the parameter may have side-effects. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param r Whether to reset the red colour curve. - * @param g Whether to reset the green colour curve. - * @param b Whether to reset the blue colour curve. - */ -#define libclut_start_over(clut, max, type, r, g, b) \ - do \ - { \ - size_t i__; \ - double m__, max__ = (double)(max); \ - if (r) \ - { \ - m__ = (double)((clut)->red_size - 1); \ - for (i__ = 0; i__ < (clut)->red_size; i__++) \ - (clut)->red[i__] = (type)(((double)i__ / m__) * max__); \ - } \ - if (g) \ - { \ - m__ = (double)((clut)->green_size - 1); \ - for (i__ = 0; i__ < (clut)->green_size; i__++) \ - (clut)->green[i__] = (type)(((double)i__ / m__) * max__); \ - } \ - if (b) \ - { \ - m__ = (double)((clut)->blue_size - 1); \ - for (i__ = 0; i__ < (clut)->blue_size; i__++) \ - (clut)->blue[i__] = (type)(((double)i__ / m__) * max__); \ - } \ - } \ - while (0) - - -/** - * Clip colour curves to only map to values between the minimum and maximum. - * This should be done, before apply the curves, and before applying changes - * with limited domain. - * - * Values below 0 are set to 0, and values above `max` are set to `max`. - * - * None of the parameter may have side-effects. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param r Whether to clip the red colour curve. - * @param g Whether to clip the green colour curve. - * @param b Whether to clip the blue colour curve. - */ -#define libclut_clip(clut, max, type, r, g, b) \ - do \ - { \ - if (r) libclut__(clut, red, type, libclut_clip__(0, LIBCLUT_VALUE, max)); \ - if (g) libclut__(clut, green, type, libclut_clip__(0, LIBCLUT_VALUE, max)); \ - if (b) libclut__(clut, blue, type, libclut_clip__(0, LIBCLUT_VALUE, max)); \ - } \ - while (0) - -/** - * Truncates a value to fit a boundary. - * - * None of the parameter may have side-effects. - * - * Intended for internal use. - * - * @param min The minimum allowed value. - * @param val The current value. - * @param max The maximum allowed value. - * @return The value truncated into its boundary. - */ -#define libclut_clip__(min, val, max) \ - (LIBCLUT_VALUE < (min) ? (min) : LIBCLUT_VALUE > (max) ? (max) : LIBCLUT_VALUE) - - -/** - * Emulates low colour resolution. - * - * None of the parameter may have side-effects. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param rx The desired emulated red encoding resolution, 0 for unchanged. - * @param ry The desired emulated red output resolution, 0 for unchanged. - * @param gx The desired emulated green encoding resolution, 0 for unchanged. - * @param gy The desired emulated green output resolution, 0 for unchanged. - * @param bx The desired emulated blue encoding resolution, 0 for unchanged. - * @param by The desired emulated blue output resolution, 0 for unchanged. - */ -#define libclut_lower_resolution(clut, max, type, rx, ry, gx, gy, bx, by) \ - do \ - { \ - libclut_lower_resolution__(clut, red, max, type, rx, ry); \ - libclut_lower_resolution__(clut, green, max, type, gx, gy); \ - libclut_lower_resolution__(clut, blue, max, type, bx, by); \ - } \ - while (0) - - -/** - * Emulates low colour resolution of a channel. - * - * None of the parameter may have side-effects. - * - * Intended for internal use. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param channel The channel, must be either "red", "green", or "blue". - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param x The desired emulated encoding resolution, 0 for unchanged. - * @param y The desired emulated output resolution, 0 for unchanged. - */ -#define libclut_lower_resolution__(clut, channel, max, type, x, y) \ - do \ - if ((x) || (y)) \ - { \ - size_t x__, y__, i__, n__ = (clut)->channel##_size; \ - double xm__ = (double)((x) - 1), ym__ = (double)((y) - 1); \ - double m__ = (double)(max), nm__ = (double)(n__ - 1); \ - type c__[n__]; /* Do not use alloca! */ \ - const double h__ = (double)5 / 10; \ - for (i__ = 0; i__ < n__; i__++) \ - { \ - if ((x__ = i__), (x)) \ - { \ - x__ = (size_t)((double)i__ * (double)(x) / (double)n__); \ - x__ = (size_t)((double)x__ * nm__ / xm__); \ - } \ - if (!(y)) \ - c__[i__] = (clut)->channel[x__]; \ - else \ - { \ - y__ = (size_t)((double)((clut)->channel[x__]) / (max) * ym__ + h__); \ - c__[i__] = (type)((double)y__ / ym__ * m__); \ - } \ - } \ - memcpy((clut)->channel, c__, n__ * sizeof(type)); \ - } \ - while (0) - - -/** - * Translates a gamma ramp structure to another gamma ramp structure type. - * - * None of the parameter may have side-effects. - * - * @param dclut Pointer to the desired gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars `red_size`, - * `green_size`, and `blue_size`. Ramp structures from - * libgamma or libcoopgamma can be used. - * @param dmax The maximum value on each stop in the ramps in `dclut`. - * @param dtype The data type used for each stop in the ramps in `dclut`. - * @param sclut Pointer to the set gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars `red_size`, - * `green_size`, and `blue_size`. Ramp structures from - * libgamma or libcoopgamma can be used. - * @param smax The maximum value on each stop in the ramps in `sclut`. - * @param stype The data type used for each stop in the ramps in `sclut`. - * (Not actually used.) - */ -#define libclut_translate(dclut, dmax, dtype, sclut, smax, stype) \ - do \ - { \ - libclut_translate__(dclut, dmax, dtype, sclut, smax, stype, red); \ - libclut_translate__(dclut, dmax, dtype, sclut, smax, stype, green); \ - libclut_translate__(dclut, dmax, dtype, sclut, smax, stype, blue); \ - } \ - while (0) - -/** - * Translates a gamma ramp structure to another gamma ramp structure type. - * - * None of the parameter may have side-effects. - * - * This is intended for internal use. - * - * @param dclut Pointer to the desired gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars `red_size`, - * `green_size`, and `blue_size`. Ramp structures from - * libgamma or libcoopgamma can be used. - * @param dmax The maximum value on each stop in the ramps in `dclut`. - * @param dtype The data type used for each stop in the ramps in `dclut`. - * @param sclut Pointer to the set gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars `red_size`, - * `green_size`, and `blue_size`. Ramp structures from - * libgamma or libcoopgamma can be used. - * @param smax The maximum value on each stop in the ramps in `sclut`. - * @param stype The data type used for each stop in the ramps in `sclut`. - * (Not actually used.) - * @param channel The channel, must be either "red", "green", or "blue". - */ -#define libclut_translate__(dclut, dmax, dtype, sclut, smax, stype, channel) \ - do \ - { \ - size_t di__, si__, sj__; \ - size_t dn__ = (dclut)->channel##_size; \ - size_t sn__ = (sclut)->channel##_size; \ - double dm__ = (double)(dmax); \ - double sm__ = (double)(smax); \ - double dmsm__ = dm__ / sm__; \ - double x__, y__; \ - if (dn__ == sn__) \ - for (di__ = 0; di__ < dn__; di__++) \ - { \ - y__ = (double)((sclut)->channel[di__]) * dmsm__; \ - (dclut)->channel[di__] = (dtype)y__; \ - } \ - else \ - for (di__ = 0; di__ < dn__; di__++) \ - { \ - x__ = di__ / (dn__ - 1) * (sn__ - 1); \ - si__ = (size_t)(x__); \ - sj__ = si__ + (si__ != sn__); \ - x__ -= (double)si__; \ - y__ = (double)((sclut)->channel[si__]) * (1 - x__); \ - y__ += (double)((sclut)->channel[sj__]) * (x__); \ - y__ *= dmsm__; \ - (dclut)->channel[di__] = (dtype)y__; \ - } \ - } \ - while (0) - - -/** - * Applies a filter or calibration. - * - * None of the parameter may have side-effects. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param filter Same as `clut`, but for the filter to apply. - * @param fmax Same as `max`, but for the filter to apply. - * @param ftype Same as `type`, but for the filter to apply. (Not actually used). - * @param r Whether to apply the filter for the red curve. - * @param g Whether to apply the filter for the green curve. - * @param b Whether to apply the filter for the blue curve. - */ -#define libclut_apply(clut, max, type, filter, fmax, ftype, r, g, b) \ - do \ - { \ - if (r) libclut_apply__(clut, max, type, filter, fmax, ftype, red); \ - if (g) libclut_apply__(clut, max, type, filter, fmax, ftype, green); \ - if (b) libclut_apply__(clut, max, type, filter, fmax, ftype, blue); \ - } \ - while (0) - - -/** - * Applies a filter or calibration for one channel. - * - * None of the parameter may have side-effects. - * - * Intended for internal use. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param filter Same as `clut`, but for the filter to apply. - * @param fmax Same as `max`, but for the filter to apply. - * @param ftype Same as `type`, but for the filter to apply. (Not actually used). - * @param channel The channel, must be either "red", "green", or "blue". - */ -#define libclut_apply__(clut, max, type, filter, fmax, ftype, channel) \ - do \ - { \ - size_t i__, rn__ = (clut)->channel##_size, fn__ = (filter)->channel##_size - 1; \ - double x__, rm__ = (double)(max), m__ = (double)(max) / (double)(fmax); \ - for (i__ = 0; i__ < rn__; i__++) \ - { \ - x__ = (double)((clut)->channel[i__]) / rm__ * (double)fn__; \ - (clut)->channel[i__] = (type)((double)((filter)->channel[(size_t)x__]) * m__); \ - } \ - } \ - while (0) - - -/** - * Applies a filter or calibration, using CIE xyY. - * - * None of the parameter may have side-effects. - * - * Requires linking with '-lclut'. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param filter Same as `clut`, but for the filter to apply. - * @param fmax Same as `max`, but for the filter to apply. - * @param ftype Same as `type`, but for the filter to apply. (Not actually used). - * @param r Whether to apply the filter for the red curve. - * @param g Whether to apply the filter for the green curve. - * @param b Whether to apply the filter for the blue curve. - */ -#define libclut_cie_apply(clut, max, type, filter, fmax, ftype, r, g, b) \ - do \ - { \ - size_t rfn__ = (filter)->red_size - 1, gfn__ = (filter)->green_size - 1; \ - size_t bfn__ = (filter)->blue_size - 1, x__; \ - size_t rm__ = (double)(max), fm__ = (double)(fmax); \ - libclut_cie__(clut, max, type, 0, r, g, b, \ - (x__ = (size_t)(Y__ / rm__ * rfn__), (double)((filter)->red[x__]) / fm__), \ - (x__ = (size_t)(Y__ / rm__ * gfn__), (double)((filter)->green[x__]) / fm__), \ - (x__ = (size_t)(Y__ / rm__ * bfn__), (double)((filter)->blue[x__]) / fm__)); \ - } \ - while (0) - - -/** - * Modify a ramp. - * - * None of the parameter may have side-effects. - * - * This is intended for internal use. - * - * @param clut Pointer to the gamma ramps, must have and array - * named `channel` and a scalar named `channel` followed - * by "_size". - * @param channel The channel, must be either "red", "green", or "blue". - * @param type The data type used for each stop in the ramps. - * @param expr Expression that evalutes the value a stop should have. - * It can use the variable `LIBCLUT_VALUE` to get the - * current value of the stop. - */ -#define libclut__(clut, channel, type, expr) \ - do \ - { \ - size_t i__, n__ = (clut)->channel##_size; \ - type LIBCLUT_VALUE; \ - for (i__ = 0; i__ < n__; i__++) \ - { \ - LIBCLUT_VALUE = (clut)->channel[i__]; \ - (clut)->channel[i__] = (type)(expr); \ - } \ - } \ - while (0) - - -/** - * Modify a ramp set in CIE xyY. - * - * None of the parameter may have side-effects. - * - * Requires linking with '-lclut'. - * - * This is intended for internal use. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param utest Whether all channels can be modified at the same time. - * This test does not have to include the ramp size. - * @param rtest Whether the red channel have to be modified. - * @param gtest Whether the green channel have to be modified. - * @param btest Whether the blue channel have to be modified. - * @param rexpr Expression calculating the intensity of the red channel. - * The current value is stored in `Y__`. - * @param gexpr Expression calculating the intensity of the green channel. - * The current value is stored in `Y__`. - * @param bexpr Expression calculating the intensity of the blue channel. - * The current value is stored in `Y__`. - */ -#define libclut_cie__(clut, max, type, utest, rtest, gtest, btest, rexpr, gexpr, bexpr) \ - do \ - { \ - size_t rn__ = (clut)->red_size; \ - size_t gn__ = (clut)->green_size; \ - size_t bn__ = (clut)->blue_size; \ - size_t i__; \ - double x__, y__, Y__, r__, g__, b__; \ - double m__ = (double)(max); \ - type* rs__ = (clut)->red; \ - type* gs__ = (clut)->green; \ - type* bs__ = (clut)->blue; \ - if ((rn__ == gn__) && (gn__ == bn__) && (utest)) \ - { \ - if (!(rtest)) \ - break; \ - for (i__ = 0; i__ < rn__; i__++) \ - { \ - libclut_model_srgb_to_ciexyy(rs__[i__] / m__, gs__[i__] / m__, \ - bs__[i__] / m__, &x__, &y__, &Y__); \ - libclut_model_ciexyy_to_srgb(x__, y__, rexpr, &r__, &g__, &b__); \ - rs__[i__] = (type)(r__ * m__); \ - gs__[i__] = (type)(g__ * m__); \ - bs__[i__] = (type)(b__ * m__); \ - } \ - } \ - else if ((rn__ == gn__) && (gn__ == bn__)) \ - { \ - if (!(rtest) && !(gtest) && !(btest)) \ - break; \ - for (i__ = 0; i__ < rn__; i__++) \ - { \ - libclut_model_srgb_to_ciexyy(rs__[i__] / m__, gs__[i__] / m__, \ - bs__[i__] / m__, &x__, &y__, &Y__); \ - if (rtest) \ - { \ - libclut_model_ciexyy_to_srgb(x__, y__, rexpr, &r__, &g__, &b__); \ - rs__[i__] = (type)(r__ * m__); \ - } \ - if (gtest) \ - { \ - libclut_model_ciexyy_to_srgb(x__, y__, gexpr, &r__, &g__, &b__); \ - gs__[i__] = (type)(g__ * m__); \ - } \ - if (btest) \ - { \ - libclut_model_ciexyy_to_srgb(x__, y__, bexpr, &r__, &g__, &b__); \ - bs__[i__] = (type)(b__ * m__); \ - } \ - } \ - } \ - else \ - { \ - if (rtest) \ - for (i__ = 0; i__ < rn__; i__++) \ - libclut_cie___(clut, max, type, r, rexpr, i__, \ - libclut_i__(i__, rn__, gn__), \ - libclut_i__(i__, rn__, bn__)); \ - if (gtest) \ - for (i__ = 0; i__ < rn__; i__++) \ - libclut_cie___(clut, max, type, g, gexpr, \ - libclut_i__(i__, gn__, rn__), i__, \ - libclut_i__(i__, gn__, bn__)); \ - if (btest) \ - for (i__ = 0; i__ < rn__; i__++) \ - libclut_cie___(clut, max, type, b, bexpr, \ - libclut_i__(i__, bn__, rn__), \ - libclut_i__(i__, bn__, gn__), i__); \ - } \ - } \ - while (0) - - -/** - * Modify a ramp stop in CIE xyY. - * - * None of the parameter may have side-effects. - * - * Requires linking with '-lclut'. - * - * This is intended for internal use. - * Assumes the existence of variables defined in `libclut_cie__`. - * - * @param clut Pointer to the gamma ramps, must have the arrays - * `red`, `green`, and `blue`, and the scalars - * `red_size`, `green_size`, and `blue_size`. Ramp - * structures from libgamma or libcoopgamma can be used. - * @param max The maximum value on each stop in the ramps. - * @param type The data type used for each stop in the ramps. - * @param c Either "r" for red, "g" for green, or "b" for blue. - * @param expr Expression calculating the intensity of the channel. - * @param ri The index of the stop translated to the red channel. - * @param gi The index of the stop translated to the green channel. - * @param bi The index of the stop translated to the blue channel. - */ -#define libclut_cie___(clut, max, type, c, expr, ri, gi, bi) \ - do \ - { \ - for (i__ = 0; i__ < c##n__; i__++) \ - { \ - libclut_model_srgb_to_ciexyy(rs__[(ri)] / m__, gs__[(gi)] / m__, \ - bs__[(bi)] / m__, &x__, &y__, &Y__); \ - libclut_model_ciexyy_to_srgb(x__, y__, expr, &r__, &g__, &b__); \ - c##s__[i__] = (type)(c##__ * m__); \ - } \ - } \ - while (0) - - -/** - * Translate an index from one channel to another. - * - * @param i The index in the input channel. - * @param in The size of the input channel. - * @param out The size of the output channel. - * @return The index in the output channel. - */ -#define libclut_i__(i, in, out) \ - (size_t)((double)(i) * (double)(out) / (double)(in)) - - - -#if defined(__GNUC__) && !defined(__clang__) -# define LIBCLUT_GCC_ONLY__(x) x -#else -# define LIBCLUT_GCC_ONLY__(x) /* do nothing */ -#endif - - - -/** - * Convert one component from [0, 1] linear sRGB to [0, 1] sRGB. - * - * If the macro variant is used, the argument must not have - * any side-effects. The macro variant requires linking with - * '-lm'. - * - * @param c The linear sRGB value. - * @return Corresponding sRGB value. - */ -LIBCLUT_GCC_ONLY__(__attribute__((__const__, __leaf__))) -double (libclut_model_linear_to_standard1)(double); -#define libclut_model_linear_to_standard1(c) \ - (((double)(c) <= 0.0031308) ? (12.92 * (double)(c)) : ((1.055) * pow((double)(c), 1 / 2.4) - 0.055)) - - -/** - * Convert [0, 1] linear sRGB to [0, 1] sRGB. - * - * The macro variant requires linking with '-lm', - * if the 'libclut_model_linear_to_standard1' is defined, - * otherwise it requires linking with '-lclut'. - * - * @param r Pointer to the linear red component, - * and output parameter for the red component. - * @param g Pointer to the linear green component, - * and output parameter for the green component. - * @param b Pointer to the linear blue component, - * and output parameter for the blue component. - */ -void (libclut_model_linear_to_standard)(double*, double*, double*); -#define libclut_model_linear_to_standard(r, g, b) \ - do \ - { \ - double *r__ = (r), *g__ = (g), *b__ = (b); \ - *r__ = libclut_model_linear_to_standard1(*r__); \ - *g__ = libclut_model_linear_to_standard1(*g__); \ - *b__ = libclut_model_linear_to_standard1(*b__); \ - } \ - while (0) - - -/** - * Convert one component from [0, 1] sRGB to [0, 1] linear sRGB. - * - * If the macro variant is used, the argument must not have - * any side-effects. The macro variant requires linking with - * '-lm'. - * - * @param c The sRGB value. - * @return Corresponding linear sRGB value. - */ -LIBCLUT_GCC_ONLY__(__attribute__((__const__, __leaf__))) -double (libclut_model_standard_to_linear1)(double); -#define libclut_model_standard_to_linear1(c) \ - (((double)(c) <= 0.04045) ? ((double)(c) / 12.92) : pow(((double)(c) + 0.055) / 1.055, 2.4)) - - -/** - * Convert [0, 1] sRGB to [0, 1] linear sRGB. - * - * The macro variant requires linking with '-lm', - * if the 'libclut_model_standard_to_linear1' is defined, - * otherwise it requires linking with '-lclut'. - * - * @param r Pointer to the red component, and output - * parameter for the linear red component. - * @param g Pointer to the green component, and output - * parameter for the linear green component. - * @param b Pointer to the blue component, and output - * parameter for the linear blue component. - */ -void (libclut_model_standard_to_linear)(double*, double*, double*); -#define libclut_model_standard_to_linear(r, g, b) \ - do \ - { \ - double *r__ = (r), *g__ = (g), *b__ = (b); \ - *r__ = libclut_model_standard_to_linear1(*r__); \ - *g__ = libclut_model_standard_to_linear1(*g__); \ - *b__ = libclut_model_standard_to_linear1(*b__); \ - } \ - while (0) - - -/** - * Convert CIE xyY to CIE XYZ. - * - * @param x The x parameter. - * @param y The y parameter. - * @param Y The Y parameter. This is also the Y (middle) parameter for the CIE XYZ colour. - * @param X Output parameter for the X parameter. - * @param Z Output parameter for the Z parameter. - */ -LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) -void (libclut_model_ciexyy_to_ciexyz)(double, double, double, double*, double*); -#define libclut_model_ciexyy_to_ciexyz(x, y, Y, X, Z) \ - do \ - { \ - double x__ = (x), y__ = (y), Y__ = (Y), *X__ = (X), *Z__ = (Z); \ - *X__ = libclut_0__(y__) ? Y__ : (Y__ * x__ / y__); \ - *Z__ = libclut_0__(y__) ? Y__ : (Y__ * (1 - x__ - y__) / y__); \ - } \ - while (0) - - -/** - * Convert CIE XYZ to CIE xyY. - * - * @param X The X parameter. - * @param Y The Y parameter. This is also the Y (last) parameter for the CIE xyY colour. - * @param Z The Z parameter. - * @param x Output parameter for the x parameter. - * @param y Output parameter for the y parameter. - */ -LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) -void (libclut_model_ciexyz_to_ciexyy)(double, double, double, double*, double*); -#define libclut_model_ciexyz_to_ciexyy(X, Y, Z, x, y) \ - do \ - { \ - double X__ = (X), Y__ = (Y), Z__ = (Z), *x__ = (x), *y__ = (y); \ - double s__ = X__ + Y__ + Z__; \ - if (libclut_0__(s__)) \ - *x__ = *y__ = 0; \ - else \ - *x__ = X__ / s__, *y__ = Y__ / s__; \ - } \ - while (0) - - -/** - * Convert CIE XYZ to [0, 1] linear sRGB. - * - * @param X The X parameter. - * @param Y The Y parameter. - * @param Z The Z parameter. - * @param r Output parameter for the red component. - * @param g Output parameter for the green component. - * @param b Output parameter for the blue component. - */ -LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) -void (libclut_model_ciexyz_to_linear)(double, double, double, double*, double*, double*); -#define libclut_model_ciexyz_to_linear(X, Y, Z, r, g, b) \ - do \ - { \ - double X__ = (X), Y__ = (Y), Z__ = (Z); \ - *(r) = ( 3.2404500 * X__) + (-1.537140 * Y__) + (-0.4985320 * Z__); \ - *(g) = (-0.9692660 * X__) + ( 1.876010 * Y__) + ( 0.0415561 * Z__); \ - *(b) = ( 0.0556434 * X__) + (-0.204026 * Y__) + ( 1.0572300 * Z__); \ - } \ - while (0) - - -/** - * Convert [0, 1] linear sRGB to CIE XYZ. - * - * @param r The red component. - * @param g The green component. - * @param b The blue component. - * @param X Output parameter for the X parameter. - * @param Y Output parameter for the Y parameter. - * @param Z Output parameter for the Z parameter. - */ -LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) -void (libclut_model_linear_to_ciexyz)(double, double, double, double*, double*, double*); -#define libclut_model_linear_to_ciexyz(r, g, b, X, Y, Z) \ - do \ - { \ - double r__ = (r), g__ = (g), b__ = (b); \ - *(X) = (0.4124564 * r__) + (0.3575761 * g__) + (0.1804375 * b__); \ - *(Y) = (0.2126729 * r__) + (0.7151522 * g__) + (0.0721750 * b__); \ - *(Z) = (0.0193339 * r__) + (0.1191920 * g__) + (0.9503041 * b__); \ - } \ - while (0) - - -/** - * Convert [0, 1] sRGB to CIE xyY. - * - * The macro variant requires linking with '-lclut' - * if any of `libclut_model_ciexyz_to_ciexyy`, - * `libclut_model_linear_to_ciexyz`, and - * `libclut_model_standard_to_linear` are undefined. - * The macro variant requires linking with '-lm' if - * neither `libclut_model_standard_to_linear` nor - * `libclut_model_standard_to_linear1` are undefined. - * - * @param r The red component. - * @param g The green component. - * @param b The blue component. - * @param x Output parameter for the x parameter. - * @param y Output parameter for the y parameter. - * @param Y Output parameter for the Y parameter. - */ -void (libclut_model_srgb_to_ciexyy)(double, double, double, double*, double*, double*); -#define libclut_model_srgb_to_ciexyy(r, g, b, x, y, Y) \ - do \ - { \ - double r___ = (r), g___ = (g), b___ = (b); \ - double *x___ = (x), *y___ = (y), *Y___ = (Y); \ - double X___, Z___; \ - libclut_model_standard_to_linear(&r___, &g___, &b___); \ - libclut_model_linear_to_ciexyz(r___, g___, b___, &X___, Y___, &Z___); \ - libclut_model_ciexyz_to_ciexyy(X___, *Y___, Z___, x___, y___); \ - } \ - while (0) - - -/** - * Convert CIE xyY to [0, 1] sRGB. - * - * The macro variant requires linking with '-lclut' - * if any of `libclut_model_ciexyy_to_ciexyz`, - * `libclut_model_ciexyz_to_linear`, and - * `libclut_model_linear_to_standard` are undefined. - * The macro variant requires linking with '-lm' if - * neither `libclut_model_linear_to_standard` nor - * `libclut_model_linear_to_standard1` are undefined. - * - * @param x The x parameter. - * @param y The y parameter. - * @param Y The Y parameter. - * @param r Output parameter for the red component. - * @param g Output parameter for the green component. - * @param b Output parameter for the blue component. - */ -void (libclut_model_ciexyy_to_srgb)(double, double, double, double*, double*, double*); -#define libclut_model_ciexyy_to_srgb(x, y, Y, r, g, b) \ - do \ - { \ - double x___ = (x), y___ = (y), Y___ = (Y); \ - double *r___ = (r), *g___ = (g), *b___ = (b); \ - double X___, Z___; \ - libclut_model_ciexyy_to_ciexyz(x___, y___, Y___, &X___, &Z___); \ - libclut_model_ciexyz_to_linear(X___, Y___, Z___, r___, g___, b___); \ - libclut_model_linear_to_standard(r___, g___, b___); \ - } \ - while(0) - - -/** - * Convert from CIE XYZ to CIE L*a*b*. - * - * The macro variant requires linking with '-lm'. - * - * @param X The X parameter. - * @param Y The Y parameter. - * @param Z The Z parameter. - * @param L Output parameter for the L* component. - * @param a Output parameter for the a* component. - * @param b Output parameter for the b* component. - */ -LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) -void (libclut_model_ciexyz_to_cielab)(double, double, double, double*, double*, double*); -#define libclut_model_ciexyz_to_cielab(X, Y, Z, L, a, b) \ - do \ - { \ - double X__ = (X), Y__ = (Y), Z__ = (Z); \ - X__ /= 0.95047, Z__ /= 1.08883; \ - X__ = LIBCLUT_MODEL_CIEXYZ_TO_CIELAB__(X__); \ - Y__ = LIBCLUT_MODEL_CIEXYZ_TO_CIELAB__(Y__); \ - Z__ = LIBCLUT_MODEL_CIEXYZ_TO_CIELAB__(Z__); \ - *(L) = 116 * Y__ - 16; \ - *(a) = 500 * (X__ - Y__); \ - *(b) = 200 * (Y__ - Z__); \ - } \ - while (0) -#define LIBCLUT_MODEL_CIEXYZ_TO_CIELAB__(C) \ - (((C) > 0.00885642) ? pow((C), 1.0 / 3) : ((7.78 + 703.0 / 99900) * (C) + 0.1379310)) - - -/** - * Convert from CIE L*a*b* to CIE XYZ. - * - * @param L The L* component. - * @param a The a* component. - * @param b The b* component. - * @param X Output parameter for the X parameter. - * @param Y Output parameter for the Y parameter. - * @param Z Output parameter for the Z parameter. - */ -LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) -void (libclut_model_cielab_to_ciexyz)(double, double, double, double*, double*, double*); -#define libclut_model_cielab_to_ciexyz(L, a, b, X, Y, Z) \ - do \ - { \ - double L__ = (L), a__ = (a), b__ = (b); \ - double *X__ = (X), *Y__ = (Y), *Z__ = (Z); \ - *Y__ = (L__ + 16) / 116; \ - *X__ = a__ / 500 + *Y__; \ - *Z__ = *Y__ - b__ / 200; \ - *X__ = LIBCLUT_MODEL_CIELAB_TO_CIEXYZ__(*X__) * 0.95047; \ - *Y__ = LIBCLUT_MODEL_CIELAB_TO_CIEXYZ__(*Y__) * 1.08883; \ - *Z__ = LIBCLUT_MODEL_CIELAB_TO_CIEXYZ__(*Z__); \ - } \ - while (0) -#define LIBCLUT_MODEL_CIELAB_TO_CIEXYZ__(C) \ - (((C)*(C)*(C) > 0.00885642) ? ((C)*(C)*(C)) : (((C) - 0.1379310) / (7.78 + 703.0 / 99900))) - - -/** - * Convert from CIE XYZ to CIELUV. - * - * Requires linking with `-lm`. - * - * @param X The X component. - * @param Y The Y component. - * @param Z The Z component. - * @param Xn The X component of the specified white object (white point). - * @param Yn The Y component of the specified white object (white point). - * @param Zn The Z component of the specified white object (white point). - * @param L Output parameter for the L* parameter. - * @param u Output parameter for the u* parameter. - * @param v Output parameter for the v* parameter. - */ -LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) -void (libclut_model_ciexyz_to_cieluv)(double, double, double, double, double, - double, double*, double*, double*); -#define libclut_model_ciexyz_to_cieluv(X, Y, Z, Xn, Yn, Zn, L, u, v) \ - do \ - { \ - double xn__ = (Xn), yn__ = (Yn); \ - double t__ = xn__ + 15 * yn__ + 3 * (Zn); \ - double u__ = 4 * xn__ / t__; \ - double v__ = 9 * yn__ / t__; \ - double x__ = (X), y__ = (Y); \ - t__ = x__ + 15 * y__ + 3 * (Z); \ - u__ = 4 * x__ / t__ - u__; \ - v__ = 9 * y__ / t__ - v__; \ - y__ /= yn__; \ - if (y__ * 24389 <= (double)216) \ - y__ *= 24389, y__ /= 27; \ - else \ - y__ = cbrt(y__) * 116 - 16; \ - *(L) = y__; \ - y__ *= 13; \ - *(u) = y__ * u__; \ - *(v) = y__ * v__; \ - } \ - while (0) - - -/** - * Convert from CIELUV to CIE XYZ. - * - * @param L The L* component. - * @param u The u* component. - * @param v The v* component. - * @param Xn The X component of the specified white object (white point). - * @param Yn The Y component of the specified white object (white point). - * @param Zn The Z component of the specified white object (white point). - * @param X Output parameter for the X parameter. - * @param Y Output parameter for the Y parameter. - * @param Z Output parameter for the Z parameter. - */ -LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) -void (libclut_model_cieluv_to_ciexyz)(double, double, double, double, double, - double, double*, double*, double*); -#define libclut_model_cieluv_to_ciexyz(L, u, v, Xn, Yn, Zn, X, Y, Z) \ - do \ - { \ - double x__ = (Xn), y__ = (Yn), l__ = (L), l13__ = l__ * 13; \ - double t__ = x__ + 15 * y__ + 3 * (Zn); \ - double u__ = 4 * x__ / t__; \ - double v__ = 9 * y__ / t__; \ - u__ = (u) / l13__ + u__; \ - v__ = (v) / l13__ + v__; \ - if (l__ <= (double)8) \ - y__ *= l__ * 27 / 24389; \ - else \ - { \ - l__ += 16, l__ /= 116; \ - y__ *= l__ *= l__ * l__; \ - } \ - *(Y) = y__; \ - *(X) = y__ * 9 * u__ / (4 * v__); \ - *(Z) = y__ * (12 - 3 * u__ - 20 * v__) / (4 * v__); \ - } \ - while (0) - - -/** - * Convert from CIELCh to CIE L*u*v*. - * - * Requires linking with `-lm`. - * - * @param C The C*_uv component. - * @param h The h_uv component. - * @param u Output parameter for the u* parameter. - * @param v Output parameter for the v* parameter. - */ -LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) -void (libclut_model_cielch_to_cieluv)(double, double, double*, double*); -#define libclut_model_cielch_to_cieluv(C, h, u, v) \ - do \ - { \ - double h__ = (h), C__ = (C); \ - *(v) = sin(h__) * C__; \ - *(u) = cos(h__) * C__; \ - } \ - while (0) - - -/** - * Convert from CIE L*u*v* to CIELCh. - * - * Requires linking with `-lm`. - * - * @param u The u* component. - * @param v The v* component. - * @param C Output parameter for the C*_uv parameter. - * @param h Output parameter for the h_uv parameter. - */ -LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) -void (libclut_model_cieluv_to_cielch)(double, double, double*, double*); -#define libclut_model_cieluv_to_cielch(u, v, C, h) \ - do \ - { \ - double u__ = (u), v__ = (v); \ - *(C) = sqrt(u__ * u__ + v__ * v__); \ - *(h) = atan2(v__, u__); \ - } \ - while (0) - - -/** - * Convert from sRGB to YIQ. - * - * Requires linking with '-lclut', or '-lm' if - * `libclut_model_standard_to_linear1` is not undefined. - * - * @param r The R component. - * @param g The G component. - * @param b The B component. - * @param y Output parameter for the Y parameter. - * @param i Output parameter for the I parameter. - * @param q Output parameter for the Q parameter. - */ -void (libclut_model_srgb_to_yiq)(double, double, double, double*, double*, double*); -#define libclut_model_srgb_to_yiq(r, g, b, y, i, q) \ - do \ - { \ - double r__ = libclut_model_standard_to_linear1(r) / 100000000000000000ULL; \ - double g__ = libclut_model_standard_to_linear1(g) / 10000000000000000ULL; \ - double b__ = libclut_model_standard_to_linear1(b) / 100000000000000000ULL; \ - *(y) = r__ * 29893602129377540ULL + g__ * 5870430744511212ULL + b__ * 11402090425510336ULL; \ - *(i) = r__ * 59594574307079930ULL - g__ * 2743886357457892ULL - b__ * 32155710732501010ULL; \ - *(q) = r__ * 21149734030682846ULL - g__ * 5229106903029739ULL + b__ * 31141334999614540ULL; \ - } \ - while (0) - - -/** - * Convert from YIQ to sRGB. - * - * Requires linking with '-lclut', or '-lm' if - * `libclut_model_linear_to_standard1` is not undefined. - * - * @param y The Y component. - * @param i The I component. - * @param q The Q component. - * @param r Output parameter for the R parameter. - * @param g Output parameter for the G parameter. - * @param b Output parameter for the B parameter. - */ -void (libclut_model_yiq_to_srgb)(double, double, double, double*, double*, double*); -#define libclut_model_yiq_to_srgb(y, i, q, r, g, b) \ - do \ - { \ - double y__ = (y), i__ = (i), q__ = (q), r__, g__, b__; \ - r__ = y__ + i__ * 956 / 1000 + q__ * 621 / 1000; \ - g__ = y__ - i__ * 272 / 1000 - q__ * 647 / 1000; \ - b__ = y__ - i__ * 1106 / 1000 + q__ * 1703 / 1000; \ - *(r) = libclut_model_linear_to_standard1(r__); \ - *(g) = libclut_model_linear_to_standard1(g__); \ - *(b) = libclut_model_linear_to_standard1(b__); \ - } \ - while (0) - - -/** - * Convert from sRGB to YDbDr. - * - * Requires linking with '-lclut', or '-lm' if - * `libclut_model_standard_to_linear1` is not undefined. - * - * @param r The R component. - * @param g The G component. - * @param b The B component. - * @param y Output parameter for the Y parameter. - * @param db Output parameter for the Db parameter. - * @param dr Output parameter for the Dr parameter. - */ -void (libclut_model_srgb_to_ydbdr)(double, double, double, double*, double*, double*); -#define libclut_model_srgb_to_ydbdr(r, g, b, y, db, dr) \ - do \ - { \ - double r__ = libclut_model_standard_to_linear1(r); \ - double g__ = libclut_model_standard_to_linear1(g); \ - double b__ = libclut_model_standard_to_linear1(b); \ - *(y) = r__ * 299 / 1000 + g__ * 587 / 1000 + b__ * 114 / 1000; \ - *(db) = -r__ * 450 / 1000 - g__ * 883 / 1000 + b__ * 1333 / 1000; \ - *(dr) = -r__ * 1333 / 1000 + g__ * 1116 / 1000 + b__ * 217 / 1000; \ - } \ - while (0) - - -/** - * Convert from YDbDr to sRGB. - * - * Requires linking with '-lclut', or '-lm' if - * `libclut_model_linear_to_standard1` is not undefined. - * - * @param y The Y component. - * @param db The Db component. - * @param dr The Dr component. - * @param r Output parameter for the R parameter. - * @param g Output parameter for the G parameter. - * @param b Output parameter for the B parameter. - */ -void (libclut_model_ydbdr_to_srgb)(double, double, double, double*, double*, double*); -#define libclut_model_ydbdr_to_srgb(y, db, dr, r, g, b) \ - do \ - { \ - double y__ = (y), db__ = (db), dr__ = (dr), r__, g__, b__; \ - db__ /= 1000000000000000ULL; \ - dr__ /= 1000000000000000ULL; \ - r__ = y__ + db__ * 92303716148ULL - dr__ * 525912630661865ULL; \ - g__ = y__ - db__ * 129132898890509ULL + dr__ * 267899328207599ULL; \ - b__ = y__ + db__ * 664679059978955ULL - dr__ * 79202543533ULL; \ - *(r) = libclut_model_linear_to_standard1(r__); \ - *(g) = libclut_model_linear_to_standard1(g__); \ - *(b) = libclut_model_linear_to_standard1(b__); \ - } \ - while (0) - - -/** - * Convert from YUV to YDbDr. - * - * @param u The U component. - * @param v The V component. - * @param db Output parameter for the Db parameter. - * @param dr Output parameter for the Dr parameter. - */ -LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) -void (libclut_model_yuv_to_ydbdr)(double, double, double*, double*); -#define libclut_model_yuv_to_ydbdr(u, v, db, dr) \ - do \ - { \ - *(db) = 3069 * (u) / 1000; \ - *(dr) = -2169 * (v) / 1000; \ - } \ - while (0) - - -/** - * Convert from YDbDr to YUV. - * - * @param db The Db component. - * @param dr The Dr component. - * @param u Output parameter for the U parameter. - * @param v Output parameter for the V parameter. - */ -LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) -void (libclut_model_ydbdr_to_yuv)(double, double, double*, double*); -#define libclut_model_ydbdr_to_yuv(db, dr, u, v) \ - do \ - { \ - *(u) = (db) * 1000 / 3069; \ - *(v) = (dr) * 1000 / -2169; \ - } \ - while (0) - - -/** - * Convert from sRGB to YPbPr. - * - * Requires linking with '-lclut', or '-lm' if - * `libclut_model_standard_to_linear1` is not undefined. - * - * @param r The R component. - * @param g The G component. - * @param b The B component. - * @param y Output parameter for the Y parameter. - * @param pb Output parameter for the Pb parameter. - * @param pr Output parameter for the Pr parameter. - */ -void (libclut_model_srgb_to_ypbpr)(double, double, double, double*, double*, double*); -#define libclut_model_srgb_to_ypbpr(r, g, b, y, pb, pr) \ - do \ - { \ - double r__ = libclut_model_standard_to_linear1(r); \ - double g__ = libclut_model_standard_to_linear1(g); \ - double b__ = libclut_model_standard_to_linear1(b); \ - double y__; \ - y__ = r__ * 2126 / 10000; \ - y__ += g__ * 7152 / 10000; \ - y__ += b__ * 722 / 10000; \ - *(y) = y__; \ - *(pb) = b__ - y__; \ - *(pr) = r__ - y__; \ - ; \ - } \ - while (0) - - -/** - * Convert from YPbPr to sRGB. - * - * Requires linking with '-lclut', or '-lm' if - * `libclut_model_linear_to_standard1` is not undefined. - * - * @param y The Y component. - * @param pb The Pb component. - * @param pr The Pr component. - * @param r Output parameter for the R parameter. - * @param g Output parameter for the G parameter. - * @param b Output parameter for the B parameter. - */ -void (libclut_model_ypbpr_to_srgb)(double, double, double, double*, double*, double*); -#define libclut_model_ypbpr_to_srgb(y, pb, pr, r, g, b) \ - do \ - { \ - double y__ = (y), r__ = (pr) + y__, g__, b__ = (pb) + y__; \ - y__ -= r__ * 2126 / 10000; \ - y__ -= b__ * 722 / 10000; \ - g__ = y__ * 10000 / 7152; \ - *(r) = libclut_model_linear_to_standard1(r__); \ - *(g) = libclut_model_linear_to_standard1(g__); \ - *(b) = libclut_model_linear_to_standard1(b__); \ - } \ - while (0) - - -/** - * Convert from sRGB to YCgCo. - * - * Requires linking with '-lclut', or '-lm' if - * `libclut_model_standard_to_linear1` is not undefined. - * - * @param r The R component. - * @param g The G component. - * @param b The B component. - * @param y Output parameter for the Y parameter. - * @param cg Output parameter for the Cg parameter. - * @param co Output parameter for the Co parameter. - */ -void (libclut_model_srgb_to_ycgco)(double, double, double, double*, double*, double*); -#define libclut_model_srgb_to_ycgco(r, g, b, y, cg, co) \ - do \ - { \ - double r__ = libclut_model_standard_to_linear1(r); \ - double g__ = libclut_model_standard_to_linear1(g); \ - double b__ = libclut_model_standard_to_linear1(b); \ - *(y) = r__ / 4 + g__ / 2 + b__ / 4; \ - *(cg) = r__ / -4 + g__ / 2 - b__ / 4; \ - *(co) = r__ / 2 - b__ / 2; \ - } \ - while (0) - - -/** - * Convert from YCgCo to sRGB. - * - * Requires linking with '-lclut', or '-lm' if - * `libclut_model_linear_to_standard1` is not undefined. - * - * @param y The Y component. - * @param cg The Cg component. - * @param co The Co component. - * @param r Output parameter for the R parameter. - * @param g Output parameter for the G parameter. - * @param b Output parameter for the B parameter. - */ -void (libclut_model_ycgco_to_srgb)(double, double, double, double*, double*, double*); -#define libclut_model_ycgco_to_srgb(y, cg, co, r, g, b) \ - do \ - { \ - double y__ = (y), cg__ = (cg), co__ = (co); \ - double r__ = y__ - cg__ + co__; \ - double g__ = y__ + cg__; \ - double b__ = y__ - cg__ - co__; \ - *(r) = libclut_model_linear_to_standard1(r__); \ - *(g) = libclut_model_linear_to_standard1(g__); \ - *(b) = libclut_model_linear_to_standard1(b__); \ - } \ - while (0) - - -/** - * Convert from CIE 1960 UCS to CIE XYZ. - * - * @param u The u component. - * @param v The v component. - * @param Y The Y component. - * @param x Output parameter for the X parameter. - * @param y Output parameter for the Y parameter. - * @param z Output parameter for the Z parameter. - */ -LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) -void (libclut_model_cie_1960_ucs_to_ciexyz)(double, double, double, double*, double*, double*); -#define libclut_model_cie_1960_ucs_to_ciexyz(u, v, Y, x, y, z) \ - do \ - { \ - double u__ = (u), v__ = (v), y__ = (Y); \ - *(y) = y__; \ - *(x) = 3 * y__ * u__ / (2 * v__); \ - *(z) = (4 * y__ - y__ * u__ - 10 * y__ * v__) / (2 * v__); \ - } \ - while (0) - - -/** - * Convert from CIE XYZ to CIE 1960 UCS. - * - * @param x The X component. - * @param y The Y component. - * @param z The Z component. - * @param u Output parameter for the u parameter. - * @param v Output parameter for the v parameter. - * @param Y Output parameter for the Y parameter. - */ -LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) -void (libclut_model_ciexyz_to_cie_1960_ucs)(double, double, double, double*, double*, double*); -#define libclut_model_ciexyz_to_cie_1960_ucs(x, y, z, u, v, Y) \ - do \ - { \ - double x__ = (x), y__ = (y); \ - double d__ = x__ + 15 * y__ + 3 * (z); \ - *(u) = 4 * x__ / d__; \ - *(v) = 6 * y__ / d__; \ - *(Y) = y__; \ - } \ - while (0) - - -/** - * Convert from CIEUVW to CIE 1960 UCS. - * - * @param U:double The U* component. - * @param V:double The V* component. - * @param W:double The W* component. - * @param u0:double The u parameter for the white point. - * @param v0:double The v parameter for the white point. - * @param u:double* Output parameter for the u parameter. - * @param v:double* Output parameter for the v parameter. - * @param Y:double* Output parameter for the Y parameter. - */ -LIBCLUT_GCC_ONLY__(__attribute__((__leaf__))) -void (libclut_model_cieuvw_to_cie_1960_ucs)(double, double, double, double, double, - double*, double*, double*); -#define libclut_model_cieuvw_to_cie_1960_ucs(U, V, W, u0, v0, u, v, Y) \ - do \ - { \ - double w__ = (W), y__ = (w__ + 17) / 25; \ - *(Y) = y__ *= y__ * y__; \ - w__ *= 13; \ - *(u) = (U) / w__ + (u0); \ - *(v) = (V) / w__ + (v0); \ - } \ - while (0) - - -/** - * Convert from CIE 1960 UCS to CIEUVW. - * - * Requires linking with `-lm`. - * - * @param u:double The u component. - * @param v:double The v component. - * @param Y:double The Y component. - * @param u0:double The u parameter for the white point. - * @param v0:double The v parameter for the white point. - * @param U:double* Output parameter for the U* parameter. - * @param V:double* Output parameter for the V* parameter. - * @param W:double* Output parameter for the W* parameter. - */ -void (libclut_model_cie_1960_ucs_to_cieuvw)(double, double, double, double, double, - double*, double*, double*); -#define libclut_model_cie_1960_ucs_to_cieuvw(u, v, Y, u0, v0, U, V, W) \ - do \ - { \ - double w__ = 25 * cbrt(Y) - 17; \ - *(W) = w__; \ - w__ *= 13; \ - *(U) = w__ * ((u) - (u0)); \ - *(V) = w__ * ((v) - (v0)); \ - } \ - while (0) - - -/** - * Create a matrix for converting values between - * two RGB colour spaces. - * - * @param from The input colour space, the Y-component is only necessary - * for the white point, `NULL` for CIE XYZ. - * @param to The output colour space, the Y-component is only necessary - * for the white point, `NULL` for CIE XYZ. - * @param M Output matrix for conversion from `from` to `to`. - * @param Minv Output matrix for conversion from `to` to `from`, may be `NULL`. - * @return Zero on success, -1 on error. - * - * @throws EINVAL The colour space cannot be used. - */ -int libclut_model_get_rgb_conversion_matrix(const libclut_rgb_colour_space_t*, - const libclut_rgb_colour_space_t*, - libclut_colour_space_conversion_matrix_t, - libclut_colour_space_conversion_matrix_t); - - -/** - * Convert an RGB colour into another RGB colour space. - * - * Both RGB colour spaces must have same gamma functions as sRGB. - * - * Requires linking with '-lclut', or '-lm' if - * `libclut_model_standard_to_linear1` or - * `libclut_model_linear_to_standard1` is not undefined. - * - * @param r The red component of the colour to convert. - * @param g The green component of the colour to convert. - * @param b The blue component of the colour to convert. - * @param M Conversion matrix, create with `libclut_model_get_rgb_conversion_matrix`, - * must not have side-effects. - * @param out_r Output parameter for the new red component. - * @param out_g Output parameter for the new green component. - * @param out_b Output parameter for the new blue component. - */ -void (libclut_model_convert_rgb)(double, double, double, libclut_colour_space_conversion_matrix_t, - double*, double*, double*); -#define libclut_model_convert_rgb(r, g, b, M, out_r, out_g, out_b) \ - do \ - { \ - double r__ = libclut_model_standard_to_linear1(r); \ - double g__ = libclut_model_standard_to_linear1(g); \ - double b__ = libclut_model_standard_to_linear1(b); \ - *(out_r) = libclut_model_linear_to_standard1((M)[0][0] * r__ + (M)[0][1] * g__ + (M)[0][2] * b__); \ - *(out_g) = libclut_model_linear_to_standard1((M)[1][0] * r__ + (M)[1][1] * g__ + (M)[1][2] * b__); \ - *(out_b) = libclut_model_linear_to_standard1((M)[2][0] * r__ + (M)[2][1] * g__ + (M)[2][2] * b__); \ - } \ - while (0) - - -/** - * Convert an RGB colour of a custom RGB colour space to CIE XYZ. - * - * The RGB colour space must have same gamma functions as sRGB. - * - * Requires linking with '-lclut', or '-lm' if - * `libclut_model_standard_to_linear1` is not undefined. - * - * @param r The red component. - * @param g The green component. - * @param b The blue component. - * @param M Conversion matrix, create with `libclut_model_get_rgb_conversion_matrix`, - * must not have side-effects. - * @param x Output parameter for the X component. - * @param y Output parameter for the Y component - * @param z Output parameter for the Z component. - */ -void (libclut_model_rgb_to_ciexyz)(double, double, double, libclut_colour_space_conversion_matrix_t, - double*, double*, double*); -#define libclut_model_rgb_to_ciexyz(r, g, b, M, x, y, z) \ - do \ - { \ - double r__ = libclut_model_standard_to_linear1(r); \ - double g__ = libclut_model_standard_to_linear1(g); \ - double b__ = libclut_model_standard_to_linear1(b); \ - *(x) = (M)[0][0] * r__ + (M)[0][1] * g__ + (M)[0][2] * b__; \ - *(y) = (M)[1][0] * r__ + (M)[1][1] * g__ + (M)[1][2] * b__; \ - *(z) = (M)[2][0] * r__ + (M)[2][1] * g__ + (M)[2][2] * b__; \ - } \ - while (0) - - -/** - * Convert a CIE XYZ colour to a custom RGB colour space. - * - * The RGB colour space must have same gamma functions as sRGB. - * - * Requires linking with '-lclut', or '-lm' if - * `libclut_model_linear_to_standard1` is not undefined. - * - * @param x The X component. - * @param y The Y component. - * @param z The Z component. - * @param M Conversion matrix, create with `libclut_model_get_rgb_conversion_matrix`, - * must not have side-effects. - * @param r Output parameter for the red component. - * @param g Output parameter for the green component - * @param b Output parameter for the blue component. - */ -void (libclut_model_ciexyz_to_rgb)(double, double, double, libclut_colour_space_conversion_matrix_t, - double*, double*, double*); -#define libclut_model_ciexyz_to_rgb(x, y, z, M, r, g, b) \ - do \ - { \ - double x__ = (x), y__ = (y), z__ = (z); \ - *(r) = libclut_model_linear_to_standard1((M)[0][0] * x__ + (M)[0][1] * y__ + (M)[0][2] * z__); \ - *(g) = libclut_model_linear_to_standard1((M)[1][0] * x__ + (M)[1][1] * y__ + (M)[1][2] * z__); \ - *(b) = libclut_model_linear_to_standard1((M)[2][0] * x__ + (M)[2][1] * y__ + (M)[2][2] * z__); \ - } \ - while (0) - - - -#if defined(__clang__) -# pragma GCC diagnostic pop -#endif - - -#endif - diff --git a/src/test.c b/src/test.c deleted file mode 100644 index 0ae2d50..0000000 --- a/src/test.c +++ /dev/null @@ -1,540 +0,0 @@ -/** - * Copyright © 2016 Mattias Andrée <maandree@member.fsf.org> - * - * 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 "libclut.h" - -#include <stddef.h> -#include <stdint.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <math.h> - - - -struct clut -{ - size_t red_size; - size_t green_size; - size_t blue_size; - uint16_t *red; - uint16_t *green; - uint16_t *blue; -}; - -struct dclut -{ - size_t red_size; - size_t green_size; - size_t blue_size; - double *red; - double *green; - double *blue; -}; - - - -static int clutcmp(const struct clut *a, const struct clut *b, uint16_t tol) -{ - size_t i; - if (tol == 0) - return memcmp(a->red, b->red, 3 * 256 * sizeof(uint16_t)); - for (i = 0; i < 3 * 256; i++) - if (a->red[i] > b->red[i]) - { - if (a->red[i] - b->red[i] > tol) - return +1; - } - else if (a->red[i] < b->red[i]) - { - if (b->red[i] - a->red[i] > tol) - return -1; - } - return 0; -} - - -static int dclutcmp(const struct dclut *a, const struct dclut *b, double tol) -{ - size_t i; - for (i = 0; i < 3 * 256; i++) - if (a->red[i] > b->red[i]) - { - if (a->red[i] - b->red[i] > tol) - return +1; - } - else if (a->red[i] < b->red[i]) - { - if (b->red[i] - a->red[i] > tol) - return -1; - } - return 0; -} - - -static void dumpcluts(const struct clut *a, const struct clut *b, int tol) -{ - size_t i; - uint16_t *r1 = a->red, *r2 = b->red, *g1 = a->green, *g2 = b->green, *b1 = a->blue, *b2 = b->blue; - for (i = 0; i < 256; i++) - { - if ((tol >= 0) && - (((r1[i] > r2[i]) ? (r1[i] - r2[i]) : (r2[i] - r1[i])) <= tol) && - (((g1[i] > g2[i]) ? (g1[i] - g2[i]) : (g2[i] - g1[i])) <= tol) && - (((b1[i] > b2[i]) ? (b1[i] - b2[i]) : (b2[i] - b1[i])) <= tol)) - continue; - printf("%3zu (%02zx) :: %04x - %04x ---- %04x - %04x ---- %04x - %04x\n", - i, i, r1[i], r2[i], g1[i], g2[i], b1[i], b2[i]); - } -} - - -static void dumpdcluts(const struct dclut *a, const struct dclut *b, double tol) -{ - size_t i; - double *r1 = a->red, *r2 = b->red, *g1 = a->green, *g2 = b->green, *b1 = a->blue, *b2 = b->blue; - for (i = 0; i < 256; i++) - { - if ((tol >= 0) && - (((r1[i] > r2[i]) ? (r1[i] - r2[i]) : (r2[i] - r1[i])) <= tol) && - (((g1[i] > g2[i]) ? (g1[i] - g2[i]) : (g2[i] - g1[i])) <= tol) && - (((b1[i] > b2[i]) ? (b1[i] - b2[i]) : (b2[i] - b1[i])) <= tol)) - continue; - printf("%3zu (%02zx) :: %lf - %lf ---- %lf - %lf ---- %lf - %lf\n", - i, i, r1[i], r2[i], g1[i], g2[i], b1[i], b2[i]); - } -} - - -static double make_double(double x) -{ - return x * 2; -} - - -/** - * Test libclut - * - * @return 0: All tests passed - * 1: At least one test fail - * 2: An error occurred - */ -int main(int argc, char *argv[]) -{ -#define HALF ((double)5 / 10) -#define TENTHS(x) ((double)x / 10) - - libclut_colour_space_conversion_matrix_t M, Minv; - libclut_rgb_colour_space_t srgb = LIBCLUT_RGB_COLOUR_SPACE_SRGB_INITIALISER; - libclut_rgb_colour_space_t wgrgb = LIBCLUT_RGB_COLOUR_SPACE_WIDE_GAMUT_RGB_INITIALISER; - struct clut t1, t2, t3; - struct dclut d1, d2; - size_t i, j; - int rc = 0; - double param, r, g, b, x, y, z; - - t1. red_size = t2. red_size = t3. red_size = d1. red_size = d2. red_size = 256; - t1.green_size = t2.green_size = t3.green_size = d1.green_size = d2.green_size = 256; - t1. blue_size = t2. blue_size = t3. blue_size = d1. blue_size = d2. blue_size = 256; - if (!(t1.red = malloc(3 * 256 * sizeof(uint16_t)))) goto fail; - if (!(t2.red = malloc(3 * 256 * sizeof(uint16_t)))) goto fail; - if (!(t3.red = malloc(3 * 256 * sizeof(uint16_t)))) goto fail; - if (!(d1.red = malloc(3 * 256 * sizeof(double)))) goto fail; - if (!(d2.red = malloc(3 * 256 * sizeof(double)))) goto fail; - t1.blue = (t1.green = t1.red + 256) + 256; - t2.blue = (t2.green = t2.red + 256) + 256; - t3.blue = (t3.green = t3.red + 256) + 256; - d1.blue = (d1.green = d1.red + 256) + 256; - d2.blue = (d2.green = d2.red + 256) + 256; - - - libclut_start_over(&t1, UINT16_MAX, uint16_t, 1, 1, 1); - for (i = 0; i < 256; i++) - t2.blue[i] = t2.green[i] = t2.red[i] = (uint16_t)((i << 8) | i); - if (clutcmp(&t1, &t2, 0)) - printf("libclut_start_over failed\n"), rc = 1; - - - for (i = 0, j = 255; i < 256; i++, j--) - { - t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)i; - t2.blue[j] = t2.green[j] = t2.red[j] = (uint16_t)i; - } - libclut_negative(&t1, UINT16_MAX, uint16_t, 1, 1, 1); - if (clutcmp(&t1, &t2, 0)) - printf("libclut_negative failed\n"), rc = 1; - - - for (i = 0; i < 256; i++) - { - t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)i; - t2.blue[i] = t2.green[i] = t2.red[i] = (uint16_t)(UINT16_MAX - (uint16_t)i); - } - libclut_rgb_invert(&t1, UINT16_MAX, uint16_t, 1, 1, 1); - if (clutcmp(&t1, &t2, 0)) - printf("libclut_rgb_invert failed\n"), rc = 1; - - - for (i = 0; i < 256; i++) - { - t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)((i << 8) | i); - t2.blue[i] = (uint16_t)(1 + (t2.green[i] = (uint16_t)(1 + (t2.red[i] = (uint16_t)(1000 + i))))); - } - libclut_rgb_limits(&t1, UINT16_MAX, uint16_t, 1000, 1255, 1001, 1256, 1002, 1257); - if (clutcmp(&t1, &t2, 0)) - printf("libclut_rgb_limits failed\n"), rc = 1; - - - for (i = 0; i < 256; i++) - { - t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)i; - t2.red[i] = (uint16_t)(t1.blue[i] * 2); - t2.green[i] = (uint16_t)(t1.green[i] * 3); - t2.blue[i] = (uint16_t)(t1.blue[i] * 4); - } - libclut_rgb_brightness(&t1, UINT16_MAX, uint16_t, 2, 3, 4); - if (clutcmp(&t1, &t2, 0)) - printf("libclut_rgb_brightness failed\n"), rc = 1; - - - for (i = 0; i < 256; i++) - { - t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)i; - t2.blue[i] = t2.green[i] = (uint16_t)(2 * (t2.red[i] = (uint16_t)i)); - } - libclut_manipulate(&t1, UINT16_MAX, uint16_t, (double (*)(double))(NULL), make_double, make_double); - if (clutcmp(&t1, &t2, 0)) - printf("libclut_manipulate failed\n"), rc = 1; - - - for (i = 0; i < 256; i++) - { - t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)i; - t2.blue[i] = t2.green[i] = t2.red[i] = (uint16_t)(pow((double)i / UINT16_MAX, (double)10 / 11) * UINT16_MAX); - } - libclut_gamma(&t1, UINT16_MAX, uint16_t, TENTHS(11), TENTHS(11), TENTHS(11)); - if (clutcmp(&t1, &t2, 0)) - printf("libclut_gamma failed\n"), rc = 1; - - - for (i = 0; i < 256; i++) - { - t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)((i << 8) | i); - t2.blue[i] = t2.green[i] = t2.red[i] = (uint16_t)((t1.red[i] - UINT16_MAX / 2) / 2 + UINT16_MAX / 2); - } - libclut_rgb_contrast(&t1, UINT16_MAX, uint16_t, HALF, HALF, HALF); - if (clutcmp(&t1, &t2, 1)) - printf("libclut_rgb_contrast failed\n"), rc = 1; - - - param = 2; - for (i = 0; i < 256; i++) - { - double x = (double)i / 255; - if (i % 255) - { - x = 1 / x - 1; - x = log(x); - x = HALF - x / param; - } - t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)((i << 8) | i); - t2.blue[i] = t2.green[i] = t2.red[i] = (uint16_t)(x * UINT16_MAX); - } - libclut_sigmoid(&t1, UINT16_MAX, uint16_t, ¶m, ¶m, ¶m); - t1.blue[0] = t1.green[0] = t1.red[0] = t2.red[0]; - t1.blue[255] = t1.green[255] = t1.red[255] = t2.red[255]; - if (clutcmp(&t1, &t2, 0)) - printf("libclut_sigmoid failed\n"), rc = 1; - - - for (i = 0; i < 256; i++) - { - t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)((i << 8) | i); - t2.blue[i] = t2.green[i] = t2.red[i] = t1.red[i & 0xF0] | (t1.red[i & 0xF0] >> 4); - } - libclut_lower_resolution(&t1, UINT16_MAX, uint16_t, 16, 0, 16, 0, 16, 0); - if (clutcmp(&t1, &t2, 0)) - printf("libclut_lower_resolution (x) failed\n"), rc = 1; - - - for (i = 0; i < 256; i++) - { - t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)((i << 8) | i); - t2.blue[i] = t2.green[i] = t2.red[i] = (uint16_t)((uint16_t)((double)i / 255 * 15 + HALF) * UINT16_MAX / 15); - } - libclut_lower_resolution(&t1, UINT16_MAX, uint16_t, 0, 16, 0, 16, 0, 16); - if (clutcmp(&t1, &t2, 0)) - printf("libclut_lower_resolution (y) failed\n"), rc = 1; - - - for (i = 0; i < 256; i++) - { - t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)((i << 8) | i); - t2.blue[i] = t2.green[i] = t2.red[i] = (uint16_t)((i << 8) | i); - } - libclut_linearise(&t1, UINT16_MAX, uint16_t, 1, 1, 1); - if (!clutcmp(&t1, &t2, 1)) - printf("libclut_linearise failed\n"), rc = 1; - libclut_standardise(&t1, UINT16_MAX, uint16_t, 1, 1, 1); - if (clutcmp(&t1, &t2, 12)) - printf("libclut_linearise/libclut_standardise failed\n"), rc = 1; - /* High error rate, especially at low values, are expected due - * to low precision and truncated values rather rounded values. */ - - - for (i = 0; i < 256; i++) - { - d1.blue[i] = d1.green[i] = d1.red[i] = (i & 1) ? -1 : 2; - d2.blue[i] = d2.green[i] = d2.red[i] = (i & 1) ? 0 : 1; - } - libclut_clip(&d1, 1, double, 1, 1, 1); - if (dclutcmp(&d1, &d2, 0)) - printf("libclut_clip failed\n"), rc = 1; - - - for (i = 0; i < 256; i++) - { - t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)(((255 - i) << 8) | (255 - i)); - t2.blue[i] = t2.green[i] = t2.red[i] = (uint16_t)(pow((double)i / 255, (double)10 / 11) * UINT16_MAX); - } - for (i = 0; i < 256; i++) - t3.blue[i] = t3.green[i] = t3.red[i] = t2.red[255 - i]; - libclut_apply(&t1, UINT16_MAX, uint16_t, &t2, UINT16_MAX, uint16_t, 1, 1, 1); - if (clutcmp(&t1, &t3, 0)) - printf("libclut_apply failed\n"), rc = 1; - - - if (libclut_model_get_rgb_conversion_matrix(&srgb, &wgrgb, M, Minv)) - { - printf("libclut_model_get_rgb_conversion_matrix failed\n"), rc = 1; - goto rgb_conversion_done; - } - if (0.5587 > M[0][0] || M[0][0] > 0.5589 || - 0.3587 > M[0][1] || M[0][1] > 0.3588 || - -.0101 > M[0][2] || M[0][2] > -.0099 || - 0.0938 > M[1][0] || M[1][0] > 0.0939 || - 0.8564 > M[1][1] || M[1][1] > 0.8566 || - 0.0746 > M[1][2] || M[1][2] > 0.0747 || - 0.0186 > M[2][0] || M[2][0] > 0.0188 || - 0.0967 > M[2][1] || M[2][1] > 0.0968 || - 1.2237 > M[2][2] || M[2][2] > 1.2239) - { - printf("libclut_model_get_rgb_conversion_matrix failed\n"), rc = 1; - goto rgb_conversion_done; - } - - - libclut_model_convert_rgb(0.1, 0.5, 0.9, M, &r, &g, &b); - if (0.3024 > r || r > 0.3025 || - 0.5301 > g || g > 0.5302 || - 0.9931 > b || b > 0.9932) - { - printf("libclut_model_convert_rgb failed\n"), rc = 1; - goto rgb_conversion_done; - } - - - libclut_model_convert_rgb(0.1, 0.5, 0.9, Minv, &r, &g, &b); - if (-1.3341 > r || r > -1.3339 || - 0.4916 > g || g > 0.4917 || - 0.8144 > b || b > 0.8145) - { - printf("libclut_model_convert_rgb failed\n"), rc = 1; - goto rgb_conversion_done; - } - - - libclut_convert_rgb_inplace(&t1, 1, double, M, trunc); /* TODO test */ - libclut_convert_rgb(&t1, 1, double, M, trunc, &t2); /* TODO test */ - - - if (libclut_model_get_rgb_conversion_matrix(&srgb, NULL, M, Minv)) - { - printf("libclut_model_get_rgb_conversion_matrix failed\n"), rc = 1; - goto rgb_conversion_done; - } - libclut_model_rgb_to_ciexyz(0.1, 0.5, 0.9, M, &x, &y, &z); - if (0.2227 > x || x > 0.2228 || - 0.2120 > y || y > 0.2121 || - 0.7739 > z || z > 0.7741) - { - printf("libclut_model_get_rgb_conversion_matrix or libclut_model_rgb_to_ciexyz failed\n"), rc = 1; - goto rgb_conversion_done; - } - libclut_model_ciexyz_to_rgb(x, y, z, Minv, &r, &g, &b); - if (0.0999 > r || r > 1.0001 || - 0.4999 > g || g > 0.5001 || - 0.8999 > b || b > 0.9001) - { - printf("libclut_model_get_rgb_conversion_matrix or libclut_model_ciexyz_to_rgb failed\n"), rc = 1; - goto rgb_conversion_done; - } - - - if (libclut_model_get_rgb_conversion_matrix(NULL, &srgb, Minv, M)) - { - printf("libclut_model_get_rgb_conversion_matrix failed\n"), rc = 1; - goto rgb_conversion_done; - } - libclut_model_rgb_to_ciexyz(0.1, 0.5, 0.9, M, &r, &g, &b); - libclut_model_ciexyz_to_rgb(r, g, b, Minv, &r, &g, &b); - if (0.0999 > r || r > 1.0001 || - 0.4999 > g || g > 0.5001 || - 0.8999 > b || b > 0.9001) - { - printf("libclut_model_get_rgb_conversion_matrix failed\n"), rc = 1; - goto rgb_conversion_done; - } - - - if (libclut_model_get_rgb_conversion_matrix(NULL, NULL, M, Minv)) - { - printf("libclut_model_get_rgb_conversion_matrix failed\n"), rc = 1; - goto rgb_conversion_done; - } - if (0.999999 > M[0][0] || M[0][0] > 1.000001 || - -.999999 > M[0][1] || M[0][1] > 0.000001 || - -.999999 > M[0][2] || M[0][2] > 0.000001 || - -.999999 > M[1][0] || M[1][0] > 0.000001 || - 0.999999 > M[1][1] || M[1][1] > 1.000001 || - -.999999 > M[1][2] || M[1][2] > 0.000001 || - -.999999 > M[2][0] || M[2][0] > 0.000001 || - -.999999 > M[2][1] || M[2][1] > 0.000001 || - 0.999999 > M[2][2] || M[2][2] > 1.000001) - { - printf("libclut_model_get_rgb_conversion_matrix failed\n"), rc = 1; - goto rgb_conversion_done; - } - if (0.999999 > Minv[0][0] || Minv[0][0] > 1.000001 || - -.999999 > Minv[0][1] || Minv[0][1] > 0.000001 || - -.999999 > Minv[0][2] || Minv[0][2] > 0.000001 || - -.999999 > Minv[1][0] || Minv[1][0] > 0.000001 || - 0.999999 > Minv[1][1] || Minv[1][1] > 1.000001 || - -.999999 > Minv[1][2] || Minv[1][2] > 0.000001 || - -.999999 > Minv[2][0] || Minv[2][0] > 0.000001 || - -.999999 > Minv[2][1] || Minv[2][1] > 0.000001 || - 0.999999 > Minv[2][2] || Minv[2][2] > 1.000001) - { - printf("libclut_model_get_rgb_conversion_matrix failed\n"), rc = 1; - goto rgb_conversion_done; - } - - - libclut_model_get_rgb_conversion_matrix(&srgb, &wgrgb, M, NULL); /* Just testing that we don't get a segfault. */ - rgb_conversion_done: - - - libclut_model_ciexyz_to_cieluv(0.4, 1.0, 0.7, 0.33, 1, 0.32, &x, &y, &z); /* TODO test */ - libclut_model_cieluv_to_ciexyz(x, y, z, 0.33, 1, 0.32, &x, &y, &z); - if (0.3999 > x || x > 0.4001 || - 0.9999 > y || y > 1.0001 || - 0.6999 > z || z > 0.7001) - printf("libclut_model_cieluv_to_ciexyz failed\n"), rc = 1; - - - libclut_model_cieluv_to_cielch(0.5, 0.6, &r, &g); /* TODO test */ - libclut_model_cielch_to_cieluv(r, g, &r, &g); - if (0.4999 > r || r > 0.5001 || - 0.5999 > g || g > 0.6001) - printf("libclut_model_cielch_to_cieluv failed\n"), rc = 1; - - - libclut_model_srgb_to_yiq(0.1, 0.6, 0.9, &r, &g, &b); /* TODO test */ - libclut_model_yiq_to_srgb(r, g, b, &r, &g, &b); - if (0.0999 > r || r > 0.1001 || - 0.5999 > g || g > 0.6001 || - 0.8999 > b || b > 0.9001) - printf("libclut_model_yiq_to_srgb failed\n"), rc = 1; - - - libclut_model_srgb_to_ydbdr(0.1, 0.6, 0.9, &r, &g, &b); /* TODO test */ - libclut_model_ydbdr_to_srgb(r, g, b, &r, &g, &b); - if (0.0999 > r || r > 0.1001 || - 0.5999 > g || g > 0.6001 || - 0.8999 > b || b > 0.9001) - printf("libclut_model_ydbdr_to_srgb failed\n"), rc = 1; - - - libclut_model_ydbdr_to_yuv(0.1, 0.6, &r, &g); /* TODO test */ - libclut_model_yuv_to_ydbdr(r, g, &r, &g); - if (0.0999 > r || r > 0.1001 || - 0.5999 > g || g > 0.6001) - printf("libclut_model_yuv_to_ydbdr failed\n"), rc = 1; - - - libclut_model_srgb_to_ypbpr(0.1, 0.6, 0.9, &r, &g, &b); /* TODO test */ - libclut_model_ypbpr_to_srgb(r, g, b, &r, &g, &b); - if (0.0999 > r || r > 0.1001 || - 0.5999 > g || g > 0.6001 || - 0.8999 > b || b > 0.9001) - printf("libclut_model_ypbpr_to_srgb failed\n"), rc = 1; - - - libclut_model_srgb_to_ycgco(0.1, 0.6, 0.9, &r, &g, &b); /* TODO test */ - libclut_model_ycgco_to_srgb(r, g, b, &r, &g, &b); - if (0.0999 > r || r > 0.1001 || - 0.5999 > g || g > 0.6001 || - 0.8999 > b || b > 0.9001) - printf("libclut_model_ycgco_to_srgb failed\n"), rc = 1; - - - libclut_model_ciexyz_to_cie_1960_ucs(0.4, 0.7, 0.6, &x, &y, &z); /* TODO test */ - libclut_model_cie_1960_ucs_to_ciexyz(x, y, z, &x, &y, &z); - if (0.3999 > x || x > 0.4001 || - 0.6999 > y || y > 0.7001 || - 0.5999 > z || z > 0.6001) - printf("libclut_model_cie_1960_ucs_to_ciexyz failed\n"), rc = 1; - - - libclut_model_cie_1960_ucs_to_cieuvw(0.1, 0.7, 0.9, 0.3, 0.4, &x, &y, &z); /* TODO test */ - libclut_model_cieuvw_to_cie_1960_ucs(x, y, z, 0.3, 0.4, &x, &y, &z); - if (0.0999 > x || x > 0.1001 || - 0.6999 > y || y > 0.7001 || - 0.8999 > z || z > 0.9001) - printf("libclut_model_cieuvw_to_cie_1960_ucs failed\n"), rc = 1; - - - if (!rc) - printf("everything is fine\n"); - free(t1.red); - free(t2.red); - free(t3.red); - free(d1.red); - free(d2.red); - return rc; - fail: - perror(*argv); - return 2; - (void) argc; - - (void) dumpcluts; - (void) dumpdcluts; -} - - -/* - TODO test these too: (also add this to the makefile) - - libclut_translate - libclut_cie_contrast - libclut_cie_brightness - libclut_cie_invert - libclut_cie_limits - libclut_cie_manipulate - libclut_cie_apply -*/ - @@ -0,0 +1,453 @@ +/* See LICENSE file for copyright and license details. */ +#include "libclut.h" + +#include <stddef.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> + +struct clut { + size_t red_size; + size_t green_size; + size_t blue_size; + uint16_t *red; + uint16_t *green; + uint16_t *blue; +}; + +struct dclut { + size_t red_size; + size_t green_size; + size_t blue_size; + double *red; + double *green; + double *blue; +}; + +static int +clutcmp(const struct clut *a, const struct clut *b, uint16_t tol) +{ + size_t i; + if (!tol) + return memcmp(a->red, b->red, 3 * 256 * sizeof(uint16_t)); + for (i = 0; i < 3 * 256; i++) { + if (a->red[i] > b->red[i]) { + if (a->red[i] - b->red[i] > tol) + return +1; + } else if (a->red[i] < b->red[i]) { + if (b->red[i] - a->red[i] > tol) + return -1; + } + } + return 0; +} + +static int +dclutcmp(const struct dclut *a, const struct dclut *b, double tol) +{ + size_t i; + for (i = 0; i < 3 * 256; i++) { + if (a->red[i] > b->red[i]) { + if (a->red[i] - b->red[i] > tol) + return +1; + } else if (a->red[i] < b->red[i]) { + if (b->red[i] - a->red[i] > tol) + return -1; + } + } + return 0; +} + +static void +dumpcluts(const struct clut *a, const struct clut *b, int tol) +{ + size_t i; + uint16_t *r1 = a->red, *r2 = b->red, *g1 = a->green, *g2 = b->green, *b1 = a->blue, *b2 = b->blue; + for (i = 0; i < 256; i++) { + if ((tol >= 0) && + (((r1[i] > r2[i]) ? (r1[i] - r2[i]) : (r2[i] - r1[i])) <= tol) && + (((g1[i] > g2[i]) ? (g1[i] - g2[i]) : (g2[i] - g1[i])) <= tol) && + (((b1[i] > b2[i]) ? (b1[i] - b2[i]) : (b2[i] - b1[i])) <= tol)) + continue; + printf("%3zu (%02zx) :: %04x - %04x ---- %04x - %04x ---- %04x - %04x\n", + i, i, r1[i], r2[i], g1[i], g2[i], b1[i], b2[i]); + } +} + +static void +dumpdcluts(const struct dclut *a, const struct dclut *b, double tol) +{ + size_t i; + double *r1 = a->red, *r2 = b->red, *g1 = a->green, *g2 = b->green, *b1 = a->blue, *b2 = b->blue; + for (i = 0; i < 256; i++) { + if ((tol >= 0) && + (((r1[i] > r2[i]) ? (r1[i] - r2[i]) : (r2[i] - r1[i])) <= tol) && + (((g1[i] > g2[i]) ? (g1[i] - g2[i]) : (g2[i] - g1[i])) <= tol) && + (((b1[i] > b2[i]) ? (b1[i] - b2[i]) : (b2[i] - b1[i])) <= tol)) + continue; + printf("%3zu (%02zx) :: %lf - %lf ---- %lf - %lf ---- %lf - %lf\n", + i, i, r1[i], r2[i], g1[i], g2[i], b1[i], b2[i]); + } +} + +static double +make_double(double x) +{ + return x * 2; +} + + +/** + * Test libclut + * + * @return 0: All tests passed + * 1: At least one test fail + * 2: An error occurred + */ +int +main(int argc, char *argv[]) +{ +#define HALF ((double)5 / 10) +#define TENTHS(x) ((double)x / 10) + + libclut_colour_space_conversion_matrix_t M, Minv; + libclut_rgb_colour_space_t srgb = LIBCLUT_RGB_COLOUR_SPACE_SRGB_INITIALISER; + libclut_rgb_colour_space_t wgrgb = LIBCLUT_RGB_COLOUR_SPACE_WIDE_GAMUT_RGB_INITIALISER; + struct clut t1, t2, t3; + struct dclut d1, d2; + size_t i, j; + int rc = 0; + double param, r, g, b, x, y, z; + + t1. red_size = t2. red_size = t3. red_size = d1. red_size = d2. red_size = 256; + t1.green_size = t2.green_size = t3.green_size = d1.green_size = d2.green_size = 256; + t1. blue_size = t2. blue_size = t3. blue_size = d1. blue_size = d2. blue_size = 256; + if (!(t1.red = malloc(3 * 256 * sizeof(uint16_t)))) goto fail; + if (!(t2.red = malloc(3 * 256 * sizeof(uint16_t)))) goto fail; + if (!(t3.red = malloc(3 * 256 * sizeof(uint16_t)))) goto fail; + if (!(d1.red = malloc(3 * 256 * sizeof(double)))) goto fail; + if (!(d2.red = malloc(3 * 256 * sizeof(double)))) goto fail; + t1.blue = (t1.green = t1.red + 256) + 256; + t2.blue = (t2.green = t2.red + 256) + 256; + t3.blue = (t3.green = t3.red + 256) + 256; + d1.blue = (d1.green = d1.red + 256) + 256; + d2.blue = (d2.green = d2.red + 256) + 256; + + libclut_start_over(&t1, UINT16_MAX, uint16_t, 1, 1, 1); + for (i = 0; i < 256; i++) + t2.blue[i] = t2.green[i] = t2.red[i] = (uint16_t)((i << 8) | i); + if (clutcmp(&t1, &t2, 0)) + printf("libclut_start_over failed\n"), rc = 1; + + for (i = 0, j = 255; i < 256; i++, j--) { + t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)i; + t2.blue[j] = t2.green[j] = t2.red[j] = (uint16_t)i; + } + libclut_negative(&t1, UINT16_MAX, uint16_t, 1, 1, 1); + if (clutcmp(&t1, &t2, 0)) + printf("libclut_negative failed\n"), rc = 1; + + for (i = 0; i < 256; i++) { + t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)i; + t2.blue[i] = t2.green[i] = t2.red[i] = (uint16_t)(UINT16_MAX - (uint16_t)i); + } + libclut_rgb_invert(&t1, UINT16_MAX, uint16_t, 1, 1, 1); + if (clutcmp(&t1, &t2, 0)) + printf("libclut_rgb_invert failed\n"), rc = 1; + + for (i = 0; i < 256; i++) { + t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)((i << 8) | i); + t2.blue[i] = (uint16_t)(1 + (t2.green[i] = (uint16_t)(1 + (t2.red[i] = (uint16_t)(1000 + i))))); + } + libclut_rgb_limits(&t1, UINT16_MAX, uint16_t, 1000, 1255, 1001, 1256, 1002, 1257); + if (clutcmp(&t1, &t2, 0)) + printf("libclut_rgb_limits failed\n"), rc = 1; + + for (i = 0; i < 256; i++) { + t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)i; + t2.red[i] = (uint16_t)(t1.blue[i] * 2); + t2.green[i] = (uint16_t)(t1.green[i] * 3); + t2.blue[i] = (uint16_t)(t1.blue[i] * 4); + } + libclut_rgb_brightness(&t1, UINT16_MAX, uint16_t, 2, 3, 4); + if (clutcmp(&t1, &t2, 0)) + printf("libclut_rgb_brightness failed\n"), rc = 1; + + for (i = 0; i < 256; i++) { + t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)i; + t2.blue[i] = t2.green[i] = (uint16_t)(2 * (t2.red[i] = (uint16_t)i)); + } + libclut_manipulate(&t1, UINT16_MAX, uint16_t, (double (*)(double))(NULL), make_double, make_double); + if (clutcmp(&t1, &t2, 0)) + printf("libclut_manipulate failed\n"), rc = 1; + + for (i = 0; i < 256; i++) { + t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)i; + t2.blue[i] = t2.green[i] = t2.red[i] = (uint16_t)(pow((double)i / UINT16_MAX, (double)10 / 11) * UINT16_MAX); + } + libclut_gamma(&t1, UINT16_MAX, uint16_t, TENTHS(11), TENTHS(11), TENTHS(11)); + if (clutcmp(&t1, &t2, 0)) + printf("libclut_gamma failed\n"), rc = 1; + + for (i = 0; i < 256; i++) { + t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)((i << 8) | i); + t2.blue[i] = t2.green[i] = t2.red[i] = (uint16_t)((t1.red[i] - UINT16_MAX / 2) / 2 + UINT16_MAX / 2); + } + libclut_rgb_contrast(&t1, UINT16_MAX, uint16_t, HALF, HALF, HALF); + if (clutcmp(&t1, &t2, 1)) + printf("libclut_rgb_contrast failed\n"), rc = 1; + + param = 2; + for (i = 0; i < 256; i++) { + double x = (double)i / 255; + if (i % 255) { + x = 1 / x - 1; + x = log(x); + x = HALF - x / param; + } + t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)((i << 8) | i); + t2.blue[i] = t2.green[i] = t2.red[i] = (uint16_t)(x * UINT16_MAX); + } + libclut_sigmoid(&t1, UINT16_MAX, uint16_t, ¶m, ¶m, ¶m); + t1.blue[0] = t1.green[0] = t1.red[0] = t2.red[0]; + t1.blue[255] = t1.green[255] = t1.red[255] = t2.red[255]; + if (clutcmp(&t1, &t2, 0)) + printf("libclut_sigmoid failed\n"), rc = 1; + + for (i = 0; i < 256; i++) { + t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)((i << 8) | i); + t2.blue[i] = t2.green[i] = t2.red[i] = t1.red[i & 0xF0] | (t1.red[i & 0xF0] >> 4); + } + libclut_lower_resolution(&t1, UINT16_MAX, uint16_t, 16, 0, 16, 0, 16, 0); + if (clutcmp(&t1, &t2, 0)) + printf("libclut_lower_resolution (x) failed\n"), rc = 1; + + for (i = 0; i < 256; i++) { + t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)((i << 8) | i); + t2.blue[i] = t2.green[i] = t2.red[i] = (uint16_t)((uint16_t)((double)i / 255 * 15 + HALF) * UINT16_MAX / 15); + } + libclut_lower_resolution(&t1, UINT16_MAX, uint16_t, 0, 16, 0, 16, 0, 16); + if (clutcmp(&t1, &t2, 0)) + printf("libclut_lower_resolution (y) failed\n"), rc = 1; + + for (i = 0; i < 256; i++) { + t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)((i << 8) | i); + t2.blue[i] = t2.green[i] = t2.red[i] = (uint16_t)((i << 8) | i); + } + libclut_linearise(&t1, UINT16_MAX, uint16_t, 1, 1, 1); + if (!clutcmp(&t1, &t2, 1)) + printf("libclut_linearise failed\n"), rc = 1; + libclut_standardise(&t1, UINT16_MAX, uint16_t, 1, 1, 1); + if (clutcmp(&t1, &t2, 12)) + printf("libclut_linearise/libclut_standardise failed\n"), rc = 1; + /* High error rate, especially at low values, are expected due + * to low precision and truncated values rather rounded values. */ + + for (i = 0; i < 256; i++) { + d1.blue[i] = d1.green[i] = d1.red[i] = (i & 1) ? -1 : 2; + d2.blue[i] = d2.green[i] = d2.red[i] = (i & 1) ? 0 : 1; + } + libclut_clip(&d1, 1, double, 1, 1, 1); + if (dclutcmp(&d1, &d2, 0)) + printf("libclut_clip failed\n"), rc = 1; + + for (i = 0; i < 256; i++) { + t1.blue[i] = t1.green[i] = t1.red[i] = (uint16_t)(((255 - i) << 8) | (255 - i)); + t2.blue[i] = t2.green[i] = t2.red[i] = (uint16_t)(pow((double)i / 255, (double)10 / 11) * UINT16_MAX); + } + for (i = 0; i < 256; i++) + t3.blue[i] = t3.green[i] = t3.red[i] = t2.red[255 - i]; + libclut_apply(&t1, UINT16_MAX, uint16_t, &t2, UINT16_MAX, uint16_t, 1, 1, 1); + if (clutcmp(&t1, &t3, 0)) + printf("libclut_apply failed\n"), rc = 1; + + if (libclut_model_get_rgb_conversion_matrix(&srgb, &wgrgb, M, Minv)) { + printf("libclut_model_get_rgb_conversion_matrix failed\n"), rc = 1; + goto rgb_conversion_done; + } + if (0.5587 > M[0][0] || M[0][0] > 0.5589 || + 0.3587 > M[0][1] || M[0][1] > 0.3588 || + -.0101 > M[0][2] || M[0][2] > -.0099 || + 0.0938 > M[1][0] || M[1][0] > 0.0939 || + 0.8564 > M[1][1] || M[1][1] > 0.8566 || + 0.0746 > M[1][2] || M[1][2] > 0.0747 || + 0.0186 > M[2][0] || M[2][0] > 0.0188 || + 0.0967 > M[2][1] || M[2][1] > 0.0968 || + 1.2237 > M[2][2] || M[2][2] > 1.2239) { + printf("libclut_model_get_rgb_conversion_matrix failed\n"), rc = 1; + goto rgb_conversion_done; + } + + libclut_model_convert_rgb(0.1, 0.5, 0.9, M, &r, &g, &b); + if (0.3024 > r || r > 0.3025 || + 0.5301 > g || g > 0.5302 || + 0.9931 > b || b > 0.9932) { + printf("libclut_model_convert_rgb failed\n"), rc = 1; + goto rgb_conversion_done; + } + + libclut_model_convert_rgb(0.1, 0.5, 0.9, Minv, &r, &g, &b); + if (-1.3341 > r || r > -1.3339 || + 0.4916 > g || g > 0.4917 || + 0.8144 > b || b > 0.8145) { + printf("libclut_model_convert_rgb failed\n"), rc = 1; + goto rgb_conversion_done; + } + + libclut_convert_rgb_inplace(&t1, 1, double, M, trunc); /* TODO test */ + libclut_convert_rgb(&t1, 1, double, M, trunc, &t2); /* TODO test */ + + if (libclut_model_get_rgb_conversion_matrix(&srgb, NULL, M, Minv)) { + printf("libclut_model_get_rgb_conversion_matrix failed\n"), rc = 1; + goto rgb_conversion_done; + } + libclut_model_rgb_to_ciexyz(0.1, 0.5, 0.9, M, &x, &y, &z); + if (0.2227 > x || x > 0.2228 || + 0.2120 > y || y > 0.2121 || + 0.7739 > z || z > 0.7741) { + printf("libclut_model_get_rgb_conversion_matrix or libclut_model_rgb_to_ciexyz failed\n"), rc = 1; + goto rgb_conversion_done; + } + libclut_model_ciexyz_to_rgb(x, y, z, Minv, &r, &g, &b); + if (0.0999 > r || r > 1.0001 || + 0.4999 > g || g > 0.5001 || + 0.8999 > b || b > 0.9001) { + printf("libclut_model_get_rgb_conversion_matrix or libclut_model_ciexyz_to_rgb failed\n"), rc = 1; + goto rgb_conversion_done; + } + + if (libclut_model_get_rgb_conversion_matrix(NULL, &srgb, Minv, M)) { + printf("libclut_model_get_rgb_conversion_matrix failed\n"), rc = 1; + goto rgb_conversion_done; + } + libclut_model_rgb_to_ciexyz(0.1, 0.5, 0.9, M, &r, &g, &b); + libclut_model_ciexyz_to_rgb(r, g, b, Minv, &r, &g, &b); + if (0.0999 > r || r > 1.0001 || + 0.4999 > g || g > 0.5001 || + 0.8999 > b || b > 0.9001) { + printf("libclut_model_get_rgb_conversion_matrix failed\n"), rc = 1; + goto rgb_conversion_done; + } + + if (libclut_model_get_rgb_conversion_matrix(NULL, NULL, M, Minv)) { + printf("libclut_model_get_rgb_conversion_matrix failed\n"), rc = 1; + goto rgb_conversion_done; + } + if (0.999999 > M[0][0] || M[0][0] > 1.000001 || + -.999999 > M[0][1] || M[0][1] > 0.000001 || + -.999999 > M[0][2] || M[0][2] > 0.000001 || + -.999999 > M[1][0] || M[1][0] > 0.000001 || + 0.999999 > M[1][1] || M[1][1] > 1.000001 || + -.999999 > M[1][2] || M[1][2] > 0.000001 || + -.999999 > M[2][0] || M[2][0] > 0.000001 || + -.999999 > M[2][1] || M[2][1] > 0.000001 || + 0.999999 > M[2][2] || M[2][2] > 1.000001) { + printf("libclut_model_get_rgb_conversion_matrix failed\n"), rc = 1; + goto rgb_conversion_done; + } + if (0.999999 > Minv[0][0] || Minv[0][0] > 1.000001 || + -.999999 > Minv[0][1] || Minv[0][1] > 0.000001 || + -.999999 > Minv[0][2] || Minv[0][2] > 0.000001 || + -.999999 > Minv[1][0] || Minv[1][0] > 0.000001 || + 0.999999 > Minv[1][1] || Minv[1][1] > 1.000001 || + -.999999 > Minv[1][2] || Minv[1][2] > 0.000001 || + -.999999 > Minv[2][0] || Minv[2][0] > 0.000001 || + -.999999 > Minv[2][1] || Minv[2][1] > 0.000001 || + 0.999999 > Minv[2][2] || Minv[2][2] > 1.000001) { + printf("libclut_model_get_rgb_conversion_matrix failed\n"), rc = 1; + goto rgb_conversion_done; + } + + libclut_model_get_rgb_conversion_matrix(&srgb, &wgrgb, M, NULL); /* Just testing that we don't get a segfault. */ +rgb_conversion_done: + + libclut_model_ciexyz_to_cieluv(0.4, 1.0, 0.7, 0.33, 1, 0.32, &x, &y, &z); /* TODO test */ + libclut_model_cieluv_to_ciexyz(x, y, z, 0.33, 1, 0.32, &x, &y, &z); + if (0.3999 > x || x > 0.4001 || + 0.9999 > y || y > 1.0001 || + 0.6999 > z || z > 0.7001) + printf("libclut_model_cieluv_to_ciexyz failed\n"), rc = 1; + + libclut_model_cieluv_to_cielch(0.5, 0.6, &r, &g); /* TODO test */ + libclut_model_cielch_to_cieluv(r, g, &r, &g); + if (0.4999 > r || r > 0.5001 || + 0.5999 > g || g > 0.6001) + printf("libclut_model_cielch_to_cieluv failed\n"), rc = 1; + + libclut_model_srgb_to_yiq(0.1, 0.6, 0.9, &r, &g, &b); /* TODO test */ + libclut_model_yiq_to_srgb(r, g, b, &r, &g, &b); + if (0.0999 > r || r > 0.1001 || + 0.5999 > g || g > 0.6001 || + 0.8999 > b || b > 0.9001) + printf("libclut_model_yiq_to_srgb failed\n"), rc = 1; + + libclut_model_srgb_to_ydbdr(0.1, 0.6, 0.9, &r, &g, &b); /* TODO test */ + libclut_model_ydbdr_to_srgb(r, g, b, &r, &g, &b); + if (0.0999 > r || r > 0.1001 || + 0.5999 > g || g > 0.6001 || + 0.8999 > b || b > 0.9001) + printf("libclut_model_ydbdr_to_srgb failed\n"), rc = 1; + + libclut_model_ydbdr_to_yuv(0.1, 0.6, &r, &g); /* TODO test */ + libclut_model_yuv_to_ydbdr(r, g, &r, &g); + if (0.0999 > r || r > 0.1001 || + 0.5999 > g || g > 0.6001) + printf("libclut_model_yuv_to_ydbdr failed\n"), rc = 1; + + libclut_model_srgb_to_ypbpr(0.1, 0.6, 0.9, &r, &g, &b); /* TODO test */ + libclut_model_ypbpr_to_srgb(r, g, b, &r, &g, &b); + if (0.0999 > r || r > 0.1001 || + 0.5999 > g || g > 0.6001 || + 0.8999 > b || b > 0.9001) + printf("libclut_model_ypbpr_to_srgb failed\n"), rc = 1; + + libclut_model_srgb_to_ycgco(0.1, 0.6, 0.9, &r, &g, &b); /* TODO test */ + libclut_model_ycgco_to_srgb(r, g, b, &r, &g, &b); + if (0.0999 > r || r > 0.1001 || + 0.5999 > g || g > 0.6001 || + 0.8999 > b || b > 0.9001) + printf("libclut_model_ycgco_to_srgb failed\n"), rc = 1; + + libclut_model_ciexyz_to_cie_1960_ucs(0.4, 0.7, 0.6, &x, &y, &z); /* TODO test */ + libclut_model_cie_1960_ucs_to_ciexyz(x, y, z, &x, &y, &z); + if (0.3999 > x || x > 0.4001 || + 0.6999 > y || y > 0.7001 || + 0.5999 > z || z > 0.6001) + printf("libclut_model_cie_1960_ucs_to_ciexyz failed\n"), rc = 1; + + libclut_model_cie_1960_ucs_to_cieuvw(0.1, 0.7, 0.9, 0.3, 0.4, &x, &y, &z); /* TODO test */ + libclut_model_cieuvw_to_cie_1960_ucs(x, y, z, 0.3, 0.4, &x, &y, &z); + if (0.0999 > x || x > 0.1001 || + 0.6999 > y || y > 0.7001 || + 0.8999 > z || z > 0.9001) + printf("libclut_model_cieuvw_to_cie_1960_ucs failed\n"), rc = 1; + + if (!rc) + printf("everything is fine\n"); + free(t1.red); + free(t2.red); + free(t3.red); + free(d1.red); + free(d2.red); + return rc; + fail: + perror(*argv); + return 2; + (void) argc; + (void) dumpcluts; + (void) dumpdcluts; +} + +/* + TODO test these too: (also add this to the makefile) + + libclut_translate + libclut_cie_contrast + libclut_cie_brightness + libclut_cie_invert + libclut_cie_limits + libclut_cie_manipulate + libclut_cie_apply +*/ |