From 3be28b4e8f75190d30e311f0e69da714cac62cc5 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 21 Jul 2022 14:53:18 +0200 Subject: Change license to ISC, change style, improve makefile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- .gitignore | 19 +- COPYING | 15 - DEPENDENCIES | 1 - LICENSE | 683 +----------------- Makefile | 210 ++---- README | 1 - config.mk | 10 + include-libgamma.h | 2 + libgamma.py | 4 + libgamma_error.py | 453 ++++++++++++ libgamma_facade.py | 126 ++++ libgamma_method.py | 1093 +++++++++++++++++++++++++++++ libgamma_native_error.posix.pyx | 188 +++++ libgamma_native_error.w32.pyx | 167 +++++ libgamma_native_facade.pyx | 1297 ++++++++++++++++++++++++++++++++++ libgamma_native_method.pyx | 616 ++++++++++++++++ mk/linux.mk | 2 + mk/macos.mk | 2 + mk/windows.mk | 2 + src/include-libgamma.h | 19 - src/libgamma.py | 23 - src/libgamma_error.py | 476 ------------- src/libgamma_facade.py | 147 ---- src/libgamma_method.py | 1117 ----------------------------- src/libgamma_native_error.pyx | 205 ------ src/libgamma_native_error.w32.pyx | 183 ----- src/libgamma_native_facade.pyx | 1389 ------------------------------------- src/libgamma_native_method.pyx | 682 ------------------ src/test.py | 124 ---- test.py | 105 +++ 30 files changed, 4129 insertions(+), 5232 deletions(-) delete mode 100644 COPYING create mode 100644 config.mk create mode 100644 include-libgamma.h create mode 100644 libgamma.py create mode 100644 libgamma_error.py create mode 100644 libgamma_facade.py create mode 100644 libgamma_method.py create mode 100644 libgamma_native_error.posix.pyx create mode 100644 libgamma_native_error.w32.pyx create mode 100644 libgamma_native_facade.pyx create mode 100644 libgamma_native_method.pyx create mode 100644 mk/linux.mk create mode 100644 mk/macos.mk create mode 100644 mk/windows.mk delete mode 100644 src/include-libgamma.h delete mode 100644 src/libgamma.py delete mode 100644 src/libgamma_error.py delete mode 100644 src/libgamma_facade.py delete mode 100644 src/libgamma_method.py delete mode 100644 src/libgamma_native_error.pyx delete mode 100644 src/libgamma_native_error.w32.pyx delete mode 100644 src/libgamma_native_facade.pyx delete mode 100644 src/libgamma_native_method.pyx delete mode 100755 src/test.py create mode 100755 test.py diff --git a/.gitignore b/.gitignore index cbc0dc0..b6f2c48 100644 --- a/.gitignore +++ b/.gitignore @@ -1,18 +1,17 @@ -_/ -bin/ -obj/ -\#*\# -.* -!.git* +*\#* *~ __pycache__/ *.bak -*.sw[op] +*.swo +*.swp *.o *.out *.su *.so +*.dll +*.dylib *.gch -*.py[co] -src/*_native_*.c - +*.pyo +*.pyo +*_native_*.c +/libgamma_native_error.pyx diff --git a/COPYING b/COPYING deleted file mode 100644 index eac493e..0000000 --- a/COPYING +++ /dev/null @@ -1,15 +0,0 @@ -pylibgamma — Python 3 wrapper for libgamma -Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) - -This library 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 library 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 library. If not, see . diff --git a/DEPENDENCIES b/DEPENDENCIES index 217abad..3acdb68 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -21,4 +21,3 @@ INSTALL DEPENDENCIES: make coreutils - diff --git a/LICENSE b/LICENSE index 94a9ed0..d3ebfaa 100644 --- a/LICENSE +++ b/LICENSE @@ -1,674 +1,15 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 +ISC License - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. +© 2014, 2022 Mattias Andrée - Preamble +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 GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. +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 index df1e521..ab06f19 100644 --- a/Makefile +++ b/Makefile @@ -1,190 +1,62 @@ -# 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. +.POSIX: +CONFIGFILE = config.mk +include $(CONFIGFILE) -# The package path prefix, if you want to install to another root, set DESTDIR to that root -PREFIX ?= /usr -# The library path excluding prefix -LIB ?= /lib -# The resource path excluding prefix -DATA ?= /share -# The library path including prefix -LIBDIR ?= $(PREFIX)$(LIB) -# The resource path including prefix -DATADIR ?= $(PREFIX)$(DATA) -# The generic documentation path including prefix -DOCDIR ?= $(DATADIR)/doc -# The info manual documentation path including prefix -INFODIR ?= $(DATADIR)/info -# The license base path including prefix -LICENSEDIR ?= $(DATADIR)/licenses +OS = linux +include mk/$(OS).mk -# The target and host platform -PLATFORM = posix -# The major version number of the current Python installation -PY_MAJOR = 3 -# The minor version number of the current Python installation -PY_MINOR = 5 -# The version number of the current Python installation without a dot -PY_VER = $(PY_MAJOR)$(PY_MINOR) -# The version number of the current Python installation with a dot -PY_VERSION = $(PY_MAJOR).$(PY_MINOR) +python = python$(PYTHON_MAJOR) +python_version = $(PYTHON_MAJOR).$(PYTHON_MINOR) +python_ver = $(PYTHON_MAJOR)$(PYTHON_MINOR) +python_dir = $(PREFIX)/lib/python$(python_version)/site-packages +python_cache = $(python_dir)/__pycache__ -# The directory for python modules -PYTHONDIR = $(LIBDIR)/python$(PY_VERSION) -# The name of the package as it should be installed -PKGNAME = pylibgamma +OBJ =\ + libgamma_native_error.o\ + libgamma_native_facade.o\ + libgamma_native_method.o +PYSRC =\ + libgamma.py\ + libgamma_error.py\ + libgamma_facade.py\ + libgamma_method.py -# The installed pkg-config command -PKGCONFIG ?= pkg-config -# The installed cython command -CYTHON ?= cython -# The installed python command -PYTHON = python$(PY_MAJOR) +LIBFILES = $(OBJ:.o=.$(LIBEXT)) +FILES = $(PYSRC) $(LIBFILES) -# Libraries to link with using pkg-config -LIBS = python$(PY_MAJOR) +all: $(LIBFILES) -# The C standard for C code compilation -STD = c99 -# Optimisation settings for C code compilation -OPTIMISE ?= -Og -g +libgamma_native_error.pyx: libgamma_native_error.$(PLATFORM).pyx + cp -- $< $@ +.o.$(LIBEXT): + $(CC) -o $@ $< -shared $(LDFLAGS) +.c.o: + $(CC) -fPIC -c -o $@ $< $$(pkg-config --cflags $(python)) $(CFLAGS) $(CPPFLAGS) -# Flags to use when compiling -CC_FLAGS = $$($(PKGCONFIG) --cflags $(LIBS)) -std=$(STD) \ - $(OPTIMISE) -fPIC $(CFLAGS) $(CPPFLAGS) +.pyx.c: + if ! cython -$(PYTHON_MAJOR) -v $< -o $@ ; then rm $@; false; fi -# Flags to use when linking -LD_FLAGS = $$($(PKGCONFIG) --libs $(LIBS)) -lgamma -std=$(STD) \ - $(OPTIMISE) -shared $(LDFLAGS) +install: $(LIBFILES) + mkdir -p -- "$(DESTDIR)$(python_dir)" + cp -- $(FILES) "$(DESTDIR)$(python_dir)/" - -# The suffixless basename of the .py-files -PYTHON_SRC = libgamma_error libgamma_facade libgamma_method libgamma - -# The suffixless basename of the .py-files -CYTHON_SRC = libgamma_native_error libgamma_native_facade libgamma_native_method - - -# Filename extension for -OO optimised python files -ifeq ($(shell test $(PY_VER) -ge 35 ; echo $$?),0) -PY_OPT2_EXT = opt-2.pyc -else -PY_OPT2_EXT = pyo -endif - - - -.PHONY: all pyc-files pyo-files so-files -all: pyc-files pyo-files so-files -pyc-files: $(foreach M,$(PYTHON_SRC),src/__pycache__/$(M).cpython-$(PY_VER).pyc) -pyo-files: $(foreach M,$(PYTHON_SRC),src/__pycache__/$(M).cpython-$(PY_VER).$(PY_OPT2_EXT)) -so-files: $(foreach M,$(CYTHON_SRC),bin/$(M).so) - -bin/%.so: obj/%.o - @mkdir -p bin - $(CC) $(LD_FLAGS) -o $@ $^ - -obj/%.o: obj/%.c src/*.h - $(CC) $(CC_FLAGS) -iquote"src" -c -o $@ $< - -obj/%.c: obj/%.pyx - if ! $(CYTHON) -3 -v $< ; then rm $@ ; false ; fi - -obj/libgamma_native_facade.pyx: src/libgamma_native_facade.pyx - @mkdir -p obj - cp $< $@ - -obj/libgamma_native_method.pyx: src/libgamma_native_method.pyx - @mkdir -p obj - cp $< $@ - -ifeq ($(PLATFORM),windows) -obj/libgamma_native_error.pyx: src/libgamma_native_error.w32.pyx - @mkdir -p obj - cp $< $@ -else -obj/libgamma_native_error.pyx: src/libgamma_native_error.pyx - @mkdir -p obj - cp $< $@ -endif - -src/__pycache__/%.cpython-$(PY_VER).pyc: src/%.py - $(PYTHON) -m compileall $< - -src/__pycache__/%.cpython-$(PY_VER).$(PY_OPT2_EXT): src/%.py - $(PYTHON) -OO -m compileall $< - - -.PHONY: install -install: install-base - -.PHONY: install-all -install-all: install-base - -.PHONY: install-base -install-base: install-lib install-copyright - - -.PHONY: install-lib -install-lib: install-source install-compiled install-optimised install-native - -.PHONY: install-source -install-source: $(foreach M,$(PYTHON_SRC),src/$(M).py) - install -dm755 -- "$(DESTDIR)$(PYTHONDIR)" - install -m644 $^ -- "$(DESTDIR)$(PYTHONDIR)" - -.PHONY: install-compiled -install-compiled: $(foreach M,$(PYTHON_SRC),src/__pycache__/$(M).cpython-$(PY_VER).pyc) - install -dm755 -- "$(DESTDIR)$(PYTHONDIR)/__pycache__" - install -m644 $^ -- "$(DESTDIR)$(PYTHONDIR)/__pycache__" - -.PHONY: install-optimised -install-optimised: $(foreach M,$(PYTHON_SRC),src/__pycache__/$(M).cpython-$(PY_VER).$(PY_OPT2_EXT)) - install -dm755 -- "$(DESTDIR)$(PYTHONDIR)/__pycache__" - install -m644 $^ -- "$(DESTDIR)$(PYTHONDIR)/__pycache__" - -.PHONY: install-native -install-native: $(foreach M,$(CYTHON_SRC),bin/$(M).so) - install -dm755 -- "$(DESTDIR)$(PYTHONDIR)" - install -m755 $^ -- "$(DESTDIR)$(PYTHONDIR)" - - -.PHONY: install-copyright -install-copyright: install-copying install-license - -.PHONY: install-copying -install-copying: COPYING - install -dm755 -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)" - install -m644 $^ -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)" - -.PHONY: install-license -install-license: LICENSE - install -dm755 -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)" - install -m644 $^ -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)" - - - -.PHONY: uninstall uninstall: - -rm -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)/LICENSE" - -rm -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)/COPYING" - -rmdir -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)" - -rm -- $(foreach M,$(PYTHON_SRC),"$(DESTDIR)$(PYTHONDIR)/__pycache__/$(M).cpython-$(PY_VER).$(PY_OPT2_EXT)") - -rm -- $(foreach M,$(PYTHON_SRC),"$(DESTDIR)$(PYTHONDIR)/__pycache__/$(M).cpython-$(PY_VER).pyc") - -rm -- $(foreach M,$(PYTHON_SRC),"$(DESTDIR)$(PYTHONDIR)/$(M).py") - -rm -- $(foreach M,$(CYTHON_SRC),"$(DESTDIR)$(PYTHONDIR)/$(M).so") + -cd -- "$(DESTDIR)$(python_dir)" && rm -f -- $(FILES) +run-test: $(LIBFILES) + ./test.py -.PHONY: clean clean: - -rm -r obj bin src/__pycache__ + -rm -rf -- *.$(LIBEXT) *.o *_native_*.c *.pyc *.pyo __pycache__ libgamma_native_error.pyx + +.SUFFIXES: +.SUFFIXES: .$(LIBEXT) .o .c .pyx +.PHONY: all install uninstall check run-test clean diff --git a/README b/README index 99ab71e..55c4546 100644 --- a/README +++ b/README @@ -10,4 +10,3 @@ SEE ALSO libgamma(7) Full documentation available locally via the command help in python(1). - diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..51eba37 --- /dev/null +++ b/config.mk @@ -0,0 +1,10 @@ +PREFIX = /usr + +PYTHON_MAJOR = $$(python --version 2>&1 | cut -d . -f 1 | cut -d ' ' -f 2) +PYTHON_MINOR = $$(python$(PYTHON_MAJOR) --version 2>&1 | cut -d . -f 2) + +CC = c99 + +CPPFLAGS = +CFLAGS = +LDFLAGS = -lgamma diff --git a/include-libgamma.h b/include-libgamma.h new file mode 100644 index 0000000..bd1a562 --- /dev/null +++ b/include-libgamma.h @@ -0,0 +1,2 @@ +/* See LICENSE file for copyright and license details. */ +#include diff --git a/libgamma.py b/libgamma.py new file mode 100644 index 0000000..fd0e7ae --- /dev/null +++ b/libgamma.py @@ -0,0 +1,4 @@ +# See LICENSE file for copyright and license details. +from libgamma_error import * +from libgamma_method import * +from libgamma_facade import * diff --git a/libgamma_error.py b/libgamma_error.py new file mode 100644 index 0000000..bd3a9aa --- /dev/null +++ b/libgamma_error.py @@ -0,0 +1,453 @@ +# See LICENSE file for copyright and license details. + +class LibgammaGroup: + ''' + Class for `group` + ''' + + @property + def gid(self) -> int: + ''' + Getter + + Group that the user needs to be a member of if + `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned + ''' + from libgamma_native_error import libgamma_native_get_group_gid + return libgamma_native_get_group_gid() + + @gid.setter + def gid(self, value : int): + ''' + Setter + + Group that the user needs to be a member of if + `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned + ''' + from libgamma_native_error import libgamma_native_set_group_gid + libgamma_native_set_group_gid(value) + + + @property + def name(self) -> str: + ''' + Getter + + Group that the user needs to be a member of if + `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, + `None` if the name of the group `group.gid` + cannot be determined + ''' + from libgamma_native_error import libgamma_native_get_group_name + return libgamma_native_get_group_name() + + @name.setter + def name(self, value : str): + ''' + Setter + + Group that the user needs to be a member of if + `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, + `None` if the name of the group `group.gid` + cannot be determined + ''' + from libgamma_native_error import libgamma_native_set_group_name + libgamma_native_set_group_name(value) + + +group = LibgammaGroup() +''' + Group that the user needs to be a member of if +`LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned +''' + + +def perror(name : str, error_code : int): + ''' + Prints an error to stderr in a `perror` fashion, + however this function will not translate the `libgamma` + errors into human-readable strings, it will simply + print the name of the error. If the value `error_code` + is the value of `LIBGAMMA_ERRNO_SET`, `perror` will be + used to print the current error stored in `errno`. + If `error_code` is non-negative (an `errno` value`), that + value will be stored in `errno` and `perror` will be + used to print it. Additionally, if the `error_code` is + the value of `LIBGAMMA_DEVICE_REQUIRE_GROUP` the + required group will be printed with its numerical value + and, if known, its name. + + @param name The text to add at the beginning + @param value The error code, may be an `errno` value + ''' + from libgamma_native_error import libgamma_native_perror + libgamma_native_perror(name, error_code) + + +def name_of_error(value : int) -> str: + ''' + Returns the name of the definition associated with a `libgamma` error code + + @param value The error code + @return The name of the definition associated with the error code, + `None` if the error code does not exist + ''' + from libgamma_native_error import libgamma_native_name_of_error + return libgamma_native_name_of_error(value) + + +def value_of_error(name : str) -> int: + ''' + Return the value of a `libgamma` error definition refered to by name + + @param name The name of the definition associated with the error code + @return The error code, zero if the name is `None` + or does not refer to a `libgamma` error + ''' + from libgamma_native_error import libgamma_native_value_of_error + return libgamma_native_value_of_error(name) + + + +LIBGAMMA_ERRNO_SET = -1 +''' +`errno` has be set with a standard error number +to indicate the what has gone wrong +''' + +LIBGAMMA_NO_SUCH_ADJUSTMENT_METHOD = -2 +''' +The selected adjustment method does not exist +or has been excluded at compile-time +''' + +LIBGAMMA_NO_SUCH_SITE = -3 +''' +The selected site does not exist +''' + +LIBGAMMA_NO_SUCH_PARTITION = -4 +''' +The selected partition does not exist +''' + +LIBGAMMA_NO_SUCH_CRTC = -5 +''' +The selected CRTC does not exist +''' + +LIBGAMMA_IMPOSSIBLE_AMOUNT = -6 +''' +Counter overflowed when counting the number +of available items +''' + +LIBGAMMA_CONNECTOR_DISABLED = -7 +''' +The selected connector is disabled, it does +not have a CRTC +''' + +LIBGAMMA_OPEN_CRTC_FAILED = -8 +''' +The selected CRTC could not be opened, +reason unknown +''' + +LIBGAMMA_CRTC_INFO_NOT_SUPPORTED = -9 +''' +The CRTC information field is not supported +by the adjustment method +''' + +LIBGAMMA_GAMMA_RAMP_READ_FAILED = -10 +''' +Failed to read the current gamma ramps for +the selected CRTC, reason unknown +''' + +LIBGAMMA_GAMMA_RAMP_WRITE_FAILED = -11 +''' +Failed to write the current gamma ramps for +the selected CRTC, reason unknown +''' + +LIBGAMMA_GAMMA_RAMP_SIZE_CHANGED = -12 +''' +The specified ramp sizes does not match the +ramps sizes returned by the adjustment methods +in response to the query/command +''' + +LIBGAMMA_MIXED_GAMMA_RAMP_SIZE = -13 +''' +The specified ramp sizes are not identical +which is required by the adjustment method +(Only returned in debug mode) +''' + +LIBGAMMA_WRONG_GAMMA_RAMP_SIZE = -14 +''' +The specified ramp sizes are not supported +by the adjustment method +(Only returned in debug mode) +''' + +LIBGAMMA_SINGLETON_GAMMA_RAMP = -15 +''' +The adjustment method reported that the gamma +ramps size is 1, or perhaps even zero or negative +''' + +LIBGAMMA_LIST_CRTCS_FAILED = -16 +''' +The adjustment method failed to list +available CRTC:s, reason unknown +''' + +LIBGAMMA_ACQUIRING_MODE_RESOURCES_FAILED = -17 +''' +Failed to acquire mode resources from the +adjustment method +''' + +LIBGAMMA_NEGATIVE_PARTITION_COUNT = -18 +''' +The adjustment method reported that a negative +number of partitions exists in the site +''' + +LIBGAMMA_NEGATIVE_CRTC_COUNT = -19 +''' +The adjustment method reported that a negative +number of CRTC:s exists in the partition +''' + +LIBGAMMA_DEVICE_RESTRICTED = -20 +''' +Device cannot be access becauses of +insufficient permissions +''' + +LIBGAMMA_DEVICE_ACCESS_FAILED = -21 +''' +Device cannot be access, reason unknown +''' + +LIBGAMMA_DEVICE_REQUIRE_GROUP = -22 +''' +Device cannot be access, membership of the +`group.gid` (named by `group.name` (can be +`None`, if so `errno` may have been set to +tell why)) is required +''' + +LIBGAMMA_GRAPHICS_CARD_REMOVED = -23 +''' +The graphics card appear to have been removed +''' + +LIBGAMMA_STATE_UNKNOWN = -24 +''' +The state of the requested information is unknown +''' + +LIBGAMMA_CONNECTOR_UNKNOWN = -25 +''' +Failed to determine which connector the +CRTC belongs to +''' + +LIBGAMMA_CONNECTOR_TYPE_NOT_RECOGNISED = -26 +''' +The detected connector type is not listed +in this library and has to be updated +''' + +LIBGAMMA_SUBPIXEL_ORDER_NOT_RECOGNISED = -27 +''' +The detected subpixel order is not listed +in this library and has to be updated +''' + +LIBGAMMA_EDID_LENGTH_UNSUPPORTED = -28 +''' +The length of the EDID does not match that +of any supported EDID structure revision +''' + +LIBGAMMA_EDID_WRONG_MAGIC_NUMBER = -29 +''' +The magic number in the EDID does not match +that of any supported EDID structure revision +''' + +LIBGAMMA_EDID_REVISION_UNSUPPORTED = -30 +''' +The EDID structure revision used by the +monitor is not supported +''' + +LIBGAMMA_GAMMA_NOT_SPECIFIED = -31 +''' +The gamma characteristics field in the EDID +is left unspecified +(This could be considered a non-error) +''' + +LIBGAMMA_EDID_CHECKSUM_ERROR = -32 +''' +The checksum in the EDID is incorrect, all +request information has been provided +by you cannot count on it +''' + +LIBGAMMA_GAMMA_NOT_SPECIFIED_AND_EDID_CHECKSUM_ERROR = -33 +''' +Both of the errors `LIBGAMMA_GAMMA_NOT_SPECIFIED` +and `LIBGAMMA_EDID_CHECKSUM_ERROR` have occurred +''' + +LIBGAMMA_GAMMA_RAMPS_SIZE_QUERY_FAILED = -34 +''' +Failed to query the gamma ramps size from the +adjustment method, reason unknown +''' + +LIBGAMMA_OPEN_PARTITION_FAILED = -35 +''' +The selected partition could not be opened, +reason unknown +''' + +LIBGAMMA_OPEN_SITE_FAILED = -36 +''' +The selected site could not be opened, +reason unknown +''' + +LIBGAMMA_PROTOCOL_VERSION_QUERY_FAILED = -37 +''' +Failed to query the adjustment method for +its protocol version, reason unknown +''' + +LIBGAMMA_PROTOCOL_VERSION_NOT_SUPPORTED = -38 +''' +The adjustment method's version of its +protocol is not supported +''' + +LIBGAMMA_LIST_PARTITIONS_FAILED = -39 +''' +The adjustment method failed to list +available partitions, reason unknown +''' + +LIBGAMMA_NULL_PARTITION = -40 +''' +Partition exists by index, but the partition +at that index does not exist +''' + +LIBGAMMA_NOT_CONNECTED = -41 +''' +There is not monitor connected to the +connector of the selected CRTC +''' + +LIBGAMMA_REPLY_VALUE_EXTRACTION_FAILED = -42 +''' +Data extraction from a reply from the +adjustment method failed, reason unknown +''' + +LIBGAMMA_EDID_NOT_FOUND = -43 +''' +No EDID property was found on the output +''' + +LIBGAMMA_LIST_PROPERTIES_FAILED = -44 +''' +Failed to list properties on the output, +reason unknown +''' + +LIBGAMMA_PROPERTY_VALUE_QUERY_FAILED = -45 +''' +Failed to query a property's value from +the output, reason unknown +''' + +LIBGAMMA_OUTPUT_INFORMATION_QUERY_FAILED = -46 +''' +A request for information on an output +failed, reason unknown +''' + + +LIBGAMMA_ERROR_MIN = -46 +''' +The number of the libgamma error with the +lowest number. If this is lower than the +number your program thinks it should be sould +update your program for new errors. +''' + + +class LibgammaError(Exception): + ''' + libgamma error class + + @variable errno The error code + @variable strerror The name of the error + ''' + + def __init__(self, errno : int, strerror : str): + ''' + Constructor + + @param errno The error code + @param strerror The name of the error + ''' + self.errno = errno + self.strerror = strerror + + def __str__(self) -> str: + ''' + Return the name of the error + + @return The name of the error + ''' + return self.strerror + + def __repr__(self) -> str: + ''' + Create a string representation of the error + + @return A string representation of the error + ''' + return 'LibgammaError(%i, %s)' % (self.errno, repr(self.strerror)) + + +def create_error(error_code : int) -> Exception: + ''' + Create an exception from an error code + + @param error_code The error code + @return :OSError|LibgammaError The error as a throwable object + ''' + if error_code == LIBGAMMA_ERRNO_SET: + import ctypes + error_code = ctypes.get_errno() + + if error_code >= 0: + import libgamma_native_error as c + e = OSError() + e.errno = error_code + e.strerror = c.strerror(e.errno) + else: + strerror = name_of_error(error_code) + e = LibgammaError(error_code, strerror) + + return e diff --git a/libgamma_facade.py b/libgamma_facade.py new file mode 100644 index 0000000..ac2ec2c --- /dev/null +++ b/libgamma_facade.py @@ -0,0 +1,126 @@ +# See LICENSE file for copyright and license details. +from libgamma_method import MethodCapabilities + + +def list_methods(operation : int) -> list: + ''' + List available adjustment methods by their order of preference based on the environment + + @param operation Allowed values + 0: Methods that the environment suggests will work, excluding fake + 1: Methods that the environment suggests will work, including fake + 2: All real non-fake methods + 3: All real methods + 4: All methods + Other values invoke undefined behaviour + @return :list A list of available adjustment methods + ''' + from libgamma_native_facade import libgamma_native_list_methods + return libgamma_native_list_methods(operation) + + +def is_method_available(method : int) -> bool: + ''' + Check whether an adjustment method is available, non-existing (invalid) methods will be + identified as not available under the rationale that the library may be out of date + + @param method The adjustment method + @return Whether the adjustment method is available + ''' + from libgamma_native_facade import libgamma_native_is_method_available + return not libgamma_native_is_method_available(method) == 0 + + +def method_capabilities(method : int) -> MethodCapabilities: + ''' + Return the capabilities of an adjustment method + + @param this The data structure to fill with the method's capabilities + @param method The adjustment method (display server and protocol) + ''' + from libgamma_native_facade import libgamma_native_method_capabilities + caps = libgamma_native_method_capabilities(method) + return MethodCapabilities(*caps) + + +def method_default_site(method : int) -> str: + ''' + Return the default site for an adjustment method + + @param method The adjustment method (display server and protocol) + @return The default site, `None` if it cannot be determined or + if multiple sites are not supported by the adjustment + method + ''' + from libgamma_native_facade import libgamma_native_method_default_site + return libgamma_native_method_default_site(method) + + +def method_default_site_variable(method : int) -> str: + ''' + Return the default variable that determines + the default site for an adjustment method + + @param method The adjustment method (display server and protocol) + @return The environ variables that is used to determine the + default site. `None` if there is none, that is, if + the method does not support multiple sites. + ''' + from libgamma_native_facade import libgamma_native_method_default_site_variable + return libgamma_native_method_default_site_variable(method) + + + +def behex_edid(edid : bytes) -> str: + ''' + Convert a raw representation of an EDID to a lowercase hexadecimal representation + + @param edid The EDID in raw representation + @return The EDID in lowercase hexadecimal representation + ''' + return behex_edid_lowercase(edid) + + +def behex_edid_lowercase(edid : bytes) -> str: + ''' + Convert a raw representation of an EDID to a lowercase hexadecimal representation + + @param edid The EDID in raw representation + @return The EDID in lowercase hexadecimal representation + ''' + rc = '' + for b in edid: + rc += '0123456789abcdef'[(b >> 4) & 15] + rc += '0123456789abcdef'[(b >> 0) & 15] + return rc + + +def behex_edid_uppercase(edid : bytes) -> str: + ''' + Convert a raw representation of an EDID to an uppercase hexadecimal representation + + @param edid The EDID in raw representation + @return The EDID in uppercase hexadecimal representation + ''' + rc = '' + for b in edid: + rc += '0123456789ABCDEF'[(b >> 4) & 15] + rc += '0123456789ABCDEF'[(b >> 0) & 15] + return rc + + +def unhex_edid(edid : str) -> bytes: + ''' + Convert an hexadecimal representation of an EDID to a raw representation + + @param edid The EDID in hexadecimal representation + @return The EDID in raw representation + ''' + rc = [] + edid = edid.lower() + for i in range(0, len(edid), 2): + a, b = edid[i + 0], edid[i + 1] + a = '0123456789abcdef'.find(a) << 4 + b = '0123456789abcdef'.find(b) << 0 + rc.append(a | b) + return bytes(rc) diff --git a/libgamma_method.py b/libgamma_method.py new file mode 100644 index 0000000..c606959 --- /dev/null +++ b/libgamma_method.py @@ -0,0 +1,1093 @@ +# See LICENSE file for copyright and license details. +from libgamma_error import create_error + + +LIBGAMMA_METHOD_DUMMY = 0 +''' +The identifier for the dummy adjustment method. +This method can be configured and is useful for +testing your program's ability to handle errors. +''' + +LIBGAMMA_METHOD_X_RANDR = 1 +''' +The identifier for the adjustment method with +uses the RandR protocol under the X display server +''' + +LIBGAMMA_METHOD_X_VIDMODE = 2 +''' +The identifier for the adjustment method with +uses the VidMode protocol under the X display server. +This is an older alternative to RandR that can +work on some drivers that are not supported by RandR, +however it can only control the primary CRTC per +screen (partition). +''' + +LIBGAMMA_METHOD_LINUX_DRM = 3 +''' +The identifier for the Direct Rendering Manager +adjustment method that is available in Linux +(built in to the Linux kernel with a userland +library for access) and is a part of the +Direct Rendering Infrastructure. This adjustment +method all work when you are in non-graphical +mode; however a display server cannnot be +started while this is running, but it can be +started while a display server is running. +''' + +LIBGAMMA_METHOD_W32_GDI = 4 +''' +The identifier for the Graphics Device Interface +adjustment method that is available in Windows. +This method is not well tested; it can be compiled +to be available under X.org using a translation layer. +''' + +LIBGAMMA_METHOD_QUARTZ_CORE_GRAPHICS = 5 +''' +The identifier for the CoreGraphics adjustment +method that is available in Mac OS X that can +adjust gamma ramps under the Quartz display server. +This method is not well tested; it can be compiled +to be available under X.org using a translation layer. +''' + + +LIBGAMMA_METHOD_MAX = 5 +''' +The index of the last gamma method, neither it +nor any index before it may actually be supported +as it could have been disabled at compile-time +''' + +LIBGAMMA_METHOD_COUNT = (LIBGAMMA_METHOD_MAX + 1) +''' +The number adjustment methods provided by this library. +Note however that this includes adjstment methods that +have been removed at compile-time. +''' + + +class MethodCapabilities: + ''' + Capabilities of adjustment methods + + ---- Integer variables ---- + + @variable crtc_information OR of the CRTC information fields in `CRTCInformation` + that may (but can fail) be read successfully + + ---- Boolean variables ---- + + @variable default_site_known Whether the default site is known, if true the site is integrated + to the system or can be determined using environment variables + @variable multiple_sites Whether the adjustment method supports multiple sites rather + than just the default site + @variable multiple_partitions Whether the adjustment method supports multiple partitions + per site + @variable multiple_crtcs Whether the adjustment method supports multiple CRTC:s + per partition per site + @variable partitions_are_graphics_cards Whether the partition to graphics card is a bijection + @variable site_restore Whether the adjustment method supports `site_restore` + @variable partition_restore Whether the adjustment method supports `partition_restore` + @variable crtc_restore Whether the adjustment method supports `crtc_restore` + @variable identical_gamma_sizes Whether the `red_gamma_size`, `green_gamma_size` and + `blue_gamma_size` fields in `CRTCInformation` will always + have the same values as each other for the adjustment method + @variable fixed_gamma_size Whether the `red_gamma_size`, `green_gamma_size` and + `blue_gamma_size` fields in `CRTCInformation` will always be + filled with the same value for the adjustment method + @variable fixed_gamma_depth Whether the `gamma_depth` field in `CRTCInformation` will + always be filled with the same value for the adjustment method + @variable real Whether the adjustment method will actually perform adjustments + @variable fake Whether the adjustment method is implement using a translation + layer + ''' + + def __init__(self, crtc_information : int = 0, booleans : int = 0): + ''' + Constructor + + @param crtc_information The value for `CRTCInformation` + @param booleans The value for each boolean variable + ''' + self.crtc_information = crtc_information + self.default_site_known = (booleans & (1 << 0)) != 0 + self.multiple_sites = (booleans & (1 << 1)) != 0 + self.multiple_partitions = (booleans & (1 << 2)) != 0 + self.multiple_crtcs = (booleans & (1 << 3)) != 0 + self.partitions_are_graphics_cards = (booleans & (1 << 4)) != 0 + self.site_restore = (booleans & (1 << 5)) != 0 + self.partition_restore = (booleans & (1 << 6)) != 0 + self.crtc_restore = (booleans & (1 << 7)) != 0 + self.identical_gamma_sizes = (booleans & (1 << 8)) != 0 + self.fixed_gamma_size = (booleans & (1 << 9)) != 0 + self.fixed_gamma_depth = (booleans & (1 << 10)) != 0 + self.real = (booleans & (1 << 11)) != 0 + self.fake = (booleans & (1 << 12)) != 0 + + +class CRTCInformation: + ''' + Cathode ray tube controller information data structure + + @variable edid:bytes The Extended Display Identification Data associated with + the attached monitor. This is raw byte array that is usually + 128 bytes long. + @variable edid_error:int Zero on success, positive it holds the value `errno` had + when the reading failed, otherwise (negative) the value + of an error identifier provided by this library + + @variable width_mm:int The phyical width, in millimetres, of the viewport of the + attached monitor, as reported by the adjustment method. This + value may be incorrect, which is a known issue with the X + server where it is the result of the X server attempting + the estimate the size on its own. + Zero means that its is not applicable, which is the case + for projectors. + @variable width_mm_error:int Zero on success, positive it holds the value `errno` had + when the reading failed, otherwise (negative) the value + of an error identifier provided by this library + @variable height_mm:int The phyical height, in millimetres, of the viewport of the + attached monitor, as reported by the adjustment method. This + value may be incorrect, which is a known issue with the X + server where it is the result of the X server attempting + the estimate the size on its own. + Zero means that its is not applicable, which is the case + for projectors. + @variable height_mm_error:int Zero on success, positive it holds the value `errno` had + when the reading failed, otherwise (negative) the value + of an error identifier provided by this library + + @variable width_mm_edid:int The phyical width, in millimetres, of the viewport of the + attached monitor, as reported by it the monitor's Extended + Display Information Data. This value can only contain whole + centimetres, which means that the result is always zero + modulus ten. However, this could change with revisions of + the EDID structure. + Zero means that its is not applicable, which is the case + for projectors. + @variable width_mm_edid_error:int Zero on success, positive it holds the value `errno` had + when the reading failed, otherwise (negative) the value + of an error identifier provided by this library + @variable height_mm_edid:int The phyical height, in millimetres, of the viewport of the + attached monitor, as reported by it the monitor's Extended + Display Information Data. This value can only contain whole + centimetres, which means that the result is always zero + modulus ten. However, this could change with revisions of + the EDID structure. + Zero means that its is not applicable, which is the case + for projectors. + @variable height_mm_edid_error:int Zero on success, positive it holds the value `errno` had + when the reading failed, otherwise (negative) the value + of an error identifier provided by this library + + @variable red_gamma_size:int The size of the encoding axis of the red gamma ramp + @variable green_gamma_size:int The size of the encoding axis of the green gamma ramp + @variable blue_gamma_size:int The size of the encoding axis of the blue gamma ramp + @variable gamma_size_error:int Zero on success, positive it holds the value `errno` had + when the reading failed, otherwise (negative) the value + of an error identifier provided by this library + + @variable gamma_depth:int The bit-depth of the value axes of gamma ramps, + -1 for single precision floating point, and -2 for + double precision floating point + @variable gamma_depth_error:int Zero on success, positive it holds the value `errno` had + when the reading failed, otherwise (negative) the value + of an error identifier provided by this library + + @variable gamma_support:int Non-zero gamma ramp adjustments are supported + @variable gamma_support_error:int Zero on success, positive it holds the value `errno` had + when the reading failed, otherwise (negative) the value + of an error identifier provided by this library + + @variable subpixel_order:int The layout of the subpixels. + You cannot count on this value — especially for CRT:s — + but it is provided anyway as a means of distinguishing monitors. + @variable subpixel_order_error:int Zero on success, positive it holds the value `errno` had + when the reading failed, otherwise (negative) the value + of an error identifier provided by this library + + @variable active:bool Whether there is a monitors connected to the CRTC + @variable active_error:int Zero on success, positive it holds the value `errno` had + when the reading failed, otherwise (negative) the value + of an error identifier provided by this library + + @variable connector_name:str The name of the connector as designated by the display + server or as give by this library in case the display + server lacks this feature + @variable connector_name_error:int Zero on success, positive it holds the value `errno` had + when the reading failed, otherwise (negative) the value + of an error identifier provided by this library + + @variable connector_type:int The type of the connector that is associated with the CRTC + @variable connector_type_error:int Zero on success, positive it holds the value `errno` had + when the reading failed, otherwise (negative) the value + of an error identifier provided by this library + + @variable gamma_red:float The gamma characteristics of the monitor as reported + in its Extended Display Information Data. The value + holds the value for the red channel. If you do not have + and more accurate measurement of the gamma for the + monitor this could be used to give a rought gamma + correction; simply divide the value with 2.2 and use + the result for the red channel in the gamma correction. + @variable gamma_green:float The gamma characteristics of the monitor as reported + in its Extended Display Information Data. The value + holds the value for the green channel. If you do not have + and more accurate measurement of the gamma for the + monitor this could be used to give a rought gamma + correction; simply divide the value with 2.2 and use + the result for the green channel in the gamma correction. + @variable gamma_blue:float The gamma characteristics of the monitor as reported + in its Extended Display Information Data. The value + holds the value for the blue channel. If you do not have + and more accurate measurement of the gamma for the + monitor this could be used to give a rought gamma + correction; simply divide the value with 2.2 and use + the result for the blue channel in the gamma correction. + @variable gamma_error:int Zero on success, positive it holds the value `errno` had + when the reading failed, otherwise (negative) the value + of an error identifier provided by this library + ''' + + def __init__(self, data): + ''' + Constructor + + @param data:list The value of each variable + ''' + self.edid = data[0] + self.edid_error = data[1] + self.width_mm = data[2] + self.width_mm_error = data[3] + self.height_mm = data[4] + self.height_mm_error = data[5] + self.width_mm_edid = data[6] + self.width_mm_edid_error = data[7] + self.height_mm_edid = data[8] + self.height_mm_edid_error = data[9] + self.red_gamma_size = data[10] + self.green_gamma_size = data[11] + self.blue_gamma_size = data[12] + self.gamma_size_error = data[13] + self.gamma_depth = data[14] + self.gamma_depth_error = data[15] + self.gamma_support = data[16] + self.gamma_support_error = data[17] + self.subpixel_order = data[18] + self.subpixel_order_error = data[19] + self.active = data[20] + self.active_error = data[21] + self.connector_name = data[22] + self.connector_name_error = data[23] + self.connector_type = data[24] + self.connector_type_error = data[25] + self.gamma_red = data[26] + self.gamma_green = data[27] + self.gamma_blue = data[28] + self.gamma_error = data[29] + + +LIBGAMMA_CONNECTOR_TYPE_Unknown = 0 +''' +The adjustment method does not know the connector's type +(This could be considered an error) +''' + +LIBGAMMA_CONNECTOR_TYPE_VGA = 1 +''' +Video Graphics Array (VGA) +''' + +LIBGAMMA_CONNECTOR_TYPE_DVI = 2 +''' +Digital Visual Interface, unknown type +''' + +LIBGAMMA_CONNECTOR_TYPE_DVII = 3 +''' +Digital Visual Interface, integrated (DVI-I) +''' + +LIBGAMMA_CONNECTOR_TYPE_DVID = 4 +''' +Digital Visual Interface, digital only (DVI-D) +''' + +LIBGAMMA_CONNECTOR_TYPE_DVIA = 5 +''' +Digital Visual Interface, analogue only (DVI-A) +''' + +LIBGAMMA_CONNECTOR_TYPE_Composite = 6 +''' +Composite video +''' + +LIBGAMMA_CONNECTOR_TYPE_SVIDEO = 7 +''' +Separate Video (S-video) +''' + +LIBGAMMA_CONNECTOR_TYPE_LVDS = 8 +''' +Low-voltage differential signaling (LVDS) +''' + +LIBGAMMA_CONNECTOR_TYPE_Component = 9 +''' +Component video, usually separate cables for each channel +''' + +LIBGAMMA_CONNECTOR_TYPE_9PinDIN = 10 +''' +9 pin DIN (Deutsches Institut für Normung) connector +''' + +LIBGAMMA_CONNECTOR_TYPE_DisplayPort = 11 +''' +DisplayPort +''' + +LIBGAMMA_CONNECTOR_TYPE_HDMI = 12 +''' +High-Definition Multimedia Interface (HDMI), unknown type +''' + +LIBGAMMA_CONNECTOR_TYPE_HDMIA = 13 +''' +High-Definition Multimedia Interface, type A (HDMI-A) +''' + +LIBGAMMA_CONNECTOR_TYPE_HDMIB = 14 +''' +High-Definition Multimedia Interface, type B (HDMI-B) +''' + +LIBGAMMA_CONNECTOR_TYPE_TV = 15 +''' +Television, unknown connector +''' + +LIBGAMMA_CONNECTOR_TYPE_eDP = 16 +''' +Embedded DisplayPort (eDP) +''' + +LIBGAMMA_CONNECTOR_TYPE_VIRTUAL = 17 +''' +A virtual connector +''' + +LIBGAMMA_CONNECTOR_TYPE_DSI = 18 +''' +Display Serial Interface (DSI) +''' + +LIBGAMMA_CONNECTOR_TYPE_LFP = 19 +''' +LFP connector +(If you know what this is add it to Wikipedia) +''' + + +LIBGAMMA_CONNECTOR_TYPE_COUNT = 20 +''' +The number of `LIBGAMMA_CONNECTOR_*` values defined +''' + + + +LIBGAMMA_SUBPIXEL_ORDER_UNKNOWN = 0 +''' +The adjustment method does not know the order of the subpixels +(This could be considered an error) +''' + +LIBGAMMA_SUBPIXEL_ORDER_NONE = 1 +''' +There are no subpixels in the monitor +''' + +LIBGAMMA_SUBPIXEL_ORDER_HORIZONTAL_RGB = 2 +''' +The subpixels are ordered red, green and then blue, from left to right +''' + +LIBGAMMA_SUBPIXEL_ORDER_HORIZONTAL_BGR = 3 +''' +The subpixels are ordered blue, green and then red, from left to right +''' + +LIBGAMMA_SUBPIXEL_ORDER_VERTICAL_RGB = 4 +''' +The subpixels are ordered red, green and then blue, from the top down +''' + +LIBGAMMA_SUBPIXEL_ORDER_VERTICAL_BGR = 5 +''' +The subpixels are ordered blue, green and then red, from the top down +''' + + +LIBGAMMA_SUBPIXEL_ORDER_COUNT = 6 +''' +The number of `LIBGAMMA_SUBPIXEL_ORDER_*` values defined +''' + + + +LIBGAMMA_CRTC_INFO_EDID = 1 << 0 +''' +For a `CRTCInformation` fill in the values for +`edid` and `edid_length` and report errors to `edid_error` +''' + +LIBGAMMA_CRTC_INFO_WIDTH_MM = 1 << 1 +''' +For a `CRTCInformation` fill in the value for +`width_mm` and report errors to `width_mm_error` +''' + +LIBGAMMA_CRTC_INFO_HEIGHT_MM = 1 << 2 +''' +For a `CRTCInformation` fill in the value for +`height_mm` and report errors to `height_mm_error` +''' + +LIBGAMMA_CRTC_INFO_WIDTH_MM_EDID = 1 << 3 +''' +For a `CRTCInformation` fill in the value for +`width_mm_edid` and report errors to `width_mm_edid_error` +''' + +LIBGAMMA_CRTC_INFO_HEIGHT_MM_EDID = 1 << 4 +''' +For a `CRTCInformation` fill in the value for +`height_mm_edid` and report errors to `height_mm_edid_error` +''' + +LIBGAMMA_CRTC_INFO_GAMMA_SIZE = 1 << 5 +''' +For a `CRTCInformation` fill in the values for +`red_gamma_size`, `green_gamma_size` and `blue_gamma_size`, +and report errors to `gamma_size_error` +''' + +LIBGAMMA_CRTC_INFO_GAMMA_DEPTH = 1 << 6 +''' +For a `CRTCInformation` fill in the value for +`gamma_depth` and report errors to `gamma_depth_error` +''' + +LIBGAMMA_CRTC_INFO_GAMMA_SUPPORT = 1 << 7 +''' +For a `CRTCInformation` fill in the value for +`gamma_support` and report errors to `gamma_support_error` +''' + +LIBGAMMA_CRTC_INFO_SUBPIXEL_ORDER = 1 << 8 +''' +For a `CRTCInformation` fill in the value for +`subpixel_order` and report errors to `subpixel_order_error` +''' + +LIBGAMMA_CRTC_INFO_ACTIVE = 1 << 9 +''' +For a `CRTCInformation` fill in the value for +`active` and report errors to `active_error` +''' + +LIBGAMMA_CRTC_INFO_CONNECTOR_NAME = 1 << 10 +''' +For a `CRTCInformation` fill in the value for +`connector_name` and report errors to `connector_name_error` +''' + +LIBGAMMA_CRTC_INFO_CONNECTOR_TYPE = 1 << 11 +''' +For a `CRTCInformation` fill in the value for +`connector_type` and report errors to `connector_type_error` +''' + +LIBGAMMA_CRTC_INFO_GAMMA = 1 << 12 +''' +For a `CRTCInformation` fill in the values for +`gamma_red`, `gamma_green` and `gamma_blue` and +report errors to `gamma_error` +''' + + +LIBGAMMA_CRTC_INFO_COUNT = 13 +''' +The number of `LIBGAMMA_CRTC_INFO_*` values defined +''' + + + +LIBGAMMA_CRTC_INFO_MACRO_EDID_VIEWPORT = LIBGAMMA_CRTC_INFO_WIDTH_MM_EDID | \ + LIBGAMMA_CRTC_INFO_HEIGHT_MM_EDID +''' +Macro for both `CRTCInformation` fields that can +specify the size of the monitor's viewport as specified +in the monitor's Extended Display Information Data +''' + +LIBGAMMA_CRTC_INFO_MACRO_EDID = LIBGAMMA_CRTC_INFO_EDID | \ + LIBGAMMA_CRTC_INFO_MACRO_EDID_VIEWPORT | \ + LIBGAMMA_CRTC_INFO_GAMMA +''' +Macro for all `CRTCInformation` fields that can be +filled if the adjustment method have support for +reading the monitors' Extended Display Information Data +''' + +LIBGAMMA_CRTC_INFO_MACRO_VIEWPORT = LIBGAMMA_CRTC_INFO_WIDTH_MM | \ + LIBGAMMA_CRTC_INFO_HEIGHT_MM +''' +Macro for both `CRTCInformation` fields that can +specify the size of the monitor's viewport as provided +by the adjustment method without this library having to +parse the monitor's Extended Display Information Data +''' + +LIBGAMMA_CRTC_INFO_MACRO_RAMP = LIBGAMMA_CRTC_INFO_GAMMA_SIZE | \ + LIBGAMMA_CRTC_INFO_GAMMA_DEPTH +''' +Macro for the `CRTCInformation` fields that specifies +the CRTC's gamma ramp sizes and gamma ramp depth +''' + +LIBGAMMA_CRTC_INFO_MACRO_CONNECTOR = LIBGAMMA_CRTC_INFO_CONNECTOR_NAME | \ + LIBGAMMA_CRTC_INFO_CONNECTOR_TYPE +''' +Macro for the `CRTCInformation` fields that specifies +the CRTC's connector type and the partition unique +name of the connector +''' + +LIBGAMMA_CRTC_INFO_MACRO_ACTIVE = LIBGAMMA_CRTC_INFO_MACRO_EDID | \ + LIBGAMMA_CRTC_INFO_MACRO_VIEWPORT | \ + LIBGAMMA_CRTC_INFO_SUBPIXEL_ORDER | \ + LIBGAMMA_CRTC_INFO_ACTIVE +''' +Macro for the `CRTCInformation` fields that required +there is a monitor attached to the connector, and +that status itself +''' + + + +class GammaRamps: + ''' + Gamma ramp structure + ''' + + class Ramp: + ''' + A gamma ramp for one single channel + ''' + + def __init__(self, ramp, size : int, depth : int): + ''' + Constructor + + @param ramp The gamma ramp + @param size The number of stops in the gamma ramp + @param depth The depth of the gamma ramp + ''' + from libgamma_native_method import libgamma_native_gamma_ramps8_get + from libgamma_native_method import libgamma_native_gamma_ramps16_get + from libgamma_native_method import libgamma_native_gamma_ramps32_get + from libgamma_native_method import libgamma_native_gamma_ramps64_get + from libgamma_native_method import libgamma_native_gamma_rampsf_get + from libgamma_native_method import libgamma_native_gamma_rampsd_get + from libgamma_native_method import libgamma_native_gamma_ramps8_set + from libgamma_native_method import libgamma_native_gamma_ramps16_set + from libgamma_native_method import libgamma_native_gamma_ramps32_set + from libgamma_native_method import libgamma_native_gamma_ramps64_set + from libgamma_native_method import libgamma_native_gamma_rampsf_set + from libgamma_native_method import libgamma_native_gamma_rampsd_set + self._size = size + self._ramp = ramp + if depth == 8: fs = (libgamma_native_gamma_ramps8_get, libgamma_native_gamma_ramps8_set) + elif depth == 16: fs = (libgamma_native_gamma_ramps16_get, libgamma_native_gamma_ramps16_set) + elif depth == 32: fs = (libgamma_native_gamma_ramps32_get, libgamma_native_gamma_ramps32_set) + elif depth == 64: fs = (libgamma_native_gamma_ramps64_get, libgamma_native_gamma_ramps64_set) + elif depth == -1: fs = (libgamma_native_gamma_rampsf_get, libgamma_native_gamma_rampsf_set) + elif depth == -2: fs = (libgamma_native_gamma_rampsd_get, libgamma_native_gamma_rampsd_set) + (self._get, self._set) = fs + + + @property + def size(self) -> int: + ''' + Get the number of stops in the gamma ramp + + @return The number of stops in the gamma ramp + ''' + return self._size + + @size.setter + def size(self, value : int): + ''' + It is not possible to change this attribute, but + a setter is required for the getter to function + ''' + raise AttributeError('cannot resize ramp') + + def __len__(self) -> int: + ''' + Get the number of stops in the gamma ramp + + @return The number of stops in the gamma ramp + ''' + return self._size + + def __getitem__(self, indices): + ''' + Read the gamma ramp + + @param indices:slice The stops to read + @return :list The values of the read stops + + -- OR -- + + @param indices:int The index of the stop to read + @return :int|float The value of the read stop + ''' + if isinstance(indices, slice): + start = indices.start + stop = indices.stop + step = indices.step + if start is None: start = 0 + elif start < 0: start += self._size + if stop is None: stop = self._size + elif stop < 0: stop += self._size + if step is None: step = 1 + return [self._get(self._ramp, i) for i in range(start, stop, step)] + else: + if indices < 0: + indices += self._size + return self._get(self._ramp, indices) + + def __setitem__(self, indices, values): + ''' + Modify the gamma ramp + + @param indices:slice The stops to modify + @param values:itr The values for the selected stops + + -- OR -- + + @param indices:int The index of the stop to modify + @param values:int|float The new value for the stop + ''' + if isinstance(indices, slice): + start = indices.start + stop = indices.stop + step = indices.step + if start is None: start = 0 + elif start < 0: start += self._size + if stop is None: stop = self._size + elif stop < 0: stop += self._size + if step is None: step = 1 + indices = list(range(start, stop, step)) + if not len(indices) == len(values): + raise ValueError('cannot resize ramp') + for index, value in zip(indices, values): + self._set(self._ramp, index, value) + else: + if indices < 0: + indices += self._size + self._set(self._ramp, indices, values) + + def __iter__(self) -> iter: + ''' + Read the gamma ramp + + @return :itr The values of each stop + ''' + for value in self[:]: + yield value + + def map(self, function): + ''' + Modify the entire ramp using a function that + maps encoding value to output value + + @param function:(float)→int|float Function that takes the encoding value as a + [0, 1] floating point and returns its output + value as the format using in the gamma ramp + ''' + max_i = self._size - 1 + for i in range(self._size): + self._set(self._ramp, i, function(i / max_i)) + + + def __init__(self, red_size : int, green_size : int = ..., blue_size : int = ..., *, depth : int = 16): + ''' + Constructor + + @param red_size The number of stops in the gamma ramp for the red channel + @param green_size The number of stops in the gamma ramp for the green channel, `...` for `red_size` + @param blue_size The number of stops in the gamma ramp for the blue channel, `...` for `green_size` + @param depth The depth of the gamma ramps + ''' + if green_size is ...: green_size = red_size + if blue_size is ...: blue_size = green_size + + self._depth = depth + + from libgamma_native_method import libgamma_native_gamma_ramps8_create + from libgamma_native_method import libgamma_native_gamma_ramps16_create + from libgamma_native_method import libgamma_native_gamma_ramps32_create + from libgamma_native_method import libgamma_native_gamma_ramps64_create + from libgamma_native_method import libgamma_native_gamma_rampsf_create + from libgamma_native_method import libgamma_native_gamma_rampsd_create + if depth == 8: ramp_struct = libgamma_native_gamma_ramps8_create (red_size, green_size, blue_size) + elif depth == 16: ramp_struct = libgamma_native_gamma_ramps16_create(red_size, green_size, blue_size) + elif depth == 32: ramp_struct = libgamma_native_gamma_ramps32_create(red_size, green_size, blue_size) + elif depth == 64: ramp_struct = libgamma_native_gamma_ramps64_create(red_size, green_size, blue_size) + elif depth == -1: ramp_struct = libgamma_native_gamma_rampsf_create (red_size, green_size, blue_size) + elif depth == -2: ramp_struct = libgamma_native_gamma_rampsd_create (red_size, green_size, blue_size) + else: + raise ValueError('invalid gamma ramp depth') + if isinstance(ramp_struct, int): + import libgamma_native_error as c + error = OSError() + error.errno = ramp_struct + error.strerror = c.strerror(error.errno) + raise error + (self._ramps, red, green, blue) = ramp_struct + + self._red = GammaRamps.Ramp(red, red_size, depth) + self._green = GammaRamps.Ramp(green, green_size, depth) + self._blue = GammaRamps.Ramp(blue, blue_size, depth) + + + def __del__(self): + ''' + This function is called when the object is not longer in use + ''' + from libgamma_native_method import libgamma_native_gamma_ramps8_free + from libgamma_native_method import libgamma_native_gamma_ramps16_free + from libgamma_native_method import libgamma_native_gamma_ramps32_free + from libgamma_native_method import libgamma_native_gamma_ramps64_free + from libgamma_native_method import libgamma_native_gamma_rampsf_free + from libgamma_native_method import libgamma_native_gamma_rampsd_free + if self._ramps == 0: + return + if self._depth == 8: libgamma_native_gamma_ramps8_free(self._ramps) + elif self._depth == 16: libgamma_native_gamma_ramps16_free(self._ramps) + elif self._depth == 32: libgamma_native_gamma_ramps32_free(self._ramps) + elif self._depth == 64: libgamma_native_gamma_ramps64_free(self._ramps) + elif self._depth == -1: libgamma_native_gamma_rampsf_free(self._ramps) + elif self._depth == -2: libgamma_native_gamma_rampsd_free(self._ramps) + + + @property + def red(self) -> Ramp: + ''' + Get the gamma ramp for the red channel + + @return The gamma ramp for the red channel + ''' + return self._red + + + @red.setter + def red(self, value): + ''' + It is not possible to change this attribute, but a setter is + required for the getter to function + ''' + raise AttributeError('cannot change ramps') + + + @property + def green(self) -> Ramp: + ''' + Get the gamma ramp for the green channel + + @return The gamma ramp for the green channel + ''' + return self._green + + + @green.setter + def green(self, value) -> Ramp: + ''' + It is not possible to change this attribute, but a setter is + required for the getter to function + ''' + raise AttributeError('cannot change ramps') + + + @property + def blue(self): + ''' + Get the gamma ramp for the blue channel + + @return The gamma ramp for the blue channel + ''' + return self._blue + + + @blue.setter + def blue(self, value): + ''' + It is not possible to change this attribute, but a setter is + required for the getter to function + ''' + raise AttributeError('cannot change ramps') + + + @property + def size(self) -> tuple: + ''' + Get the ramps' sizes + + @return :(red:int, green:int, blue:int) The size of each individual ramp + ''' + return (self._red.size, self._green.size, self._blue.size) + + + @size.setter + def size(self, value): + ''' + It is not possible to change this attribute, but a setter is + required for the getter to function + ''' + raise AttributeError('cannot resize ramps') + + + @property + def depth(self) -> int: + ''' + Get the depth of ramps + + @return :int The ramps' depth in bits and -1 for single precision floating + point and -2 for doublesingle precision floating point + ''' + return self._depth + + + @depth.setter + def depth(self, value): + ''' + It is not possible to change this attribute, but a setter is + required for the getter to function + ''' + raise AttributeError('cannot change depth') + + +class Site: + ''' + Site state + + On operating systems that integrate a graphical environment + there is usually just one site. However, one systems with + pluggable graphics, like Unix-like systems such as GNU/Linux + and the BSD:s, there can usually be any (feasible) number of + sites. In X.org parlance they are called displays. + + @variable method:int The adjustment method of the site + @variable site:str? The site identifier + @variable partitions_available:int The number of paritions available in the site + ''' + + def __init__(self, method : int, site : str = None): + ''' + Constructor + + @param method:int The adjustment method of the site + @param site:str? The site identifier + ''' + from libgamma_native_facade import libgamma_native_site_create + (self._state, n) = libgamma_native_site_create(method, site) + if self._state == 0: + raise create_error(n) + self.partitions_available = n + self.method = method + self.site = site + + + def __del__(self): + ''' + This function is called when the object is not longer in use + ''' + from libgamma_native_facade import libgamma_native_site_free + if not self._state == 0: + libgamma_native_site_free(self._state) + + + def restore(self): + ''' + Restore the gamma ramps all CRTC:s with the site to the system settings + ''' + from libgamma_native_facade import libgamma_native_site_restore + r = libgamma_native_site_restore(self._state) + if not r == 0: + raise create_error(r) + + +class Partition: + ''' + Partition state + + Probably the majority of display server only one partition + per site. However, X.org can, and traditional used to have + on multi-headed environments, multiple partitions per site. + In X.org partitions are called 'screens'. It is not to be + confused with monitor. A screen is a collection of monitors, + and the mapping from monitors to screens is a surjection. + On hardware-level adjustment methods, such as Direct + Rendering Manager, a partition is a graphics card + + @variable site:Site The site of the partition + @variable partition:int The index of the partition + @variable crtcs_available:int The number of CRTC:s available in the parition + ''' + + def __init__(self, site : Site, partition : int): + ''' + Constructor. + + @param site The site of the partition + @param partition The index of the partition + ''' + from libgamma_native_facade import libgamma_native_partition_create + (self._state, n) = libgamma_native_partition_create(site._state, partition) + if self._state == 0: + raise create_error(n) + self.crtcs_available = n + self.site = site + self.partition = partition + + + def __del__(self): + ''' + This function is called when the object is not longer in use + ''' + from libgamma_native_facade import libgamma_native_partition_free + if not self._state == 0: + libgamma_native_partition_free(self._state) + + + def restore(self): + ''' + Restore the gamma ramps all CRTC:s with the partition to the system settings + ''' + from libgamma_native_facade import libgamma_native_partition_restore + r = libgamma_native_partition_restore(self._state) + if not r == 0: + raise create_error(r) + + +class CRTC: + ''' + Cathode ray tube controller state + + The CRTC controls the gamma ramps for the + monitor that is plugged in to the connector + that the CRTC belongs to + + @variable partition:Partition The partition of the CRTC + @variable crtc:int The index of the CRTC + ''' + + def __init__(self, partition : Partition, crtc : int): + ''' + Constructor + + @param partition The partition the of the CRTC + @param crtc The index of the CRTC + ''' + from libgamma_native_facade import libgamma_native_crtc_create + (self._state, n) = libgamma_native_crtc_create(partition._state, crtc) + if self._state == 0: + raise create_error(n) + self.partition = partition + self.crtc = crtc + + + def __del__(self): + ''' + This function is called when the object is not longer in use + ''' + from libgamma_native_facade import libgamma_native_crtc_free + if not self._state == 0: + libgamma_native_crtc_free(self._state) + + + def restore(self): + ''' + Restore the gamma ramps for a CRTC to the system settings for that CRTC + ''' + from libgamma_native_facade import libgamma_native_crtc_restore + r = libgamma_native_crtc_restore(self._state) + if not r == 0: + raise create_error(r) + + + def information(self, fields : int) -> tuple: + ''' + Read information about a CRTC + + @param field OR:ed identifiers for the information + about the CRTC that should be read + @return :(:CRTCInformation, :bool) The information about the CRTC and + whether no errors occurred + ''' + from libgamma_native_facade import libgamma_native_get_crtc_information + (data, e) = libgamma_native_get_crtc_information(self._state, fields) + return (CRTCInformation(data), e == 0) + + + def get_gamma(self, ramps : GammaRamps): + ''' + Get the current gamma ramps for the CRTC + + @param ramps The gamma ramps to fill with the current values + ''' + from libgamma_native_facade import libgamma_native_crtc_get_gamma_ramps8 + from libgamma_native_facade import libgamma_native_crtc_get_gamma_ramps16 + from libgamma_native_facade import libgamma_native_crtc_get_gamma_ramps32 + from libgamma_native_facade import libgamma_native_crtc_get_gamma_ramps64 + from libgamma_native_facade import libgamma_native_crtc_get_gamma_rampsf + from libgamma_native_facade import libgamma_native_crtc_get_gamma_rampsd + if ramps.depth == 8: r = libgamma_native_crtc_get_gamma_ramps8(self._state, ramps._ramps) + elif ramps.depth == 16: r = libgamma_native_crtc_get_gamma_ramps16(self._state, ramps._ramps) + elif ramps.depth == 32: r = libgamma_native_crtc_get_gamma_ramps32(self._state, ramps._ramps) + elif ramps.depth == 64: r = libgamma_native_crtc_get_gamma_ramps64(self._state, ramps._ramps) + elif ramps.depth == -1: r = libgamma_native_crtc_get_gamma_rampsf(self._state, ramps._ramps) + elif ramps.depth == -2: r = libgamma_native_crtc_get_gamma_rampsd(self._state, ramps._ramps) + if not r == 0: + raise create_error(r) + + + def set_gamma(self, ramps : GammaRamps): + ''' + Set gamma ramps for the CRTC + + @param ramps The gamma ramps to apply + ''' + from libgamma_native_facade import libgamma_native_crtc_set_gamma_ramps8 + from libgamma_native_facade import libgamma_native_crtc_set_gamma_ramps16 + from libgamma_native_facade import libgamma_native_crtc_set_gamma_ramps32 + from libgamma_native_facade import libgamma_native_crtc_set_gamma_ramps64 + from libgamma_native_facade import libgamma_native_crtc_set_gamma_rampsf + from libgamma_native_facade import libgamma_native_crtc_set_gamma_rampsd + if ramps.depth == 8: r = libgamma_native_crtc_set_gamma_ramps8(self._state, ramps._ramps) + elif ramps.depth == 16: r = libgamma_native_crtc_set_gamma_ramps16(self._state, ramps._ramps) + elif ramps.depth == 32: r = libgamma_native_crtc_set_gamma_ramps32(self._state, ramps._ramps) + elif ramps.depth == 64: r = libgamma_native_crtc_set_gamma_ramps64(self._state, ramps._ramps) + elif ramps.depth == -1: r = libgamma_native_crtc_set_gamma_rampsf(self._state, ramps._ramps) + elif ramps.depth == -2: r = libgamma_native_crtc_set_gamma_rampsd(self._state, ramps._ramps) + if not r == 0: + raise create_error(r) diff --git a/libgamma_native_error.posix.pyx b/libgamma_native_error.posix.pyx new file mode 100644 index 0000000..0370eb4 --- /dev/null +++ b/libgamma_native_error.posix.pyx @@ -0,0 +1,188 @@ +# -*- python -*- +# See LICENSE file for copyright and license details. +cimport cython + +from posix.unistd cimport gid_t +from libc.string cimport strerror as c_strerror + + +cdef extern gid_t libgamma_group_gid_get() nogil +cdef extern void libgamma_group_gid_set(gid_t) nogil +''' +Group that the user needs to be a member of if +`LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned +''' + +cdef extern const char *libgamma_group_name_get() nogil +cdef extern void libgamma_group_name_set(const char *) nogil +''' +Group that the user needs to be a member of if +`LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, +`NULL` if the name of the group `libgamma_group_gid` +cannot be determined +''' + + +cdef extern void libgamma_perror(const char *name, int error_code) nogil +''' +Prints an error to stderr in a `perror` fashion, +however this function will not translate the `libgamma` +errors into human-readable strings, it will simply +print the name of the error. If the value `error_code` +is the value of `LIBGAMMA_ERRNO_SET`, `perror` will be +used to print the current error stored in `errno`. +If `error_code` is non-negative (an `errno` value`), that +value will be stored in `errno` and `perror` will be +used to print it. Additionally, if the `error_code` is +the value of `LIBGAMMA_DEVICE_REQUIRE_GROUP` the +required group will be printed with its numerical value +and, if known, its name. + +@param name The text to add at the beginning +@param value The error code, may be an `errno` value +''' + +cdef extern const char *libgamma_name_of_error(int value) nogil +''' +Returns the name of the definition associated with a `libgamma` error code + +@param value The error code +@return The name of the definition associated with the error code, + `NULL` if the error code does not exist. The return string + should not be `free`:d. +''' + +cdef extern int libgamma_value_of_error(const char *name) nogil +''' +Return the value of a `libgamma` error definition refered to by name + +@param name The name of the definition associated with the error code +@return The error code, zero if the name does is `NULL` + or does not refer to a `libgamma` error +''' + + +def libgamma_native_get_group_gid() -> int: + ''' + Getter + + Group that the user needs to be a member of if + `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned + ''' + return int(libgamma_group_gid_get()) + + +def libgamma_native_set_group_gid(gid : int): + ''' + Setter + + Group that the user needs to be a member of if + `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned + ''' + libgamma_group_gid_set(gid) + + +def libgamma_native_get_group_name() -> str: + ''' + Getter + + Group that the user needs to be a member of if + `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, + `None` if the name of the group `libgamma_group_gid` + cannot be determined + ''' + cdef const char *group_name + cdef bytes bs + group_name = libgamma_group_name_get() + if group_name is NULL: + return None + bs = group_name + return bs.decode('utf-8', 'strict') + + +def libgamma_native_set_group_name(name : str): + ''' + Setter + + Group that the user needs to be a member of if + `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, + `None` if the name of the group `libgamma_group_gid` + cannot be determined + ''' + cdef const char *group_name + cdef bytes bs + if name is None: + libgamma_group_name_set(NULL) + return + bs = name.encode('utf-8') + bytes([0]) + group_name = bs + libgamma_group_name_set(group_name) + + +def libgamma_native_perror(name : str, error_code : int): + ''' + Prints an error to stderr in a `perror` fashion, + however this function will not translate the `libgamma` + errors into human-readable strings, it will simply + print the name of the error. If the value `error_code` + is the value of `LIBGAMMA_ERRNO_SET`, `perror` will be + used to print the current error stored in `errno`. + If `error_code` is non-negative (an `errno` value`), that + value will be stored in `errno` and `perror` will be + used to print it. Additionally, if the `error_code` is + the value of `LIBGAMMA_DEVICE_REQUIRE_GROUP` the + required group will be printed with its numerical value + and, if known, its name. + + @param name The text to add at the beginning + @param value The error code, may be an `errno` value + ''' + cdef bytes bs + bs = name.encode('utf-8') + bytes([0]) + libgamma_perror(bs, error_code) + + +def libgamma_native_name_of_error(value : int) -> str: + ''' + Returns the name of the definition associated with a `libgamma` error code + + @param value The error code + @return The name of the definition associated with the error code, + `None` if the error code does not exist + ''' + cdef const char *name + cdef bytes bs + name = libgamma_name_of_error(value) + if name is NULL: + return None + bs = name + return bs.decode('utf-8', 'strict') + + +def libgamma_native_value_of_error(name : str) -> int: + ''' + Return the value of a `libgamma` error definition refered to by name + + @param name The name of the definition associated with the error code + @return The error code, zero if the name is `None`, + or does not refer to a `libgamma` error + ''' + cdef bytes bs + if name is None: + return 0 + bs = name.encode('utf-8') + bytes([0]) + return int(libgamma_value_of_error(bs)) + + +def strerror(error : int) -> str: + ''' + Get a textual description of an error + + @param error The number of the error + @return The description of the error + ''' + cdef const char *text + cdef bytes bs + text = c_strerror(error) + bs = text + return bs.decode('utf-8', 'strict') diff --git a/libgamma_native_error.w32.pyx b/libgamma_native_error.w32.pyx new file mode 100644 index 0000000..21548f0 --- /dev/null +++ b/libgamma_native_error.w32.pyx @@ -0,0 +1,167 @@ +# -*- python -*- +# See LICENSE file for copyright and license details. +cimport cython + + +cdef extern short libgamma_group_gid +''' +Group that the user needs to be a member of if +`LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned +''' + +cdef extern const char* libgamma_group_name +''' +Group that the user needs to be a member of if +`LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, +`NULL` if the name of the group `libgamma_group_gid` +cannot be determined +''' + + +cdef extern void libgamma_perror(const char *name, int error_code) nogil +''' +Prints an error to stderr in a `perror` fashion, +however this function will not translate the `libgamma` +errors into human-readable strings, it will simply +print the name of the error. If the value `error_code` +is the value of `LIBGAMMA_ERRNO_SET`, `perror` will be +used to print the current error stored in `errno`. +If `error_code` is non-negative (an `errno` value`), that +value will be stored in `errno` and `perror` will be +used to print it. Additionally, if the `error_code` is +the value of `LIBGAMMA_DEVICE_REQUIRE_GROUP` the +required group will be printed with its numerical value +and, if known, its name. + +@param name The text to add at the beginning +@param value The error code, may be an `errno` value +''' + +cdef extern const char *libgamma_name_of_error(int value) nogil +''' +Returns the name of the definition associated with a `libgamma` error code + +@param value The error code +@return The name of the definition associated with the error code, + `NULL` if the error code does not exist. The return string + should not be `free`:d +''' + +cdef extern int libgamma_value_of_error(const char *name) nogil +''' +Return the value of a `libgamma` error definition refered to by name + +@param name The name of the definition associated with the error code +@return The error code, zero if the name does is `NULL` + or does not refer to a `libgamma` error +''' + + +def libgamma_native_get_group_gid() -> int: + ''' + Getter + + Group that the user needs to be a member of if + `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned + ''' + return int(libgamma_group_gid) + + +def libgamma_native_set_group_gid(gid : int): + ''' + Setter + + Group that the user needs to be a member of if + `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned + ''' + libgamma_group_gid = gid + + +def libgamma_native_get_group_name() -> str: + ''' + Getter + + Group that the user needs to be a member of if + `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, + `None` if the name of the group `libgamma_group_gid` + cannot be determined + ''' + cdef bytes bs + if libgamma_group_name is NULL: + return None + bs = libgamma_group_name + return bs.decode('utf-8', 'strict') + + +def libgamma_native_set_group_name(name : str): + ''' + Setter + + Group that the user needs to be a member of if + `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, + `None` if the name of the group `libgamma_group_gid` + cannot be determined + ''' + cdef bytes bs + if name is None: + libgamma_group_name = NULL + return + bs = name.encode('utf-8') + bytes([0]) + libgamma_group_name = bs + + +def libgamma_native_perror(name : str, error_code : int): + ''' + Prints an error to stderr in a `perror` fashion, + however this function will not translate the `libgamma` + errors into human-readable strings, it will simply + print the name of the error. If the value `error_code` + is the value of `LIBGAMMA_ERRNO_SET`, `perror` will be + used to print the current error stored in `errno`. + If `error_code` is non-negative (an `errno` value`), that + value will be stored in `errno` and `perror` will be + used to print it. Additionally, if the `error_code` is + the value of `LIBGAMMA_DEVICE_REQUIRE_GROUP` the + required group will be printed with its numerical value + and, if known, its name. + + @param name The text to add at the beginning + @param value The error code, may be an `errno` value + ''' + cdef bytes bs + bs = name.encode('utf-8') + bytes([0]) + libgamma_perror(bs, error_code) + + +def libgamma_native_name_of_error(value : int) -> str: + ''' + Returns the name of the definition associated with a `libgamma` error code + + @param value The error code + @return The name of the definition associated with the error code, + `None` if the error code does not exist. The return string + should not be `free`:d + ''' + cdef const char* name + cdef bytes bs + name = libgamma_name_of_error(value) + if name is NULL: + return None + bs = name + return bs.decode('utf-8', 'strict') + + +def libgamma_native_value_of_error(name : str) -> int: + ''' + Return the value of a `libgamma` error definition refered to by name + + @param name The name of the definition associated with the error code + @return The error code, zero if the name is `None`, + or does not refer to a `libgamma` error + ''' + cdef bytes bs + if name is None: + return 0 + bs = name.encode('utf-8') + bytes([0]) + return int(libgamma_value_of_error(bs)) + diff --git a/libgamma_native_facade.pyx b/libgamma_native_facade.pyx new file mode 100644 index 0000000..19da8b1 --- /dev/null +++ b/libgamma_native_facade.pyx @@ -0,0 +1,1297 @@ +# -*- python -*- +# See LICENSE file for copyright and license details. +cimport cython + +from libc.stddef cimport size_t +from libc.stdlib cimport malloc, free +from libc.stdint cimport int32_t, uint8_t, uint16_t, uint32_t, uint64_t +from libc.errno cimport errno + + +ctypedef int libgamma_subpixel_order_t +ctypedef int libgamma_connector_type_t + +cdef extern from "include-libgamma.h": + + ctypedef struct libgamma_method_capabilities_t: + # Capabilities of adjustment methods + + int32_t crtc_information + # OR of the CRTC information fields in `libgamma_crtc_information_t` + # that may (but can fail) be read successfully + + unsigned default_site_known # : 1 + # Whether the default site is known, if true the site is integrated + # to the system or can be determined using environment variables + + unsigned multiple_sites # : 1 + # Whether the adjustment method supports multiple sites rather + # than just the default site + + unsigned multiple_partitions # : 1 + # Whether the adjustment method supports multiple partitions + # per site + + unsigned multiple_crtcs # : 1 + # Whether the adjustment method supports multiple CRTC:s + # per partition per site + + unsigned partitions_are_graphics_cards # : 1 + # Whether the partition to graphics card is a bijection + + unsigned site_restore # : 1 + # Whether the adjustment method supports `libgamma_site_restore` + + unsigned partition_restore # : 1 + # Whether the adjustment method supports `libgamma_partition_restore` + + unsigned crtc_restore # : 1 + # Whether the adjustment method supports `libgamma_crtc_restore` + + unsigned identical_gamma_sizes # : 1 + # Whether the `red_gamma_size`, `green_gamma_size` and `blue_gamma_size` + # fields in `libgamma_crtc_information_t` will always have the same + # values as each other for the adjustment method + + unsigned fixed_gamma_size # : 1 + # Whether the `red_gamma_size`, `green_gamma_size` and `blue_gamma_size` + # fields in `libgamma_crtc_information_t` will always be filled with the + # same value for the adjustment method + + unsigned fixed_gamma_depth # : 1 + # Whether the `gamma_depth` field in `libgamma_crtc_information_t` + # will always be filled with the same value for the adjustment method + + unsigned real # : 1 + # Whether the adjustment method will actually perform adjustments + + unsigned fake # : 1 + # Whether the adjustment method is implement using a translation layer + + ctypedef struct libgamma_site_state_t: + # Site state + # + # On operating systems that integrate a graphical environment + # there is usually just one site. However, one systems with + # pluggable graphics, like Unix-like systems such as GNU/Linux + # and the BSD:s, there can usually be any (feasible) number of + # sites. In X.org parlance they are called displays. + + void *data + # Adjustment method implementation specific data. + # You as a user of this library should not touch this. + + int method + # This field specifies, for the methods if this library, + # which adjustment method (display server and protocol) + # is used to adjust the gamma ramps + + char *site + # The site identifier. It can either be `NULL` or a string. + # `NULL` indicates the default site. On systems like the + # Unix-like systems, where the graphics are pluggable, this + # is usually resolved by an environment variable, such as + # "DISPLAY" for X.org. + + size_t partitions_available + # The number of partitions that is available on this site. + # Probably the majority of display server only one partition + # per site. However, X.org can, and traditional used to have + # on multi-headed environments, multiple partitions per site. + # In X.org partitions are called 'screens'. It is not to be + # confused with monitor. A screen is a collection of monitors, + # and the mapping from monitors to screens is a surjection. + # On hardware-level adjustment methods, such as Direct + # Rendering Manager, a partition is a graphics card. + + ctypedef struct libgamma_partition_state_t: + # Partition state + # + # Probably the majority of display server only one partition + # per site. However, X.org can, and traditional used to have + # on multi-headed environments, multiple partitions per site. + # In X.org partitions are called 'screens'. It is not to be + # confused with monitor. A screen is a collection of monitors, + # and the mapping from monitors to screens is a surjection. + # On hardware-level adjustment methods, such as Direct + # Rendering Manager, a partition is a graphics card. + + void *data + # Adjustment method implementation specific data. + # You as a user of this library should not touch this. + + libgamma_site_state_t* site + # The site this partition belongs to + + size_t partition + # The index of the partition + + size_t crtcs_available + # The number of CRTC:s that are available under this + # partition. Note that the CRTC:s are not necessarily + # online. + + ctypedef struct libgamma_crtc_state_t: + # Cathode ray tube controller state + # + # The CRTC controls the gamma ramps for the + # monitor that is plugged in to the connector + # that the CRTC belongs to + + void* data + # Adjustment method implementation specific data. + # You as a user of this library should not touch this. + + libgamma_partition_state_t* partition + # The partition this CRTC belongs to + + size_t crtc + # The index of the CRTC within its partition + + ctypedef struct libgamma_crtc_information_t: + # Cathode ray tube controller information data structure + + unsigned char *edid + # The Extended Display Identification Data associated with + # the attached monitor. This is raw byte array that is usually + # 128 bytes long. It is not NUL-terminate, rather its length + # is stored in `edid_length`. + + size_t edid_length + # The length of `edid` + + int edid_error + # Zero on success, positive it holds the value `errno` had + # when the reading failed, otherwise (negative) the value + # of an error identifier provided by this library. + + size_t width_mm + # The phyical width, in millimetres, of the viewport of the + # attached monitor, as reported by the adjustment method. This + # value may be incorrect, which is a known issue with the X + # server where it is the result of the X server attempting + # the estimate the size on its own. + # Zero means that its is not applicable, which is the case + # for projectors. + + int width_mm_error + # Zero on success, positive it holds the value `errno` had + # when the reading failed, otherwise (negative) the value + # of an error identifier provided by this library + + size_t height_mm + # The phyical height, in millimetres, of the viewport of the + # attached monitor, as reported by the adjustment method. This + # value may be incorrect, which is a known issue with the X + # server where it is the result of the X server attempting + # the estimate the size on its own. + # Zero means that its is not applicable, which is the case + # for projectors. + + int height_mm_error + # Zero on success, positive it holds the value `errno` had + # when the reading failed, otherwise (negative) the value + # of an error identifier provided by this library + + size_t width_mm_edid + # The phyical width, in millimetres, of the viewport of the + # attached monitor, as reported by it the monitor's Extended + # Display Information Data. This value can only contain whole + # centimetres, which means that the result is always zero + # modulus ten. However, this could change with revisions of + # the EDID structure. + # Zero means that its is not applicable, which is the case + # for projectors. + + int width_mm_edid_error + # Zero on success, positive it holds the value `errno` had + # when the reading failed, otherwise (negative) the value + # of an error identifier provided by this library + + size_t height_mm_edid + # The phyical height, in millimetres, of the viewport of the + # attached monitor, as reported by it the monitor's Extended + # Display Information Data. This value can only contain whole + # centimetres, which means that the result is always zero + # modulus ten. However, this could change with revisions of + # the EDID structure. + # Zero means that its is not applicable, which is the case + # for projectors. + + int height_mm_edid_error + # Zero on success, positive it holds the value `errno` had + # when the reading failed, otherwise (negative) the value + # of an error identifier provided by this library + + size_t red_gamma_size + # The size of the encoding axis of the red gamma ramp + + size_t green_gamma_size + # The size of the encoding axis of the green gamma ramp + + size_t blue_gamma_size + # The size of the encoding axis of the blue gamma ramp + + int gamma_size_error + # Zero on success, positive it holds the value `errno` had + # when the reading failed, otherwise (negative) the value + # of an error identifier provided by this library + + signed gamma_depth + # The bit-depth of the value axes of gamma ramps, + # -1 for single precision floating point, and -2 for + # double precision floating point + + int gamma_depth_error + # Zero on success, positive it holds the value `errno` had + # when the reading failed, otherwise (negative) the value + # of an error identifier provided by this library + + int gamma_support + # Non-zero gamma ramp adjustments are supported + + int gamma_support_error + # Zero on success, positive it holds the value `errno` had + # when the reading failed, otherwise (negative) the value + # of an error identifier provided by this library + + libgamma_subpixel_order_t subpixel_order + # The layout of the subpixels. + # You cannot count on this value --- especially for CRT:s --- + # but it is provided anyway as a means of distinguishing monitors. + + int subpixel_order_error + # Zero on success, positive it holds the value `errno` had + # when the reading failed, otherwise (negative) the value + # of an error identifier provided by this library. + + int active + # Whether there is a monitors connected to the CRTC + + int active_error + # Zero on success, positive it holds the value `errno` had + # when the reading failed, otherwise (negative) the value + # of an error identifier provided by this library + + char *connector_name + # The name of the connector as designated by the display + # server or as give by this library in case the display + # server lacks this feature + + int connector_name_error + # Zero on success, positive it holds the value `errno` had + # when the reading failed, otherwise (negative) the value + # of an error identifier provided by this library + + libgamma_connector_type_t connector_type + # The type of the connector that is associated with the CRTC + + int connector_type_error + # Zero on success, positive it holds the value `errno` had + # when the reading failed, otherwise (negative) the value + # of an error identifier provided by this library + + float gamma_red + # The gamma characteristics of the monitor as reported + # in its Extended Display Information Data. The value + # holds the value for the red channel. If you do not have + # and more accurate measurement of the gamma for the + # monitor this could be used to give a rought gamma + # correction; simply divide the value with 2.2 and use + # the result for the red channel in the gamma correction. + + float gamma_green + # The gamma characteristics of the monitor as reported + # in its Extended Display Information Data. The value + # holds the value for the green channel. If you do not have + # and more accurate measurement of the gamma for the + # monitor this could be used to give a rought gamma + # correction; simply divide the value with 2.2 and use + # the result for the green channel in the gamma correction. + + float gamma_blue + # The gamma characteristics of the monitor as reported + # in its Extended Display Information Data. The value + # holds the value for the blue channel. If you do not have + # and more accurate measurement of the gamma for the + # monitor this could be used to give a rought gamma + # correction; simply divide the value with 2.2 and use + # the result for the blue channel in the gamma correction. + + int gamma_error + # Zero on success, positive it holds the value `errno` had + # when the reading failed, otherwise (negative) the value + # of an error identifier provided by this library + + ctypedef struct libgamma_gamma_ramps8_t: + # Gamma ramp structure for 8-bit gamma ramps + size_t red_size # The size of `red` + size_t green_size # The size of `green` + size_t blue_size # The size of `blue` + uint8_t *red # The gamma ramp for the red channel + uint8_t *green # The gamma ramp for the green channel + uint8_t *blue # The gamma ramp for the blue channel + + ctypedef struct libgamma_gamma_ramps16_t: + # Gamma ramp structure for 16-bit gamma ramps + size_t red_size # The size of `red` + size_t green_size # The size of `green` + size_t blue_size # The size of `blue` + uint16_t *red # The gamma ramp for the red channel + uint16_t *green # The gamma ramp for the green channel + uint16_t *blue # The gamma ramp for the blue channel + + ctypedef struct libgamma_gamma_ramps32_t: + # Gamma ramp structure for 32-bit gamma ramps + size_t red_size # The size of `red` + size_t green_size # The size of `green` + size_t blue_size # The size of `blue` + uint32_t *red # The gamma ramp for the red channel + uint32_t *green # The gamma ramp for the green channel + uint32_t *blue # The gamma ramp for the blue channel + + ctypedef struct libgamma_gamma_ramps64_t: + # Gamma ramp structure for 64-bit gamma ramps + size_t red_size # The size of `red` + size_t green_size # The size of `green` + size_t blue_size # The size of `blue` + uint64_t *red # The gamma ramp for the red channel + uint64_t *green # The gamma ramp for the green channel + uint64_t *blue # The gamma ramp for the blue channel + + ctypedef struct libgamma_gamma_rampsf_t: + # Gamma ramp structure for `float` gamma ramps + size_t red_size # The size of `red` + size_t green_size # The size of `green` + size_t blue_size # The size of `blue` + float *red # The gamma ramp for the red channel + float *green # The gamma ramp for the green channel + float *blue # The gamma ramp for the blue channel + + ctypedef struct libgamma_gamma_rampsd_t: + # Gamma ramp structure for `double` gamma ramps + size_t red_size # The size of `red` + size_t green_size # The size of `green` + size_t blue_size # The size of `blue` + double *red # The gamma ramp for the red channel + double *green # The gamma ramp for the green channel + double *blue # The gamma ramp for the blue channel + + +cdef extern size_t libgamma_list_methods(int *methods, size_t buf_size, int operation) nogil +''' +List available adjustment methods by their order of preference based on the environment + +@param methods Output array of methods, should be able to hold `LIBGAMMA_METHOD_COUNT` elements +@param buf_size The number of elements that fits in `methods`, it should be `LIBGAMMA_METHOD_COUNT`, + This is used to avoid writing outside the output buffer if this library adds new + adjustment methods without the users of the library recompiling +@param operation Allowed values: + 0: Methods that the environment suggests will work, excluding fake + 1: Methods that the environment suggests will work, including fake + 2: All real non-fake methods + 3: All real methods + 4: All methods + Other values invoke undefined behaviour +@return The number of element that have been stored in `methods`, or should + have been stored if the buffer was large enough +''' + + +cdef extern int libgamma_is_method_available(int method) nogil +''' +Check whether an adjustment method is available, non-existing (invalid) methods will be +identified as not available under the rationale that the library may be out of date + +@param method The adjustment method +@return Whether the adjustment method is available +''' + + +cdef extern void libgamma_method_capabilities(libgamma_method_capabilities_t *this, int method) nogil +''' +Return the capabilities of an adjustment method + +@param this The data structure to fill with the method's capabilities +@param method The adjustment method (display server and protocol) +''' + + +cdef extern char *libgamma_method_default_site(int method) nogil +''' +Return the default site for an adjustment method + +@param method The adjustment method (display server and protocol) +@return The default site, `NULL` if it cannot be determined or + if multiple sites are not supported by the adjustment + method. This value should not be `free`:d +''' + + +cdef extern const char *libgamma_method_default_site_variable(int method) nogil +''' +Return the default variable that determines +the default site for an adjustment method + +@param method The adjustment method (display server and protocol) +@return The environ variables that is used to determine the + default site. `NULL` if there is none, that is, if + the method does not support multiple sites. + This value should not be `free`:d. +''' + + +cdef extern int libgamma_site_initialise(libgamma_site_state_t *this, int method, char *site) nogil +''' +Initialise an allocated site state + +@param this The site state to initialise +@param method The adjustment method (display server and protocol) +@param site The site identifier, unless it is `NULL` it must a + `free`:able. One the state is destroyed the library + will attempt to free it. There you should not free + it yourself, and it must not be a string constant + or allocate on the stack. Note however that it will + not be `free`:d if this function fails. +@return Zero on success, otherwise (negative) the value of an + error identifier provided by this library +''' + + +cdef extern void libgamma_site_free(libgamma_site_state_t *this) nogil +''' +Release all resources held by a site state +and free the site state pointer + +@param this The site state +''' + + +cdef extern int libgamma_site_restore(libgamma_site_state_t *this) nogil +''' +Restore the gamma ramps all CRTC:s with a site to the system settings + +@param this The site state +@return Zero on success, otherwise (negative) the value of an + error identifier provided by this library +''' + + +cdef extern int libgamma_partition_initialise(libgamma_partition_state_t *this, libgamma_site_state_t* site, size_t partition) nogil +''' +Initialise an allocated partition state + +@param this The partition state to initialise +@param site The site state for the site that the partition belongs to. +@param partition The index of the partition within the site +@return Zero on success, otherwise (negative) the value of an + error identifier provided by this library +''' + + +cdef extern void libgamma_partition_free(libgamma_partition_state_t *this) nogil +''' +Release all resources held by a partition state +and free the partition state pointer + +@param this The partition state +''' + + +cdef extern int libgamma_partition_restore(libgamma_partition_state_t *this) nogil +''' +Restore the gamma ramps all CRTC:s with a partition to the system settings + +@param this The partition state +@return Zero on success, otherwise (negative) the value of an + error identifier provided by this library +''' + + +cdef extern int libgamma_crtc_initialise(libgamma_crtc_state_t *this, libgamma_partition_state_t *partition, size_t crtc) nogil +''' +Initialise an allocated CRTC state + +@param this The CRTC state to initialise +@param partition The partition state for the partition that the CRTC belongs to +@param crtc The index of the CRTC within the partition +@return Zero on success, otherwise (negative) the value of an + error identifier provided by this library +''' + + +cdef extern void libgamma_crtc_free(libgamma_crtc_state_t *this) nogil +''' +Release all resources held by a CRTC state +and free the CRTC state pointer + +@param this The CRTC state +''' + + +cdef extern int libgamma_crtc_restore(libgamma_crtc_state_t *this) nogil +''' +Restore the gamma ramps for a CRTC to the system settings for that CRTC + +@param this The CRTC state +@return Zero on success, otherwise (negative) the value of an + error identifier provided by this library +''' + + +cdef extern int libgamma_get_crtc_information(libgamma_crtc_information_t *this, libgamma_crtc_state_t *crtc, int32_t fields) nogil +''' +Read information about a CRTC + +@param this Instance of a data structure to fill with the information about the CRTC +@param crtc The state of the CRTC whose information should be read +@param fields OR:ed identifiers for the information about the CRTC that should be read +@return Zero on success, -1 on error; on error refer to the error reports in `this` +''' + + +cdef extern void libgamma_crtc_information_destroy(libgamma_crtc_information_t *this) nogil +''' +Release all resources in an information data structure for a CRTC + +@param this The CRTC information +''' + + +cdef extern int libgamma_crtc_get_gamma_ramps8(libgamma_crtc_state_t *this, libgamma_gamma_ramps8_t *ramps) nogil +''' +Get the current gamma ramps for a CRTC, 8-bit gamma-depth version + +@param this The CRTC state +@param ramps The gamma ramps to fill with the current values +@return Zero on success, otherwise (negative) the value of an + error identifier provided by this library +''' + + +cdef extern int libgamma_crtc_set_gamma_ramps8(libgamma_crtc_state_t *this, libgamma_gamma_ramps8_t ramps) nogil +''' +Set the gamma ramps for a CRTC, 8-bit gamma-depth version + +@param this The CRTC state +@param ramps The gamma ramps to apply +@return Zero on success, otherwise (negative) the value of an + error identifier provided by this library +''' + + +cdef extern int libgamma_crtc_get_gamma_ramps16(libgamma_crtc_state_t *this, libgamma_gamma_ramps16_t *ramps) nogil +''' +Get the current gamma ramps for a CRTC, 16-bit gamma-depth version + +@param this The CRTC state +@param ramps The gamma ramps to fill with the current values +@return Zero on success, otherwise (negative) the value of an + error identifier provided by this library +''' + + +cdef extern int libgamma_crtc_set_gamma_ramps16(libgamma_crtc_state_t *this, libgamma_gamma_ramps16_t ramps) nogil +''' +Set the gamma ramps for a CRTC, 16-bit gamma-depth version + +@param this The CRTC state +@param ramps The gamma ramps to apply +@return Zero on success, otherwise (negative) the value of an + error identifier provided by this library +''' + + +cdef extern int libgamma_crtc_get_gamma_ramps32(libgamma_crtc_state_t *this, libgamma_gamma_ramps32_t *ramps) nogil +''' +Get the current gamma ramps for a CRTC, 32-bit gamma-depth version + +@param this The CRTC state +@param ramps The gamma ramps to fill with the current values +@return Zero on success, otherwise (negative) the value of an + error identifier provided by this library +''' + + +cdef extern int libgamma_crtc_set_gamma_ramps32(libgamma_crtc_state_t *this, libgamma_gamma_ramps32_t ramps) nogil +''' +Set the gamma ramps for a CRTC, 32-bit gamma-depth version + +@param this The CRTC state +@param ramps The gamma ramps to apply +@return Zero on success, otherwise (negative) the value of an + error identifier provided by this library +''' + + +cdef extern int libgamma_crtc_get_gamma_ramps64(libgamma_crtc_state_t *this, libgamma_gamma_ramps64_t *ramps) nogil +''' +Get the current gamma ramps for a CRTC, 64-bit gamma-depth version + +@param this The CRTC state +@param ramps The gamma ramps to fill with the current values +@return Zero on success, otherwise (negative) the value of an + error identifier provided by this library +''' + + +cdef extern int libgamma_crtc_set_gamma_ramps64(libgamma_crtc_state_t *this, libgamma_gamma_ramps64_t ramps) nogil +''' +Set the gamma ramps for a CRTC, 64-bit gamma-depth version + +@param this The CRTC state +@param ramps The gamma ramps to apply +@return Zero on success, otherwise (negative) the value of an + error identifier provided by this library +''' + + +cdef extern int libgamma_crtc_get_gamma_rampsf(libgamma_crtc_state_t *this, libgamma_gamma_rampsf_t *ramps) nogil +''' +Get the current gamma ramps for a CRTC, `float` version + +@param this The CRTC state +@param ramps The gamma ramps to fill with the current values +@return Zero on success, otherwise (negative) the value of an + error identifier provided by this library +''' + + +cdef extern int libgamma_crtc_set_gamma_rampsf(libgamma_crtc_state_t *this, libgamma_gamma_rampsf_t ramps) nogil +''' +Set the gamma ramps for a CRTC, `float` version + +@param this The CRTC state +@param ramps The gamma ramps to apply +@return Zero on success, otherwise (negative) the value of an + error identifier provided by this library +''' + + + +cdef extern int libgamma_crtc_get_gamma_rampsd(libgamma_crtc_state_t *this, libgamma_gamma_rampsd_t *ramps) nogil +''' +Get the current gamma ramps for a CRTC, `double` version + +@param this The CRTC state +@param ramps The gamma ramps to fill with the current values +@return Zero on success, otherwise (negative) the value of an + error identifier provided by this library +''' + + +cdef extern int libgamma_crtc_set_gamma_rampsd(libgamma_crtc_state_t *this, libgamma_gamma_rampsd_t ramps) nogil +''' +Set the gamma ramps for a CRTC, `double` version + +@param this The CRTC state +@param ramps The gamma ramps to apply +@return Zero on success, otherwise (negative) the value of an + error identifier provided by this library +''' + + +def libgamma_native_list_methods(operation : int) -> list: + ''' + List available adjustment methods by their order of preference based on the environment + + @param operation Allowed values: + 0: Methods that the environment suggests will work, excluding fake + 1: Methods that the environment suggests will work, including fake + 2: All real non-fake methods + 3: All real methods + 4: All methods + Other values invoke undefined behaviour + @return :list A list of available adjustment methods + ''' + cdef int *methods + cdef size_t buf_size + cdef size_t r + buf_size = 6 + methods = malloc(buf_size * sizeof(size_t)) + if methods == NULL: + raise MemoryError() + r = libgamma_list_methods(methods, buf_size, operation) + if r > buf_size: + buf_size = r + free(methods) + methods = malloc(buf_size * sizeof(size_t)) + if methods == NULL: + raise MemoryError() + libgamma_list_methods(methods, buf_size, operation) + rc = [] + for i in range(r): + rc.append(methods[i]) + free(methods) + return rc + + +def libgamma_native_is_method_available(method : int) -> int: + ''' + Check whether an adjustment method is available, non-existing (invalid) methods will be + identified as not available under the rationale that the library may be out of date + + @param method The adjustment method + @return Whether the adjustment method is available + ''' + return int(libgamma_is_method_available(method)) + + +def libgamma_native_method_capabilities(method : int) -> tuple: + ''' + Return the capabilities of an adjustment method + + @param method The adjustment method (display server and protocol) + @return :(int, int) Input parameters for `MethodCapabilities.__init__` + ''' + cdef libgamma_method_capabilities_t caps + libgamma_method_capabilities(&caps, method) + booleans = 0 + crtc_information = int(caps.crtc_information) + booleans |= (0 if caps.default_site_known == 0 else 1) << 0 + booleans |= (0 if caps.multiple_sites == 0 else 1) << 1 + booleans |= (0 if caps.multiple_partitions == 0 else 1) << 2 + booleans |= (0 if caps.multiple_crtcs == 0 else 1) << 3 + booleans |= (0 if caps.partitions_are_graphics_cards == 0 else 1) << 4 + booleans |= (0 if caps.site_restore == 0 else 1) << 5 + booleans |= (0 if caps.partition_restore == 0 else 1) << 6 + booleans |= (0 if caps.crtc_restore == 0 else 1) << 7 + booleans |= (0 if caps.identical_gamma_sizes == 0 else 1) << 8 + booleans |= (0 if caps.fixed_gamma_size == 0 else 1) << 9 + booleans |= (0 if caps.fixed_gamma_depth == 0 else 1) << 10 + booleans |= (0 if caps.real == 0 else 1) << 11 + booleans |= (0 if caps.fake == 0 else 1) << 12 + return (crtc_information, booleans) + + +def libgamma_native_method_default_site(method : int) -> str: + ''' + Return the default site for an adjustment method + + @param method The adjustment method (display server and protocol) + @return The default site, `None` if it cannot be determined or + if multiple sites are not supported by the adjustment + method + ''' + cdef char *var + cdef bytes bs + var = libgamma_method_default_site(method) + if var is NULL: + return None + bs = var + return bs.decode('utf-8', 'strict') + + +def libgamma_native_method_default_site_variable(method : int) -> str: + ''' + Return the default variable that determines + the default site for an adjustment method + + @param method The adjustment method (display server and protocol) + @return The environ variables that is used to determine the + default site. `None` if there is none, that is, if + the method does not support multiple sites. + ''' + cdef const char *var + cdef bytes bs + var = libgamma_method_default_site_variable(method) + if var is NULL: + return None + bs = var + return bs.decode('utf-8', 'strict') + + +def libgamma_native_site_create(method : int, site : str) -> tuple: + ''' + Create an allocated site state + + @param method The adjustment method (display server and protocol) + @param site The site identifier, unless it is `NULL` it must a + `free`:able. One the state is destroyed the library + will attempt to free it. There you should not free + it yourself, and it must not be a string constant + or allocate on the stack. Note however that it will + not be `free`:d if this function fails. + @return :(site:int, partitions:int) First value: The created site, zero on error + Second value: The number of partitions in the site, + on error: the value of the error identifier + provided by this library or `errno` + ''' + cdef libgamma_site_state_t *this + cdef char *site_ + cdef size_t this_address + this = malloc(sizeof(libgamma_site_state_t)) + if this is NULL: + raise MemoryError() + this_address = this + site_ = NULL + if site is not None: + site_bs = site.encode('utf-8') + bytes([0]) + site_ = malloc(len(site_bs) * sizeof(char)) + if site_ is None: + free(this) + raise MemoryError() + for i in range(len(site_bs)): + site_[i] = (site_bs[i]) + r = int(libgamma_site_initialise(this, method, site_)) + if not r == 0: + libgamma_site_free(this) + return (0, int(errno) if r == -1 else r) + return (int(this_address), int(this.partitions_available)) + + +def libgamma_native_site_free(this : int): + ''' + Release all resources held by a site state + and free the CRTC state pointer + + @param this The site state + ''' + cdef size_t this_address + cdef libgamma_site_state_t *this_ + this_address = this + this_ = this_address + libgamma_site_free(this_) + + +def libgamma_native_site_restore(this : int) -> int: + ''' + Restore the gamma ramps all CRTC:s with a site to the system settings + + @param this The site state + @return Zero on success, otherwise the value of an error + identifier provided by this library or `errno` + ''' + cdef size_t this_address + cdef libgamma_site_state_t *this_ + this_address = this + this_ = this_address + r = int(libgamma_site_restore(this_)) + return int(errno) if r == -1 else r + + +def libgamma_native_partition_create(site : int, partition : int) -> tuple: + ''' + Create an allocated partition state + + @param site The site state for the site that the partition belongs to + @param partition The index of the partition within the site + @return :(site:int, partitions:int) First value: The created partition, zero on error + Second value: The number of CRTC:s in the partition, + on error: the value of the error identifier + provided by this library or `errno` + ''' + cdef libgamma_partition_state_t *this + cdef libgamma_site_state_t *site_ + cdef size_t this_address + cdef size_t site_address + site_address = site + site_ = site_address + this = malloc(sizeof(libgamma_partition_state_t)) + if this is NULL: + raise MemoryError() + this_address = this + r = int(libgamma_partition_initialise(this, site_, partition)) + if not r == 0: + libgamma_partition_free(this) + return (0, int(errno) if r == -1 else r) + return (int(this_address), int(this.crtcs_available)) + + +def libgamma_native_partition_free(this : int): + ''' + Release all resources held by a partition state + and free the partition state pointer + + @param this The partition state + ''' + cdef size_t this_address + cdef libgamma_partition_state_t *this_ + this_address = this + this_ = this_address + libgamma_partition_free(this_) + + +def libgamma_native_partition_restore(this : int) -> int: + ''' + Restore the gamma ramps all CRTC:s with a partition to the system settings + + @param this The partition state + @return Zero on success, otherwise the value of an error + identifier provided by this library or `errno` + ''' + cdef size_t this_address + cdef libgamma_partition_state_t *this_ + this_address = this + this_ = this_address + r = int(libgamma_partition_restore(this_)) + return int(errno) if r == -1 else r + + +def libgamma_native_crtc_create(partition : int, crtc : int) -> tuple: + ''' + Create an allocated CRTC state + + @param partition The partition state for the partition that the CRTC belongs to. + @param crtc The index of the CRTC within the partition + @return :(int, int) First value: The created CRTC, zero on error + Second value: Zero on success, otherwise the value of an error + identifier provided by this library or `errno` + ''' + cdef libgamma_crtc_state_t *this + cdef libgamma_partition_state_t *partition_ + cdef size_t this_address + cdef size_t partition_address + partition_address = partition + partition_ = partition_address + this = malloc(sizeof(libgamma_crtc_state_t)) + if this is NULL: + raise MemoryError() + this_address = this + r = int(libgamma_crtc_initialise(this, partition_, crtc)) + if not r == 0: + libgamma_crtc_free(this) + return (0, int(errno) if r == -1 else r) + return (int(this_address), 0) + + +def libgamma_native_crtc_free(this : int): + ''' + Release all resources held by a CRTC state + and free the CRTC state pointer + + @param this The CRTC state + ''' + cdef size_t this_address + cdef libgamma_crtc_state_t *this_ + this_address = this + this_ = this_address + libgamma_crtc_free(this_) + + +def libgamma_native_crtc_restore(this : int) -> int: + ''' + Restore the gamma ramps for a CRTC to the system settings for that CRTC + + @param this The CRTC state + @return Zero on success, otherwise the value of an error + identifier provided by this library or `errno` + ''' + cdef size_t this_address + cdef libgamma_crtc_state_t *this_ + this_address = this + this_ = this_address + r = int(libgamma_crtc_restore(this_)) + return int(errno) if r == -1 else r + + +def libgamma_native_get_crtc_information(crtc : int, fields : int) -> tuple: + ''' + Read information about a CRTC + + @param crtc The state of the CRTC whose information should be read + @param field OR:ed identifiers for the information about the CRTC that should be read + @return :(list, :int) First value: Input parametrs for `CRTCInformation.__init__` + Second value: Zero on success, -1 on error; on error refer to + the error reports in the return + ''' + cdef libgamma_crtc_information_t info + cdef size_t crtc_address + cdef libgamma_crtc_state_t *crtc_ + cdef bytes bs + crtc_address = crtc + crtc_ = crtc_address + r = int(libgamma_get_crtc_information(&info, crtc_, fields)) + rc = [] + connector_name = None + if info.connector_name is not NULL: + bs = info.connector_name + connector_name = bs.decode('utf-8', 'strict') + edid = None + if info.edid is not NULL: + bs = info.edid[:info.edid_length] + edid = bs + rc.append(edid) + rc.append(int(info.edid_error)) + rc.append(int(info.width_mm)) + rc.append(int(info.width_mm_error)) + rc.append(int(info.height_mm)) + rc.append(int(info.height_mm_error)) + rc.append(int(info.width_mm_edid)) + rc.append(int(info.width_mm_edid_error)) + rc.append(int(info.height_mm_edid)) + rc.append(int(info.height_mm_edid_error)) + rc.append(int(info.red_gamma_size)) + rc.append(int(info.green_gamma_size)) + rc.append(int(info.blue_gamma_size)) + rc.append(int(info.gamma_size_error)) + rc.append(int(info.gamma_depth)) + rc.append(int(info.gamma_depth_error)) + rc.append(int(info.gamma_support)) + rc.append(int(info.gamma_support_error)) + rc.append(int(info.subpixel_order)) + rc.append(int(info.subpixel_order_error)) + rc.append(int(info.active)) + rc.append(int(info.active_error)) + rc.append(connector_name) + rc.append(int(info.connector_name_error)) + rc.append(int(info.connector_type)) + rc.append(int(info.connector_type_error)) + rc.append(float(info.gamma_red)) + rc.append(float(info.gamma_green)) + rc.append(float(info.gamma_blue)) + rc.append(int(info.gamma_error)) + libgamma_crtc_information_destroy(&info) + return (rc, r) + + +def libgamma_native_crtc_get_gamma_ramps8(this : int, ramps : int) -> int: + ''' + Get the current gamma ramps for a CRTC, 8-bit gamma-depth version + + @param this The CRTC state + @param ramps The gamma ramps to fill with the current values + @return Zero on success, otherwise the value of an error + identifier provided by this library or `errno` + ''' + cdef size_t this_address + cdef size_t ramps_address + cdef libgamma_crtc_state_t *this_ + cdef libgamma_gamma_ramps8_t *ramps_ + this_address = this + ramps_address = ramps + this_ = this_address + ramps_ = ramps_address + r = int(libgamma_crtc_get_gamma_ramps8(this_, ramps_)) + return int(errno) if r == -1 else r + + +def libgamma_native_crtc_set_gamma_ramps8(this : int, ramps : int) -> int: + ''' + Set the gamma ramps for a CRTC, 8-bit gamma-depth version + + @param this The CRTC state + @param ramps The gamma ramps to apply + @return Zero on success, otherwise the value of an error + identifier provided by this library or `errno` + ''' + cdef size_t this_address + cdef size_t ramps_address + cdef libgamma_crtc_state_t *this_ + cdef libgamma_gamma_ramps8_t *ramps_ + this_address = this + ramps_address = ramps + this_ = this_address + ramps_ = ramps_address + r = int(libgamma_crtc_set_gamma_ramps8(this_, ramps_[0])) + return int(errno) if r == -1 else r + + +def libgamma_native_crtc_get_gamma_ramps16(this : int, ramps : int) -> int: + ''' + Get the current gamma ramps for a CRTC, 16-bit gamma-depth version + + @param this The CRTC state + @param ramps The gamma ramps to fill with the current values + @return Zero on success, otherwise the value of an error + identifier provided by this library or `errno` + ''' + cdef size_t this_address + cdef size_t ramps_address + cdef libgamma_crtc_state_t *this_ + cdef libgamma_gamma_ramps16_t *ramps_ + this_address = this + ramps_address = ramps + this_ = this_address + ramps_ = ramps_address + r = int(libgamma_crtc_get_gamma_ramps16(this_, ramps_)) + return int(errno) if r == -1 else r + + +def libgamma_native_crtc_set_gamma_ramps16(this : int, ramps : int) -> int: + ''' + Set the gamma ramps for a CRTC, 16-bit gamma-depth version + + @param this The CRTC state + @param ramps The gamma ramps to apply + @return Zero on success, otherwise the value of an error + identifier provided by this library or `errno` + ''' + cdef size_t this_address + cdef size_t ramps_address + cdef libgamma_crtc_state_t *this_ + cdef libgamma_gamma_ramps16_t *ramps_ + this_address = this + ramps_address = ramps + this_ = this_address + ramps_ = ramps_address + r = int(libgamma_crtc_set_gamma_ramps16(this_, ramps_[0])) + return int(errno) if r == -1 else r + + +def libgamma_native_crtc_get_gamma_ramps32(this : int, ramps : int) -> int: + ''' + Get the current gamma ramps for a CRTC, 32-bit gamma-depth version + + @param this The CRTC state + @param ramps The gamma ramps to fill with the current values + @return Zero on success, otherwise the value of an error + identifier provided by this library or `errno` + ''' + cdef size_t this_address + cdef size_t ramps_address + cdef libgamma_crtc_state_t *this_ + cdef libgamma_gamma_ramps32_t *ramps_ + this_address = this + ramps_address = ramps + this_ = this_address + ramps_ = ramps_address + r = int(libgamma_crtc_get_gamma_ramps32(this_, ramps_)) + return int(errno) if r == -1 else r + + +def libgamma_native_crtc_set_gamma_ramps32(this : int, ramps : int) -> int: + ''' + Set the gamma ramps for a CRTC, 32-bit gamma-depth version + + @param this The CRTC state + @param ramps The gamma ramps to apply + @return Zero on success, otherwise the value of an error + identifier provided by this library or `errno` + ''' + cdef size_t this_address + cdef size_t ramps_address + cdef libgamma_crtc_state_t *this_ + cdef libgamma_gamma_ramps32_t *ramps_ + this_address = this + ramps_address = ramps + this_ = this_address + ramps_ = ramps_address + r = int(libgamma_crtc_set_gamma_ramps32(this_, ramps_[0])) + return int(errno) if r == -1 else r + + +def libgamma_native_crtc_get_gamma_ramps64(this : int, ramps : int) -> int: + ''' + Get the current gamma ramps for a CRTC, 64-bit gamma-depth version + + @param this The CRTC state + @param ramps The gamma ramps to fill with the current values + @return Zero on success, otherwise the value of an error + identifier provided by this library or `errno` + ''' + cdef size_t this_address + cdef size_t ramps_address + cdef libgamma_crtc_state_t *this_ + cdef libgamma_gamma_ramps64_t *ramps_ + this_address = this + ramps_address = ramps + this_ = this_address + ramps_ = ramps_address + r = int(libgamma_crtc_get_gamma_ramps64(this_, ramps_)) + return int(errno) if r == -1 else r + + +def libgamma_native_crtc_set_gamma_ramps64(this : int, ramps : int) -> int: + ''' + Set the gamma ramps for a CRTC, 64-bit gamma-depth version + + @param this The CRTC state + @param ramps The gamma ramps to apply + @return Zero on success, otherwise the value of an error + identifier provided by this library or `errno` + ''' + cdef size_t this_address + cdef size_t ramps_address + cdef libgamma_crtc_state_t * this_ + cdef libgamma_gamma_ramps64_t * ramps_ + this_address = this + ramps_address = ramps + this_ = this_address + ramps_ = ramps_address + r = int(libgamma_crtc_set_gamma_ramps64(this_, ramps_[0])) + return int(errno) if r == -1 else r + + +def libgamma_native_crtc_get_gamma_rampsf(this : int, ramps : int) -> int: + ''' + Get the current gamma ramps for a CRTC, `float` version + + @param this The CRTC state + @param ramps The gamma ramps to fill with the current values + @return Zero on success, otherwise the value of an error + identifier provided by this library or `errno` + ''' + cdef size_t this_address + cdef size_t ramps_address + cdef libgamma_crtc_state_t *this_ + cdef libgamma_gamma_rampsf_t *ramps_ + this_address = this + ramps_address = ramps + this_ = this_address + ramps_ = ramps_address + r = int(libgamma_crtc_get_gamma_rampsf(this_, ramps_)) + return int(errno) if r == -1 else r + + +def libgamma_native_crtc_set_gamma_rampsf(this : int, ramps : int) -> int: + ''' + Set the gamma ramps for a CRTC, `float` version + + @param this The CRTC state + @param ramps The gamma ramps to apply + @return Zero on success, otherwise the value of an error + identifier provided by this library or `errno` + ''' + cdef size_t this_address + cdef size_t ramps_address + cdef libgamma_crtc_state_t *this_ + cdef libgamma_gamma_rampsf_t *ramps_ + this_address = this + ramps_address = ramps + this_ = this_address + ramps_ = ramps_address + r = int(libgamma_crtc_set_gamma_rampsf(this_, ramps_[0])) + return int(errno) if r == -1 else r + + +def libgamma_native_crtc_get_gamma_rampsd(this : int, ramps : int) -> int: + ''' + Get the current gamma ramps for a CRTC, `double` version + + @param this The CRTC state + @param ramps The gamma ramps to fill with the current values + @return Zero on success, otherwise the value of an error + identifier provided by this library or `errno` + ''' + cdef size_t this_address + cdef size_t ramps_address + cdef libgamma_crtc_state_t *this_ + cdef libgamma_gamma_rampsd_t *ramps_ + this_address = this + ramps_address = ramps + this_ = this_address + ramps_ = ramps_address + r = int(libgamma_crtc_get_gamma_rampsd(this_, ramps_)) + return int(errno) if r == -1 else r + + +def libgamma_native_crtc_set_gamma_rampsd(this : int, ramps : int) -> int: + ''' + Set the gamma ramps for a CRTC, `double` version + + @param this The CRTC state + @param ramps The gamma ramps to apply + @return Zero on success, otherwise the value of an error + identifier provided by this library or `errno` + ''' + cdef size_t this_address + cdef size_t ramps_address + cdef libgamma_crtc_state_t *this_ + cdef libgamma_gamma_rampsd_t *ramps_ + this_address = this + ramps_address = ramps + this_ = this_address + ramps_ = ramps_address + r = int(libgamma_crtc_set_gamma_rampsd(this_, ramps_[0])) + return int(errno) if r == -1 else r diff --git a/libgamma_native_method.pyx b/libgamma_native_method.pyx new file mode 100644 index 0000000..96eee7c --- /dev/null +++ b/libgamma_native_method.pyx @@ -0,0 +1,616 @@ +# -*- python -*- +# See LICENSE file for copyright and license details. +cimport cython + +from libc.stdint cimport * +from libc.stdlib cimport malloc +from libc.stddef cimport size_t +from libc.errno cimport errno + + +cdef extern from "include-libgamma.h": + ctypedef struct libgamma_gamma_ramps8_t: + # Gamma ramp structure for 8-bit gamma ramps + size_t red_size # The size of `red` + size_t green_size # The size of `green` + size_t blue_size # The size of `blue` + uint8_t *red # The gamma ramp for the red channel + uint8_t *green # The gamma ramp for the green channel + uint8_t *blue # The gamma ramp for the blue channel + + ctypedef struct libgamma_gamma_ramps16_t: + # Gamma ramp structure for 16-bit gamma ramps + size_t red_size # The size of `red` + size_t green_size # The size of `green` + size_t blue_size # The size of `blue` + uint16_t *red # The gamma ramp for the red channel + uint16_t *green # The gamma ramp for the green channel + uint16_t *blue # The gamma ramp for the blue channel + + ctypedef struct libgamma_gamma_ramps32_t: + # Gamma ramp structure for 32-bit gamma ramps + size_t red_size # The size of `red` + size_t green_size # The size of `green` + size_t blue_size # The size of `blue` + uint32_t *red # The gamma ramp for the red channel + uint32_t *green # The gamma ramp for the green channel + uint32_t *blue # The gamma ramp for the blue channel + + ctypedef struct libgamma_gamma_ramps64_t: + # Gamma ramp structure for 64-bit gamma ramps + size_t red_size # The size of `red` + size_t green_size # The size of `green` + size_t blue_size # The size of `blue` + uint64_t *red # The gamma ramp for the red channel + uint64_t *green # The gamma ramp for the green channel + uint64_t *blue # The gamma ramp for the blue channel + + ctypedef struct libgamma_gamma_rampsf_t: + # Gamma ramp structure for `float` gamma ramps + size_t red_size # The size of `red` + size_t green_size # The size of `green` + size_t blue_size # The size of `blue` + float *red # The gamma ramp for the red channel + float *green # The gamma ramp for the green channel + float *blue # The gamma ramp for the blue channel + + ctypedef struct libgamma_gamma_rampsd_t: + # Gamma ramp structure for `double` gamma ramps + size_t red_size # The size of `red` + size_t green_size # The size of `green` + size_t blue_size # The size of `blue` + double *red # The gamma ramp for the red channel + double *green # The gamma ramp for the green channel + double *blue # The gamma ramp for the blue channel + +cdef extern int libgamma_gamma_ramps8_initialise(libgamma_gamma_ramps8_t *this) nogil +''' +Initialise a gamma ramp in the proper way that allows all adjustment +methods to read from and write to it without causing segmentation violation + +The input must have `red_size`, `green_size` and `blue_size` +set to the sizes of the gamma ramps that should be allocated + +@param this The gamma ramps +@return Zero on success, -1 on allocation error, `errno` will be set accordingly +''' + +cdef extern void libgamma_gamma_ramps8_free(libgamma_gamma_ramps8_t *this) nogil +''' +Release resources that are held by a gamma ramp strcuture that +has been allocated by `libgamma_gamma_ramps8_initialise` or +otherwise initialises in the proper manner, as well as release +the pointer to the structure + +@param this The gamma ramps +''' + +cdef extern int libgamma_gamma_ramps16_initialise(libgamma_gamma_ramps16_t *this) nogil +''' +Initialise a gamma ramp in the proper way that allows all adjustment +methods to read from and write to it without causing segmentation violation + +The input must have `red_size`, `green_size` and `blue_size` +set to the sizes of the gamma ramps that should be allocated + +@param this The gamma ramps +@return Zero on success, -1 on allocation error, `errno` will be set accordingly +''' + +cdef extern void libgamma_gamma_ramps16_free(libgamma_gamma_ramps16_t *this) nogil +''' +Release resources that are held by a gamma ramp strcuture that +has been allocated by `libgamma_gamma_ramps16_initialise` or +otherwise initialises in the proper manner, as well as release +the pointer to the structure + +@param this The gamma ramps +''' + +cdef extern int libgamma_gamma_ramps32_initialise(libgamma_gamma_ramps32_t *this) nogil +''' +Initialise a gamma ramp in the proper way that allows all adjustment +methods to read from and write to it without causing segmentation violation + +The input must have `red_size`, `green_size` and `blue_size` +set to the sizes of the gamma ramps that should be allocated + +@param this The gamma ramps +@return Zero on success, -1 on allocation error, `errno` will be set accordingly +''' + +cdef extern void libgamma_gamma_ramps32_free(libgamma_gamma_ramps32_t *this) nogil +''' +Release resources that are held by a gamma ramp strcuture that +has been allocated by `libgamma_gamma_ramps32_initialise` or +otherwise initialises in the proper manner, as well as release +the pointer to the structure + +@param this The gamma ramps +''' + +cdef extern int libgamma_gamma_ramps64_initialise(libgamma_gamma_ramps64_t *this) nogil +''' +Initialise a gamma ramp in the proper way that allows all adjustment +methods to read from and write to it without causing segmentation violation + +The input must have `red_size`, `green_size` and `blue_size` +set to the sizes of the gamma ramps that should be allocated + +@param this The gamma ramps +@return Zero on success, -1 on allocation error, `errno` will be set accordingly +''' + +cdef extern void libgamma_gamma_ramps64_free(libgamma_gamma_ramps64_t *this) nogil +''' +Release resources that are held by a gamma ramp strcuture that +has been allocated by `libgamma_gamma_ramps64_initialise` or +otherwise initialises in the proper manner, as well as release +the pointer to the structure + +@param this The gamma ramps +''' + +cdef extern int libgamma_gamma_rampsf_initialise(libgamma_gamma_rampsf_t *this) nogil +''' +Initialise a gamma ramp in the proper way that allows all adjustment +methods to read from and write to it without causing segmentation violation + +The input must have `red_size`, `green_size` and `blue_size` +set to the sizes of the gamma ramps that should be allocated + +@param this The gamma ramps +@return Zero on success, -1 on allocation error, `errno` will be set accordingly +''' + +cdef extern void libgamma_gamma_rampsf_free(libgamma_gamma_rampsf_t *this) nogil +''' +Release resources that are held by a gamma ramp strcuture that +has been allocated by `libgamma_gamma_rampsf_initialise` or +otherwise initialises in the proper manner, as well as release +the pointer to the structure + +@param this The gamma ramps +''' + +cdef extern int libgamma_gamma_rampsd_initialise(libgamma_gamma_rampsd_t *this) nogil +''' +Initialise a gamma ramp in the proper way that allows all adjustment +methods to read from and write to it without causing segmentation violation + +The input must have `red_size`, `green_size` and `blue_size` +set to the sizes of the gamma ramps that should be allocated + +@param this The gamma ramps +@return Zero on success, -1 on allocation error, `errno` will be set accordingly +''' + +cdef extern void libgamma_gamma_rampsd_free(libgamma_gamma_rampsd_t *this) nogil +''' +Release resources that are held by a gamma ramp strcuture that +has been allocated by `libgamma_gamma_rampsd_initialise` or +otherwise initialises in the proper manner, as well as release +the pointer to the structure + +@param this The gamma ramps +''' + + +def libgamma_native_gamma_ramps8_create(red_size : int, green_size : int, blue_size : int): + ''' + Create a gamma ramp in the proper way that allows all adjustment methods + to read from and write to it without causing segmentation violation + + @param red_size The size of the gamma ramp for the red channel + @param green_size The size of the gamma ramp for the green channel + @param blue_size The size of the gamma ramp for the blue channel + @return :(int){4}|int The tuple that describes the created data, `errno` on failure: + Element 1: The address of the gamma ramp structure + Element 2: The address of the gamma ramp for the red channel + Element 3: The address of the gamma ramp for the green channel + Element 4: The address of the gamma ramp for the blue channel + ''' + cdef void *allocation = malloc(sizeof(libgamma_gamma_ramps8_t)) + cdef libgamma_gamma_ramps8_t *item = allocation + cdef size_t red, green, blue + if item is NULL: + return int(errno) + item.red_size = red_size + item.green_size = green_size + item.blue_size = blue_size + if libgamma_gamma_ramps8_initialise(item) < 0: + return int(errno) + red = (item.red) + green = (item.green) + blue = (item.blue) + return (int(allocation), int(red), int(green), int(blue)) + + +def libgamma_native_gamma_ramps8_free(this : int): + ''' + Release resources that are held by a gamma ramp strcuture that + has been allocated by `libgamma_native_gamma_ramps8_create` or + otherwise created in the proper manner, as well as release the + pointer to the structure + + @param this The gamma ramps + ''' + cdef void *address = this + cdef libgamma_gamma_ramps8_t *item = address + libgamma_gamma_ramps8_free(item) + + +def libgamma_native_gamma_ramps8_get(this : int, index : int) -> int: + ''' + Read a stop in a gamma ramp + + @param this The gamma ramp + @param index The index of the gamma ramp stop + @return The value of the gamma ramp stop + ''' + cdef void *address = this + cdef uint8_t *ramp = address + return int(ramp[index]) + + +def libgamma_native_gamma_ramps8_set(this : int, index : int, value : int): + ''' + Modify a stop in a gamma ramp + + @param this The gamma ramp + @param index The index of the gamma ramp stop + @param value The value of the gamma ramp stop + ''' + cdef void *address = this + cdef uint8_t *ramp = address + ramp[index] = value + + +def libgamma_native_gamma_ramps16_create(red_size : int, green_size : int, blue_size : int): + ''' + Create a gamma ramp in the proper way that allows all adjustment methods + to read from and write to it without causing segmentation violation + + @param red_size The size of the gamma ramp for the red channel + @param green_size The size of the gamma ramp for the green channel + @param blue_size The size of the gamma ramp for the blue channel + @return :(int){4}|int The tuple that describes the created data, `errno` on failure: + Element 1: The address of the gamma ramp structure + Element 2: The address of the gamma ramp for the red channel + Element 3: The address of the gamma ramp for the green channel + Element 4: The address of the gamma ramp for the blue channel + ''' + cdef void *allocation = malloc(sizeof(libgamma_gamma_ramps16_t)) + cdef libgamma_gamma_ramps16_t *item = allocation + cdef size_t red, green, blue + if item is NULL: + return int(errno) + item.red_size = red_size + item.green_size = green_size + item.blue_size = blue_size + if libgamma_gamma_ramps16_initialise(item) < 0: + return int(errno) + red = (item.red) + green = (item.green) + blue = (item.blue) + return (int(allocation), int(red), int(green), int(blue)) + + +def libgamma_native_gamma_ramps16_free(this : int): + ''' + Release resources that are held by a gamma ramp strcuture that + has been allocated by `libgamma_native_gamma_ramps16_create` or + otherwise created in the proper manner, as well as release the + pointer to the structure + + @param this The gamma ramps + ''' + cdef void *address = this + cdef libgamma_gamma_ramps16_t *item = address + libgamma_gamma_ramps16_free(item) + + +def libgamma_native_gamma_ramps16_get(this : int, index : int) -> int: + ''' + Read a stop in a gamma ramp + + @param this The gamma ramp + @param index The index of the gamma ramp stop + @return The value of the gamma ramp stop + ''' + cdef void *address = this + cdef uint16_t *ramp = address + return int(ramp[index]) + + +def libgamma_native_gamma_ramps16_set(this : int, index : int, value : int): + ''' + Modify a stop in a gamma ramp + + @param this The gamma ramp + @param index The index of the gamma ramp stop + @param value The value of the gamma ramp stop + ''' + cdef void *address = this + cdef uint16_t *ramp = address + ramp[index] = value + + +def libgamma_native_gamma_ramps32_create(red_size : int, green_size : int, blue_size : int): + ''' + Create a gamma ramp in the proper way that allows all adjustment methods + to read from and write to it without causing segmentation violation + + @param red_size The size of the gamma ramp for the red channel + @param green_size The size of the gamma ramp for the green channel + @param blue_size The size of the gamma ramp for the blue channel + @return :(int){4}|int The tuple that describes the created data, `errno` on failure: + Element 1: The address of the gamma ramp structure + Element 2: The address of the gamma ramp for the red channel + Element 3: The address of the gamma ramp for the green channel + Element 4: The address of the gamma ramp for the blue channel + ''' + cdef void *allocation = malloc(sizeof(libgamma_gamma_ramps32_t)) + cdef libgamma_gamma_ramps32_t *item = allocation + cdef size_t red, green, blue + if item is NULL: + return int(errno) + item.red_size = red_size + item.green_size = green_size + item.blue_size = blue_size + if libgamma_gamma_ramps32_initialise(item) < 0: + return int(errno) + red = (item.red) + green = (item.green) + blue = (item.blue) + return (int(allocation), int(red), int(green), int(blue)) + + +def libgamma_native_gamma_ramps32_free(this : int): + ''' + Release resources that are held by a gamma ramp strcuture that + has been allocated by `libgamma_native_gamma_ramps32_create` or + otherwise created in the proper manner, as well as release the + pointer to the structure + + @param this The gamma ramps + ''' + cdef void *address = this + cdef libgamma_gamma_ramps32_t *item = address + libgamma_gamma_ramps32_free(item) + + +def libgamma_native_gamma_ramps32_get(this : int, index : int) -> int: + ''' + Read a stop in a gamma ramp + + @param this The gamma ramp + @param index The index of the gamma ramp stop + @return The value of the gamma ramp stop + ''' + cdef void *address = this + cdef uint32_t *ramp = address + return int(ramp[index]) + + +def libgamma_native_gamma_ramps32_set(this : int, index : int, value : int): + ''' + Modify a stop in a gamma ramp + + @param this The gamma ramp + @param index The index of the gamma ramp stop + @param value The value of the gamma ramp stop + ''' + cdef void *address = this + cdef uint32_t *ramp = address + ramp[index] = value + + +def libgamma_native_gamma_ramps64_create(red_size : int, green_size : int, blue_size : int): + ''' + Create a gamma ramp in the proper way that allows all adjustment methods + to read from and write to it without causing segmentation violation + + @param red_size The size of the gamma ramp for the red channel + @param green_size The size of the gamma ramp for the green channel + @param blue_size The size of the gamma ramp for the blue channel + @return :(int){4}|int The tuple that describes the created data, `errno` on failure: + Element 1: The address of the gamma ramp structure + Element 2: The address of the gamma ramp for the red channel + Element 3: The address of the gamma ramp for the green channel + Element 4: The address of the gamma ramp for the blue channel + ''' + cdef void *allocation = malloc(sizeof(libgamma_gamma_ramps64_t)) + cdef libgamma_gamma_ramps64_t *item = allocation + cdef size_t red, green, blue + if item is NULL: + return int(errno) + item.red_size = red_size + item.green_size = green_size + item.blue_size = blue_size + if libgamma_gamma_ramps64_initialise(item) < 0: + return int(errno) + red = (item.red) + green = (item.green) + blue = (item.blue) + return (int(allocation), int(red), int(green), int(blue)) + + +def libgamma_native_gamma_ramps64_free(this : int): + ''' + Release resources that are held by a gamma ramp strcuture that + has been allocated by `libgamma_native_gamma_ramps64_create` or + otherwise created in the proper manner, as well as release the + pointer to the structure + + @param this The gamma ramps + ''' + cdef void *address = this + cdef libgamma_gamma_ramps64_t *item = address + libgamma_gamma_ramps64_free(item) + + +def libgamma_native_gamma_ramps64_get(this : int, index : int) -> int: + ''' + Read a stop in a gamma ramp + + @param this The gamma ramp + @param index The index of the gamma ramp stop + @return The value of the gamma ramp stop + ''' + cdef void *address = this + cdef uint64_t *ramp = address + return int(ramp[index]) + + +def libgamma_native_gamma_ramps64_set(this : int, index : int, value : int): + ''' + Modify a stop in a gamma ramp + + @param this The gamma ramp + @param index The index of the gamma ramp stop + @param value The value of the gamma ramp stop + ''' + cdef void *address = this + cdef uint64_t *ramp = address + ramp[index] = value + + +def libgamma_native_gamma_rampsf_create(red_size : int, green_size : int, blue_size : int): + ''' + Create a gamma ramp in the proper way that allows all adjustment methods + to read from and write to it without causing segmentation violation + + @param red_size The size of the gamma ramp for the red channel + @param green_size The size of the gamma ramp for the green channel + @param blue_size The size of the gamma ramp for the blue channel + @return :(int){4}|int The tuple that describes the created data, `errno` on failure: + Element 1: The address of the gamma ramp structure + Element 2: The address of the gamma ramp for the red channel + Element 3: The address of the gamma ramp for the green channel + Element 4: The address of the gamma ramp for the blue channel + ''' + cdef void *allocation = malloc(sizeof(libgamma_gamma_rampsf_t)) + cdef libgamma_gamma_rampsf_t *item = allocation + cdef size_t red, green, blue + if item is NULL: + return int(errno) + item.red_size = red_size + item.green_size = green_size + item.blue_size = blue_size + if libgamma_gamma_rampsf_initialise(item) < 0: + return int(errno) + red = (item.red) + green = (item.green) + blue = (item.blue) + return (int(allocation), int(red), int(green), int(blue)) + + +def libgamma_native_gamma_rampsf_free(this : int): + ''' + Release resources that are held by a gamma ramp strcuture that + has been allocated by `libgamma_native_gamma_rampsf_create` or + otherwise created in the proper manner, as well as release the + pointer to the structure + + @param this The gamma ramps + ''' + cdef void *address = this + cdef libgamma_gamma_rampsf_t *item = address + libgamma_gamma_rampsf_free(item) + + +def libgamma_native_gamma_rampsf_get(this : int, index : int) -> float: + ''' + Read a stop in a gamma ramp + + @param this The gamma ramp + @param index The index of the gamma ramp stop + @return The value of the gamma ramp stop + ''' + cdef void *address = this + cdef float *ramp = address + return float(ramp[index]) + + +def libgamma_native_gamma_rampsf_set(this : int, index : int, value : float): + ''' + Modify a stop in a gamma ramp + + @param this The gamma ramp + @param index The index of the gamma ramp stop + @param value The value of the gamma ramp stop + ''' + cdef void *address = this + cdef float *ramp = address + ramp[index] = value + + +def libgamma_native_gamma_rampsd_create(red_size : int, green_size : int, blue_size : int): + ''' + Create a gamma ramp in the proper way that allows all adjustment + methods to read from and write to it without causing segmentation violation + + @param red_size The size of the gamma ramp for the red channel + @param green_size The size of the gamma ramp for the green channel + @param blue_size The size of the gamma ramp for the blue channel + @return :(int){4}|int The tuple that describes the created data, `errno` on failure: + Element 1: The address of the gamma ramp structure + Element 2: The address of the gamma ramp for the red channel + Element 3: The address of the gamma ramp for the green channel + Element 4: The address of the gamma ramp for the blue channel + ''' + cdef void *allocation = malloc(sizeof(libgamma_gamma_rampsd_t)) + cdef libgamma_gamma_rampsd_t *item = allocation + cdef size_t red, green, blue + if item is NULL: + return int(errno) + item.red_size = red_size + item.green_size = green_size + item.blue_size = blue_size + if libgamma_gamma_rampsd_initialise(item) < 0: + return int(errno) + red = (item.red) + green = (item.green) + blue = (item.blue) + return (int(allocation), int(red), int(green), int(blue)) + + +def libgamma_native_gamma_rampsd_free(this : int): + ''' + Release resources that are held by a gamma ramp strcuture that + has been allocated by `libgamma_native_gamma_rampsd_create` or + otherwise created in the proper manner, as well as release the + pointer to the structure + + @param this The gamma ramps + ''' + cdef void *address = this + cdef libgamma_gamma_rampsd_t *item = address + libgamma_gamma_rampsd_free(item) + + +def libgamma_native_gamma_rampsd_get(this : int, index : int) -> float: + ''' + Read a stop in a gamma ramp + + @param this The gamma ramp + @param index The index of the gamma ramp stop + @return The value of the gamma ramp stop + ''' + cdef void *address = this + cdef double *ramp = address + return float(ramp[index]) + + +def libgamma_native_gamma_rampsd_set(this : int, index : int, value : float): + ''' + Modify a stop in a gamma ramp + + @param this The gamma ramp + @param index The index of the gamma ramp stop + @param value The value of the gamma ramp stop + ''' + cdef void *address = this + cdef double *ramp = address + ramp[index] = value diff --git a/mk/linux.mk b/mk/linux.mk new file mode 100644 index 0000000..818e2e1 --- /dev/null +++ b/mk/linux.mk @@ -0,0 +1,2 @@ +PLATFORM = posix +LIBEXT = so diff --git a/mk/macos.mk b/mk/macos.mk new file mode 100644 index 0000000..35caab1 --- /dev/null +++ b/mk/macos.mk @@ -0,0 +1,2 @@ +PLATFORM = posix +LIBEXT = dylib diff --git a/mk/windows.mk b/mk/windows.mk new file mode 100644 index 0000000..8489de6 --- /dev/null +++ b/mk/windows.mk @@ -0,0 +1,2 @@ +PLATFORM = w32 +LIBEXT = dll diff --git a/src/include-libgamma.h b/src/include-libgamma.h deleted file mode 100644 index eb857e1..0000000 --- a/src/include-libgamma.h +++ /dev/null @@ -1,19 +0,0 @@ -/** - * pylibgamma — Python 3 wrapper for libgamma - * Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) - * - * This library 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 library 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 library. If not, see . - */ -#include - diff --git a/src/libgamma.py b/src/libgamma.py deleted file mode 100644 index 34c646c..0000000 --- a/src/libgamma.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- python -*- -''' -pylibgamma — Python 3 wrapper for libgamma -Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) - -This library 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 library 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 library. If not, see . -''' - -from libgamma_error import * -from libgamma_method import * -from libgamma_facade import * - diff --git a/src/libgamma_error.py b/src/libgamma_error.py deleted file mode 100644 index afefd5e..0000000 --- a/src/libgamma_error.py +++ /dev/null @@ -1,476 +0,0 @@ -# -*- python -*- -''' -pylibgamma — Python 3 wrapper for libgamma -Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) - -This library 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 library 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 library. If not, see . -''' - - - -class LibgammaGroup: - ''' - Class for `group` - ''' - - @property - def gid(self) -> int: - ''' - Getter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned. - ''' - from libgamma_native_error import libgamma_native_get_group_gid - return libgamma_native_get_group_gid() - - @gid.setter - def gid(self, value : int): - ''' - Setter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned. - ''' - from libgamma_native_error import libgamma_native_set_group_gid - libgamma_native_set_group_gid(value) - - - @property - def name(self) -> str: - ''' - Getter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, - `None` if the name of the group `group.gid` - cannot be determined. - ''' - from libgamma_native_error import libgamma_native_get_group_name - return libgamma_native_get_group_name() - - @name.setter - def name(self, value : str): - ''' - Setter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, - `None` if the name of the group `group.gid` - cannot be determined. - ''' - from libgamma_native_error import libgamma_native_set_group_name - libgamma_native_set_group_name(value) - - -group = LibgammaGroup() -''' - Group that the user needs to be a member of if -`LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned. -''' - - -def perror(name : str, error_code : int): - ''' - Prints an error to stderr in a `perror` fashion, - however this function will not translate the `libgamma` - errors into human-readable strings, it will simply - print the name of the error. If the value `error_code` - is the value of `LIBGAMMA_ERRNO_SET`, `perror` will be - used to print the current error stored in `errno`. - If `error_code` is non-negative (an `errno` value`), that - value will be stored in `errno` and `perror` will be - used to print it. Additionally, if the `error_code` is - the value of `LIBGAMMA_DEVICE_REQUIRE_GROUP` the - required group will be printed with its numerical value - and, if known, its name. - - @param name The text to add at the beginning. - @param value The error code, may be an `errno` value. - ''' - from libgamma_native_error import libgamma_native_perror - libgamma_native_perror(name, error_code) - - -def name_of_error(value : int) -> str: - ''' - Returns the name of the definition associated with a `libgamma` error code. - - @param value The error code. - @return The name of the definition associated with the error code, - `None` if the error code does not exist. - ''' - from libgamma_native_error import libgamma_native_name_of_error - return libgamma_native_name_of_error(value) - - -def value_of_error(name : str) -> int: - ''' - Return the value of a `libgamma` error definition refered to by name. - - @param name The name of the definition associated with the error code. - @return The error code, zero if the name is `None` - or does not refer to a `libgamma` error. - ''' - from libgamma_native_error import libgamma_native_value_of_error - return libgamma_native_value_of_error(name) - - - -LIBGAMMA_ERRNO_SET = -1 -''' -`errno` has be set with a standard error number -to indicate the what has gone wrong. -''' - -LIBGAMMA_NO_SUCH_ADJUSTMENT_METHOD = -2 -''' -The selected adjustment method does not exist -or has been excluded at compile-time. -''' - -LIBGAMMA_NO_SUCH_SITE = -3 -''' -The selected site does not exist. -''' - -LIBGAMMA_NO_SUCH_PARTITION = -4 -''' -The selected partition does not exist. -''' - -LIBGAMMA_NO_SUCH_CRTC = -5 -''' -The selected CRTC does not exist. -''' - -LIBGAMMA_IMPOSSIBLE_AMOUNT = -6 -''' -Counter overflowed when counting the number -of available items. -''' - -LIBGAMMA_CONNECTOR_DISABLED = -7 -''' -The selected connector is disabled, it does -not have a CRTC. -''' - -LIBGAMMA_OPEN_CRTC_FAILED = -8 -''' -The selected CRTC could not be opened, -reason unknown. -''' - -LIBGAMMA_CRTC_INFO_NOT_SUPPORTED = -9 -''' -The CRTC information field is not supported -by the adjustment method. -''' - -LIBGAMMA_GAMMA_RAMP_READ_FAILED = -10 -''' -Failed to read the current gamma ramps for -the selected CRTC, reason unknown. -''' - -LIBGAMMA_GAMMA_RAMP_WRITE_FAILED = -11 -''' -Failed to write the current gamma ramps for -the selected CRTC, reason unknown. -''' - -LIBGAMMA_GAMMA_RAMP_SIZE_CHANGED = -12 -''' -The specified ramp sizes does not match the -ramps sizes returned by the adjustment methods -in response to the query/command. -''' - -LIBGAMMA_MIXED_GAMMA_RAMP_SIZE = -13 -''' -The specified ramp sizes are not identical -which is required by the adjustment method. -(Only returned in debug mode.) -''' - -LIBGAMMA_WRONG_GAMMA_RAMP_SIZE = -14 -''' -The specified ramp sizes are not supported -by the adjustment method. -(Only returned in debug mode.) -''' - -LIBGAMMA_SINGLETON_GAMMA_RAMP = -15 -''' -The adjustment method reported that the gamma -ramps size is 1, or perhaps even zero or negative. -''' - -LIBGAMMA_LIST_CRTCS_FAILED = -16 -''' -The adjustment method failed to list -available CRTC:s, reason unknown. -''' - -LIBGAMMA_ACQUIRING_MODE_RESOURCES_FAILED = -17 -''' -Failed to acquire mode resources from the -adjustment method. -''' - -LIBGAMMA_NEGATIVE_PARTITION_COUNT = -18 -''' -The adjustment method reported that a negative -number of partitions exists in the site. -''' - -LIBGAMMA_NEGATIVE_CRTC_COUNT = -19 -''' -The adjustment method reported that a negative -number of CRTC:s exists in the partition. -''' - -LIBGAMMA_DEVICE_RESTRICTED = -20 -''' -Device cannot be access becauses of -insufficient permissions. -''' - -LIBGAMMA_DEVICE_ACCESS_FAILED = -21 -''' -Device cannot be access, reason unknown. -''' - -LIBGAMMA_DEVICE_REQUIRE_GROUP = -22 -''' -Device cannot be access, membership of the -`group.gid` (named by `group.name` (can be -`None`, if so `errno` may have been set to -tell why)) is required. -''' - -LIBGAMMA_GRAPHICS_CARD_REMOVED = -23 -''' -The graphics card appear to have been removed. -''' - -LIBGAMMA_STATE_UNKNOWN = -24 -''' -The state of the requested information is unknown. -''' - -LIBGAMMA_CONNECTOR_UNKNOWN = -25 -''' -Failed to determine which connector the -CRTC belongs to. -''' - -LIBGAMMA_CONNECTOR_TYPE_NOT_RECOGNISED = -26 -''' -The detected connector type is not listed -in this library and has to be updated. -''' - -LIBGAMMA_SUBPIXEL_ORDER_NOT_RECOGNISED = -27 -''' -The detected subpixel order is not listed -in this library and has to be updated. -''' - -LIBGAMMA_EDID_LENGTH_UNSUPPORTED = -28 -''' -The length of the EDID does not match that -of any supported EDID structure revision. -''' - -LIBGAMMA_EDID_WRONG_MAGIC_NUMBER = -29 -''' -The magic number in the EDID does not match -that of any supported EDID structure revision. -''' - -LIBGAMMA_EDID_REVISION_UNSUPPORTED = -30 -''' -The EDID structure revision used by the -monitor is not supported. -''' - -LIBGAMMA_GAMMA_NOT_SPECIFIED = -31 -''' -The gamma characteristics field in the EDID -is left unspecified. -(This could be considered a non-error.) -''' - -LIBGAMMA_EDID_CHECKSUM_ERROR = -32 -''' -The checksum in the EDID is incorrect, all -request information has been provided -by you cannot count on it. -''' - -LIBGAMMA_GAMMA_NOT_SPECIFIED_AND_EDID_CHECKSUM_ERROR = -33 -''' -Both of the errors `LIBGAMMA_GAMMA_NOT_SPECIFIED` -and `LIBGAMMA_EDID_CHECKSUM_ERROR` have occurred. -''' - -LIBGAMMA_GAMMA_RAMPS_SIZE_QUERY_FAILED = -34 -''' -Failed to query the gamma ramps size from the -adjustment method, reason unknown. -''' - -LIBGAMMA_OPEN_PARTITION_FAILED = -35 -''' -The selected partition could not be opened, -reason unknown. -''' - -LIBGAMMA_OPEN_SITE_FAILED = -36 -''' -The selected site could not be opened, -reason unknown. -''' - -LIBGAMMA_PROTOCOL_VERSION_QUERY_FAILED = -37 -''' -Failed to query the adjustment method for -its protocol version, reason unknown. -''' - -LIBGAMMA_PROTOCOL_VERSION_NOT_SUPPORTED = -38 -''' -The adjustment method's version of its -protocol is not supported. -''' - -LIBGAMMA_LIST_PARTITIONS_FAILED = -39 -''' -The adjustment method failed to list -available partitions, reason unknown. -''' - -LIBGAMMA_NULL_PARTITION = -40 -''' -Partition exists by index, but the partition -at that index does not exist. -''' - -LIBGAMMA_NOT_CONNECTED = -41 -''' -There is not monitor connected to the -connector of the selected CRTC. -''' - -LIBGAMMA_REPLY_VALUE_EXTRACTION_FAILED = -42 -''' -Data extraction from a reply from the -adjustment method failed, reason unknown. -''' - -LIBGAMMA_EDID_NOT_FOUND = -43 -''' -No EDID property was found on the output. -''' - -LIBGAMMA_LIST_PROPERTIES_FAILED = -44 -''' -Failed to list properties on the output, -reason unknown. -''' - -LIBGAMMA_PROPERTY_VALUE_QUERY_FAILED = -45 -''' -Failed to query a property's value from -the output, reason unknown. -''' - -LIBGAMMA_OUTPUT_INFORMATION_QUERY_FAILED = -46 -''' -A request for information on an output -failed, reason unknown. -''' - - -LIBGAMMA_ERROR_MIN = -46 -''' -The number of the libgamma error with the -lowest number. If this is lower than the -number your program thinks it should be sould -update your program for new errors. -''' - - - -class LibgammaError(Exception): - ''' - libgamma error class. - - @variable errno The error code. - @variable strerror The name of the error. - ''' - - def __init__(self, errno : int, strerror : str): - ''' - Constructor. - - @param errno The error code. - @param strerror The name of the error. - ''' - self.errno = errno - self.strerror = strerror - - def __str__(self) -> str: - ''' - Return the name of the error. - - @return The name of the error. - ''' - return self.strerror - - - def __repr__(self) -> str: - ''' - Create a string representation of the error. - - @return A string representation of the error. - ''' - return 'LibgammaError(%i, %s)' % (self.errno, repr(self.strerror)) - - - -def create_error(error_code : int) -> Exception: - ''' - Create an exception from an error code. - - @param error_code The error code. - @return :OSError|LibgammaError The error as a throwable object. - ''' - if error_code == LIBGAMMA_ERRNO_SET: - import ctypes - error_code = ctypes.get_errno() - - if error_code >= 0: - import libgamma_native_error as c - e = OSError() - e.errno = error_code - e.strerror = c.strerror(e.errno) - else: - strerror = name_of_error(error_code) - e = LibgammaError(error_code, strerror) - - return e - diff --git a/src/libgamma_facade.py b/src/libgamma_facade.py deleted file mode 100644 index 5920a5b..0000000 --- a/src/libgamma_facade.py +++ /dev/null @@ -1,147 +0,0 @@ -# -*- python -*- -''' -pylibgamma — Python 3 wrapper for libgamma -Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) - -This library 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 library 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 library. If not, see . -''' - - -from libgamma_method import MethodCapabilities - - - -def list_methods(operation : int) -> list: - ''' - List available adjustment methods by their order of preference based on the environment. - - @param operation Allowed values: - 0: Methods that the environment suggests will work, excluding fake. - 1: Methods that the environment suggests will work, including fake. - 2: All real non-fake methods. - 3: All real methods. - 4: All methods. - Other values invoke undefined behaviour. - @return :list A list of available adjustment methods. - ''' - from libgamma_native_facade import libgamma_native_list_methods - return libgamma_native_list_methods(operation) - - -def is_method_available(method : int) -> bool: - ''' - Check whether an adjustment method is available, non-existing (invalid) methods will be - identified as not available under the rationale that the library may be out of date. - - @param method The adjustment method. - @return Whether the adjustment method is available. - ''' - from libgamma_native_facade import libgamma_native_is_method_available - return not libgamma_native_is_method_available(method) == 0 - - -def method_capabilities(method : int) -> MethodCapabilities: - ''' - Return the capabilities of an adjustment method. - - @param this The data structure to fill with the method's capabilities - @param method The adjustment method (display server and protocol). - ''' - from libgamma_native_facade import libgamma_native_method_capabilities - caps = libgamma_native_method_capabilities(method) - return MethodCapabilities(*caps) - - -def method_default_site(method : int) -> str: - ''' - Return the default site for an adjustment method. - - @param method The adjustment method (display server and protocol.) - @return The default site, `None` if it cannot be determined or - if multiple sites are not supported by the adjustment - method. - ''' - from libgamma_native_facade import libgamma_native_method_default_site - return libgamma_native_method_default_site(method) - - -def method_default_site_variable(method : int) -> str: - ''' - Return the default variable that determines - the default site for an adjustment method. - - @param method The adjustment method (display server and protocol.) - @return The environ variables that is used to determine the - default site. `None` if there is none, that is, if - the method does not support multiple sites. - ''' - from libgamma_native_facade import libgamma_native_method_default_site_variable - return libgamma_native_method_default_site_variable(method) - - - -def behex_edid(edid : bytes) -> str: - ''' - Convert a raw representation of an EDID to a lowercase hexadecimal representation. - - @param edid The EDID in raw representation. - @return The EDID in lowercase hexadecimal representation. - ''' - return behex_edid_lowercase(edid) - - -def behex_edid_lowercase(edid : bytes) -> str: - ''' - Convert a raw representation of an EDID to a lowercase hexadecimal representation. - - @param edid The EDID in raw representation. - @return The EDID in lowercase hexadecimal representation. - ''' - rc = '' - for b in edid: - rc += '0123456789abcdef'[(b >> 4) & 15] - rc += '0123456789abcdef'[(b >> 0) & 15] - return rc - - -def behex_edid_uppercase(edid : bytes) -> str: - ''' - Convert a raw representation of an EDID to an uppercase hexadecimal representation. - - @param edid The EDID in raw representation. - @return The EDID in uppercase hexadecimal representation. - ''' - rc = '' - for b in edid: - rc += '0123456789ABCDEF'[(b >> 4) & 15] - rc += '0123456789ABCDEF'[(b >> 0) & 15] - return rc - - -def unhex_edid(edid : str) -> bytes: - ''' - Convert an hexadecimal representation of an EDID to a raw representation. - - @param edid The EDID in hexadecimal representation. - @return The EDID in raw representation. - ''' - rc = [] - edid = edid.lower() - for i in range(0, len(edid), 2): - a, b = edid[i + 0], edid[i + 1] - a = '0123456789abcdef'.find(a) << 4 - b = '0123456789abcdef'.find(b) << 0 - rc.append(a | b) - return bytes(rc) - diff --git a/src/libgamma_method.py b/src/libgamma_method.py deleted file mode 100644 index dcd4f6a..0000000 --- a/src/libgamma_method.py +++ /dev/null @@ -1,1117 +0,0 @@ -# -*- python -*- -''' -pylibgamma — Python 3 wrapper for libgamma -Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) - -This library 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 library 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 library. If not, see . -''' - -from libgamma_error import create_error - - - -LIBGAMMA_METHOD_DUMMY = 0 -''' -The identifier for the dummy adjustment method. -This method can be configured and is useful for -testing your program's ability to handle errors. -''' - -LIBGAMMA_METHOD_X_RANDR = 1 -''' -The identifier for the adjustment method with -uses the RandR protocol under the X display server. -''' - -LIBGAMMA_METHOD_X_VIDMODE = 2 -''' -The identifier for the adjustment method with -uses the VidMode protocol under the X display server. -This is an older alternative to RandR that can -work on some drivers that are not supported by RandR, -however it can only control the primary CRTC per -screen (partition). -''' - -LIBGAMMA_METHOD_LINUX_DRM = 3 -''' -The identifier for the Direct Rendering Manager -adjustment method that is available in Linux -(built in to the Linux kernel with a userland -library for access) and is a part of the -Direct Rendering Infrastructure. This adjustment -method all work when you are in non-graphical -mode; however a display server cannnot be -started while this is running, but it can be -started while a display server is running. -''' - -LIBGAMMA_METHOD_W32_GDI = 4 -''' -The identifier for the Graphics Device Interface -adjustment method that is available in Windows. -This method is not well tested; it can be compiled -to be available under X.org using a translation layer. -''' - -LIBGAMMA_METHOD_QUARTZ_CORE_GRAPHICS = 5 -''' -The identifier for the CoreGraphics adjustment -method that is available in Mac OS X that can -adjust gamma ramps under the Quartz display server. -This method is not well tested; it can be compiled -to be available under X.org using a translation layer. -''' - - -LIBGAMMA_METHOD_MAX = 5 -''' -The index of the last gamma method, neither it -nor any index before it may actually be supported -as it could have been disabled at compile-time -''' - -LIBGAMMA_METHOD_COUNT = (LIBGAMMA_METHOD_MAX + 1) -''' -The number adjustment methods provided by this library. -Note however that this includes adjstment methods that -have been removed at compile-time. -''' - - -class MethodCapabilities: - ''' - Capabilities of adjustment methods - - ---- Integer variables ---- - - @variable crtc_information OR of the CRTC information fields in `CRTCInformation` - that may (but can fail) be read successfully. - - ---- Boolean variables ---- - - @variable default_site_known Whether the default site is known, if true the site is integrated - to the system or can be determined using environment variables. - @variable multiple_sites Whether the adjustment method supports multiple sites rather - than just the default site. - @variable multiple_partitions Whether the adjustment method supports multiple partitions - per site. - @variable multiple_crtcs Whether the adjustment method supports multiple CRTC:s - per partition per site. - @variable partitions_are_graphics_cards Whether the partition to graphics card is a bijection. - @variable site_restore Whether the adjustment method supports `site_restore`. - @variable partition_restore Whether the adjustment method supports `partition_restore`. - @variable crtc_restore Whether the adjustment method supports `crtc_restore`. - @variable identical_gamma_sizes Whether the `red_gamma_size`, `green_gamma_size` and - `blue_gamma_size` fields in `CRTCInformation` will always - have the same values as each other for the adjustment method. - @variable fixed_gamma_size Whether the `red_gamma_size`, `green_gamma_size` and - `blue_gamma_size` fields in `CRTCInformation` will always be - filled with the same value for the adjustment method. - @variable fixed_gamma_depth Whether the `gamma_depth` field in `CRTCInformation` will - always be filled with the same value for the adjustment method. - @variable real Whether the adjustment method will actually perform adjustments. - @variable fake Whether the adjustment method is implement using a translation - layer. - ''' - - def __init__(self, crtc_information : int = 0, booleans : int = 0): - ''' - Constructor - - @param crtc_information The value for `CRTCInformation` - @param booleans The value for each booleanic variable - ''' - self.crtc_information = crtc_information - self.default_site_known = (booleans & (1 << 0)) != 0 - self.multiple_sites = (booleans & (1 << 1)) != 0 - self.multiple_partitions = (booleans & (1 << 2)) != 0 - self.multiple_crtcs = (booleans & (1 << 3)) != 0 - self.partitions_are_graphics_cards = (booleans & (1 << 4)) != 0 - self.site_restore = (booleans & (1 << 5)) != 0 - self.partition_restore = (booleans & (1 << 6)) != 0 - self.crtc_restore = (booleans & (1 << 7)) != 0 - self.identical_gamma_sizes = (booleans & (1 << 8)) != 0 - self.fixed_gamma_size = (booleans & (1 << 9)) != 0 - self.fixed_gamma_depth = (booleans & (1 << 10)) != 0 - self.real = (booleans & (1 << 11)) != 0 - self.fake = (booleans & (1 << 12)) != 0 - - -class CRTCInformation: - ''' - Cathode ray tube controller information data structure. - - @variable edid:bytes The Extended Display Identification Data associated with - the attached monitor. This is raw byte array that is usually - 128 bytes long. - @variable edid_error:int Zero on success, positive it holds the value `errno` had - when the reading failed, otherwise (negative) the value - of an error identifier provided by this library. - - @variable width_mm:int The phyical width, in millimetres, of the viewport of the - attached monitor, as reported by the adjustment method. This - value may be incorrect, which is a known issue with the X - server where it is the result of the X server attempting - the estimate the size on its own. - Zero means that its is not applicable, which is the case - for projectors. - @variable width_mm_error:int Zero on success, positive it holds the value `errno` had - when the reading failed, otherwise (negative) the value - of an error identifier provided by this library. - @variable height_mm:int The phyical height, in millimetres, of the viewport of the - attached monitor, as reported by the adjustment method. This - value may be incorrect, which is a known issue with the X - server where it is the result of the X server attempting - the estimate the size on its own. - Zero means that its is not applicable, which is the case - for projectors. - @variable height_mm_error:int Zero on success, positive it holds the value `errno` had - when the reading failed, otherwise (negative) the value - of an error identifier provided by this library. - - @variable width_mm_edid:int The phyical width, in millimetres, of the viewport of the - attached monitor, as reported by it the monitor's Extended - Display Information Data. This value can only contain whole - centimetres, which means that the result is always zero - modulus ten. However, this could change with revisions of - the EDID structure. - Zero means that its is not applicable, which is the case - for projectors. - @variable width_mm_edid_error:int Zero on success, positive it holds the value `errno` had - when the reading failed, otherwise (negative) the value - of an error identifier provided by this library. - @variable height_mm_edid:int The phyical height, in millimetres, of the viewport of the - attached monitor, as reported by it the monitor's Extended - Display Information Data. This value can only contain whole - centimetres, which means that the result is always zero - modulus ten. However, this could change with revisions of - the EDID structure. - Zero means that its is not applicable, which is the case - for projectors. - @variable height_mm_edid_error:int Zero on success, positive it holds the value `errno` had - when the reading failed, otherwise (negative) the value - of an error identifier provided by this library. - - @variable red_gamma_size:int The size of the encoding axis of the red gamma ramp. - @variable green_gamma_size:int The size of the encoding axis of the green gamma ramp. - @variable blue_gamma_size:int The size of the encoding axis of the blue gamma ramp. - @variable gamma_size_error:int Zero on success, positive it holds the value `errno` had - when the reading failed, otherwise (negative) the value - of an error identifier provided by this library. - - @variable gamma_depth:int The bit-depth of the value axes of gamma ramps, - -1 for single precision floating point, and -2 for - double precision floating point. - @variable gamma_depth_error:int Zero on success, positive it holds the value `errno` had - when the reading failed, otherwise (negative) the value - of an error identifier provided by this library. - - @variable gamma_support:int Non-zero gamma ramp adjustments are supported. - @variable gamma_support_error:int Zero on success, positive it holds the value `errno` had - when the reading failed, otherwise (negative) the value - of an error identifier provided by this library. - - @variable subpixel_order:int The layout of the subpixels. - You cannot count on this value — especially for CRT:s — - but it is provided anyway as a means of distinguishing monitors. - @variable subpixel_order_error:int Zero on success, positive it holds the value `errno` had - when the reading failed, otherwise (negative) the value - of an error identifier provided by this library. - - @variable active:bool Whether there is a monitors connected to the CRTC. - @variable active_error:int Zero on success, positive it holds the value `errno` had - when the reading failed, otherwise (negative) the value - of an error identifier provided by this library. - - @variable connector_name:str The name of the connector as designated by the display - server or as give by this library in case the display - server lacks this feature. - @variable connector_name_error:int Zero on success, positive it holds the value `errno` had - when the reading failed, otherwise (negative) the value - of an error identifier provided by this library. - - @variable connector_type:int The type of the connector that is associated with the CRTC. - @variable connector_type_error:int Zero on success, positive it holds the value `errno` had - when the reading failed, otherwise (negative) the value - of an error identifier provided by this library. - - @variable gamma_red:float The gamma characteristics of the monitor as reported - in its Extended Display Information Data. The value - holds the value for the red channel. If you do not have - and more accurate measurement of the gamma for the - monitor this could be used to give a rought gamma - correction; simply divide the value with 2.2 and use - the result for the red channel in the gamma correction. - @variable gamma_green:float The gamma characteristics of the monitor as reported - in its Extended Display Information Data. The value - holds the value for the green channel. If you do not have - and more accurate measurement of the gamma for the - monitor this could be used to give a rought gamma - correction; simply divide the value with 2.2 and use - the result for the green channel in the gamma correction. - @variable gamma_blue:float The gamma characteristics of the monitor as reported - in its Extended Display Information Data. The value - holds the value for the blue channel. If you do not have - and more accurate measurement of the gamma for the - monitor this could be used to give a rought gamma - correction; simply divide the value with 2.2 and use - the result for the blue channel in the gamma correction. - @variable gamma_error:int Zero on success, positive it holds the value `errno` had - when the reading failed, otherwise (negative) the value - of an error identifier provided by this library. - ''' - - def __init__(self, data): - ''' - Constructor - - @param data:list The value of each variable - ''' - self.edid = data[0] - self.edid_error = data[1] - self.width_mm = data[2] - self.width_mm_error = data[3] - self.height_mm = data[4] - self.height_mm_error = data[5] - self.width_mm_edid = data[6] - self.width_mm_edid_error = data[7] - self.height_mm_edid = data[8] - self.height_mm_edid_error = data[9] - self.red_gamma_size = data[10] - self.green_gamma_size = data[11] - self.blue_gamma_size = data[12] - self.gamma_size_error = data[13] - self.gamma_depth = data[14] - self.gamma_depth_error = data[15] - self.gamma_support = data[16] - self.gamma_support_error = data[17] - self.subpixel_order = data[18] - self.subpixel_order_error = data[19] - self.active = data[20] - self.active_error = data[21] - self.connector_name = data[22] - self.connector_name_error = data[23] - self.connector_type = data[24] - self.connector_type_error = data[25] - self.gamma_red = data[26] - self.gamma_green = data[27] - self.gamma_blue = data[28] - self.gamma_error = data[29] - - -LIBGAMMA_CONNECTOR_TYPE_Unknown = 0 -''' -The adjustment method does not know the connector's type -(This could be considered an error). -''' - -LIBGAMMA_CONNECTOR_TYPE_VGA = 1 -''' -Video Graphics Array (VGA). -''' - -LIBGAMMA_CONNECTOR_TYPE_DVI = 2 -''' -Digital Visual Interface, unknown type. -''' - -LIBGAMMA_CONNECTOR_TYPE_DVII = 3 -''' -Digital Visual Interface, integrated (DVI-I). -''' - -LIBGAMMA_CONNECTOR_TYPE_DVID = 4 -''' -Digital Visual Interface, digital only (DVI-D). -''' - -LIBGAMMA_CONNECTOR_TYPE_DVIA = 5 -''' -Digital Visual Interface, analogue only (DVI-A). -''' - -LIBGAMMA_CONNECTOR_TYPE_Composite = 6 -''' -Composite video. -''' - -LIBGAMMA_CONNECTOR_TYPE_SVIDEO = 7 -''' -Separate Video (S-video). -''' - -LIBGAMMA_CONNECTOR_TYPE_LVDS = 8 -''' -Low-voltage differential signaling (LVDS). -''' - -LIBGAMMA_CONNECTOR_TYPE_Component = 9 -''' -Component video, usually separate cables for each channel. -''' - -LIBGAMMA_CONNECTOR_TYPE_9PinDIN = 10 -''' -9 pin DIN (Deutsches Institut für Normung) connector. -''' - -LIBGAMMA_CONNECTOR_TYPE_DisplayPort = 11 -''' -DisplayPort. -''' - -LIBGAMMA_CONNECTOR_TYPE_HDMI = 12 -''' -High-Definition Multimedia Interface (HDMI), unknown type. -''' - -LIBGAMMA_CONNECTOR_TYPE_HDMIA = 13 -''' -High-Definition Multimedia Interface, type A (HDMI-A). -''' - -LIBGAMMA_CONNECTOR_TYPE_HDMIB = 14 -''' -High-Definition Multimedia Interface, type B (HDMI-B). -''' - -LIBGAMMA_CONNECTOR_TYPE_TV = 15 -''' -Television, unknown connector. -''' - -LIBGAMMA_CONNECTOR_TYPE_eDP = 16 -''' -Embedded DisplayPort (eDP). -''' - -LIBGAMMA_CONNECTOR_TYPE_VIRTUAL = 17 -''' -A virtual connector. -''' - -LIBGAMMA_CONNECTOR_TYPE_DSI = 18 -''' -Display Serial Interface (DSI). -''' - -LIBGAMMA_CONNECTOR_TYPE_LFP = 19 -''' -LFP connector. -(If you know what this is add it to Wikipedia.) -''' - - -LIBGAMMA_CONNECTOR_TYPE_COUNT = 20 -''' -The number of `LIBGAMMA_CONNECTOR_*` values defined. -''' - - - -LIBGAMMA_SUBPIXEL_ORDER_UNKNOWN = 0 -''' -The adjustment method does not know the order of the subpixels. -(This could be considered an error.) -''' - -LIBGAMMA_SUBPIXEL_ORDER_NONE = 1 -''' -There are no subpixels in the monitor. -''' - -LIBGAMMA_SUBPIXEL_ORDER_HORIZONTAL_RGB = 2 -''' -The subpixels are ordered red, green and then blue, from left to right. -''' - -LIBGAMMA_SUBPIXEL_ORDER_HORIZONTAL_BGR = 3 -''' -The subpixels are ordered blue, green and then red, from left to right. -''' - -LIBGAMMA_SUBPIXEL_ORDER_VERTICAL_RGB = 4 -''' -The subpixels are ordered red, green and then blue, from the top down. -''' - -LIBGAMMA_SUBPIXEL_ORDER_VERTICAL_BGR = 5 -''' -The subpixels are ordered blue, green and then red, from the top down. -''' - - -LIBGAMMA_SUBPIXEL_ORDER_COUNT = 6 -''' -The number of `LIBGAMMA_SUBPIXEL_ORDER_*` values defined. -''' - - - -LIBGAMMA_CRTC_INFO_EDID = 1 << 0 -''' -For a `CRTCInformation` fill in the -values for `edid` and `edid_length` and report errors to `edid_error`. -''' - -LIBGAMMA_CRTC_INFO_WIDTH_MM = 1 << 1 -''' -For a `CRTCInformation` fill in the -value for `width_mm` and report errors to `width_mm_error`. -''' - -LIBGAMMA_CRTC_INFO_HEIGHT_MM = 1 << 2 -''' -For a `CRTCInformation` fill in the -value for `height_mm` and report errors to `height_mm_error`. -''' - -LIBGAMMA_CRTC_INFO_WIDTH_MM_EDID = 1 << 3 -''' -For a `CRTCInformation` fill in the -value for `width_mm_edid` and report errors to `width_mm_edid_error`. -''' - -LIBGAMMA_CRTC_INFO_HEIGHT_MM_EDID = 1 << 4 -''' -For a `CRTCInformation` fill in the -value for `height_mm_edid` and report errors to `height_mm_edid_error`. -''' - -LIBGAMMA_CRTC_INFO_GAMMA_SIZE = 1 << 5 -''' -For a `CRTCInformation` fill in the -values for `red_gamma_size`, `green_gamma_size` and `blue_gamma_size`. -and report errors to `gamma_size_error` -''' - -LIBGAMMA_CRTC_INFO_GAMMA_DEPTH = 1 << 6 -''' -For a `CRTCInformation` fill in the -value for `gamma_depth` and report errors to `gamma_depth_error`. -''' - -LIBGAMMA_CRTC_INFO_GAMMA_SUPPORT = 1 << 7 -''' -For a `CRTCInformation` fill in the -value for `gamma_support` and report errors to `gamma_support_error`. -''' - -LIBGAMMA_CRTC_INFO_SUBPIXEL_ORDER = 1 << 8 -''' -For a `CRTCInformation` fill in the -value for `subpixel_order` and report errors to `subpixel_order_error`. -''' - -LIBGAMMA_CRTC_INFO_ACTIVE = 1 << 9 -''' -For a `CRTCInformation` fill in the -value for `active` and report errors to `active_error`. -''' - -LIBGAMMA_CRTC_INFO_CONNECTOR_NAME = 1 << 10 -''' -For a `CRTCInformation` fill in the -value for `connector_name` and report errors to `connector_name_error`. -''' - -LIBGAMMA_CRTC_INFO_CONNECTOR_TYPE = 1 << 11 -''' -For a `CRTCInformation` fill in the -value for `connector_type` and report errors to `connector_type_error`. -''' - -LIBGAMMA_CRTC_INFO_GAMMA = 1 << 12 -''' -For a `CRTCInformation` fill in the -values for `gamma_red`, `gamma_green` and `gamma_blue` -and report errors to `gamma_error`. -''' - - -LIBGAMMA_CRTC_INFO_COUNT = 13 -''' -The number of `LIBGAMMA_CRTC_INFO_*` values defined. -''' - - - -LIBGAMMA_CRTC_INFO_MACRO_EDID_VIEWPORT = LIBGAMMA_CRTC_INFO_WIDTH_MM_EDID | \ - LIBGAMMA_CRTC_INFO_HEIGHT_MM_EDID -''' -Macro for both `CRTCInformation` fields -that can specify the size of the monitor's viewport -as specified in the monitor's Extended Display -Information Data. -''' - -LIBGAMMA_CRTC_INFO_MACRO_EDID = LIBGAMMA_CRTC_INFO_EDID | \ - LIBGAMMA_CRTC_INFO_MACRO_EDID_VIEWPORT | \ - LIBGAMMA_CRTC_INFO_GAMMA -''' -Macro for all `CRTCInformation` fields -that can be filled if the adjustment method have -support for reading the monitors' Extended Display -Information Data. -''' - -LIBGAMMA_CRTC_INFO_MACRO_VIEWPORT = LIBGAMMA_CRTC_INFO_WIDTH_MM | \ - LIBGAMMA_CRTC_INFO_HEIGHT_MM -''' -Macro for both `CRTCInformation` fields -that can specify the size of the monitor's viewport -as provided by the adjustment method without this -library having to parse the monitor's Extended Display -Information Data. -''' - -LIBGAMMA_CRTC_INFO_MACRO_RAMP = LIBGAMMA_CRTC_INFO_GAMMA_SIZE | \ - LIBGAMMA_CRTC_INFO_GAMMA_DEPTH -''' -Macro for the `CRTCInformation` fields -that specifies the CRTC's gamma ramp sizes and gamma -ramp depth. -''' - -LIBGAMMA_CRTC_INFO_MACRO_CONNECTOR = LIBGAMMA_CRTC_INFO_CONNECTOR_NAME | \ - LIBGAMMA_CRTC_INFO_CONNECTOR_TYPE -''' -Macro for the `CRTCInformation` fields -that specifies the CRTC's connector type and the -partition unique name of the connector. -''' - -LIBGAMMA_CRTC_INFO_MACRO_ACTIVE = LIBGAMMA_CRTC_INFO_MACRO_EDID | \ - LIBGAMMA_CRTC_INFO_MACRO_VIEWPORT | \ - LIBGAMMA_CRTC_INFO_SUBPIXEL_ORDER | \ - LIBGAMMA_CRTC_INFO_ACTIVE -''' -Macro for the `CRTCInformation` fields -that required there is a monitor attached to the connector, -and that status itself. -''' - - - -class GammaRamps: - ''' - Gamma ramp structure. - ''' - - class Ramp: - ''' - A gamma ramp for one single channel. - ''' - - def __init__(self, ramp, size : int, depth : int): - ''' - Constructor. - - @param ramp The gamma ramp. - @param size The number of stops in the gamma ramp. - @param depth The depth of the gamma ramp. - ''' - from libgamma_native_method import libgamma_native_gamma_ramps8_get - from libgamma_native_method import libgamma_native_gamma_ramps16_get - from libgamma_native_method import libgamma_native_gamma_ramps32_get - from libgamma_native_method import libgamma_native_gamma_ramps64_get - from libgamma_native_method import libgamma_native_gamma_rampsf_get - from libgamma_native_method import libgamma_native_gamma_rampsd_get - from libgamma_native_method import libgamma_native_gamma_ramps8_set - from libgamma_native_method import libgamma_native_gamma_ramps16_set - from libgamma_native_method import libgamma_native_gamma_ramps32_set - from libgamma_native_method import libgamma_native_gamma_ramps64_set - from libgamma_native_method import libgamma_native_gamma_rampsf_set - from libgamma_native_method import libgamma_native_gamma_rampsd_set - self._size = size - self._ramp = ramp - if depth == 8: fs = (libgamma_native_gamma_ramps8_get, libgamma_native_gamma_ramps8_set) - elif depth == 16: fs = (libgamma_native_gamma_ramps16_get, libgamma_native_gamma_ramps16_set) - elif depth == 32: fs = (libgamma_native_gamma_ramps32_get, libgamma_native_gamma_ramps32_set) - elif depth == 64: fs = (libgamma_native_gamma_ramps64_get, libgamma_native_gamma_ramps64_set) - elif depth == -1: fs = (libgamma_native_gamma_rampsf_get, libgamma_native_gamma_rampsf_set) - elif depth == -2: fs = (libgamma_native_gamma_rampsd_get, libgamma_native_gamma_rampsd_set) - (self._get, self._set) = fs - - - @property - def size(self) -> int: - ''' - Get the number of stops in the gamma ramp. - - @return The number of stops in the gamma ramp. - ''' - return self._size - - @size.setter - def size(self, value : int): - ''' - It is not possible to change this attribute, but a setter is - required for the getter to function. - ''' - raise AttributeError('cannot resize ramp') - - def __len__(self) -> int: - ''' - Get the number of stops in the gamma ramp. - - @return The number of stops in the gamma ramp. - ''' - return self._size - - def __getitem__(self, indices): - ''' - Read the gamma ramp. - - @param indices:slice The stops to read. - @return :list The values of the read stops. - - -- OR -- - - @param indices:int The index of the stop to read. - @return :int|float The value of the read stop. - ''' - if isinstance(indices, slice): - start = indices.start - stop = indices.stop - step = indices.step - if start is None: start = 0 - elif start < 0: start += self._size - if stop is None: stop = self._size - elif stop < 0: stop += self._size - if step is None: step = 1 - return [self._get(self._ramp, i) for i in range(start, stop, step)] - else: - if indices < 0: - indices += self._size - return self._get(self._ramp, indices) - - def __setitem__(self, indices, values): - ''' - Modify the gamma ramp. - - @param indices:slice The stops to modify. - @param values:itr The values for the selected stops. - - -- OR -- - - @param indices:int The index of the stop to modify. - @param values:int|float The new value for the stop. - ''' - if isinstance(indices, slice): - start = indices.start - stop = indices.stop - step = indices.step - if start is None: start = 0 - elif start < 0: start += self._size - if stop is None: stop = self._size - elif stop < 0: stop += self._size - if step is None: step = 1 - indices = list(range(start, stop, step)) - if not len(indices) == len(values): - raise ValueError('cannot resize ramp') - for index, value in zip(indices, values): - self._set(self._ramp, index, value) - else: - if indices < 0: - indices += self._size - self._set(self._ramp, indices, values) - - def __iter__(self) -> iter: - ''' - Read the gamma ramp. - - @return :itr The values of each stop. - ''' - for value in self[:]: - yield value - - def map(self, function): - ''' - Modify the entire ramp using a function that - maps encoding value to output value. - - @param function:(float)→int|float Function that takes the encoding value as a - [0, 1] floating point and returns its output - value as the format using in the gamma ramp. - ''' - max_i = self._size - 1 - for i in range(self._size): - self._set(self._ramp, i, function(i / max_i)) - - def __init__(self, red_size : int, green_size : int = ..., blue_size : int = ..., *, depth : int = 16): - ''' - Constructor. - - @param red_size The number of stops in the gamma ramp for the red channel. - @param green_size The number of stops in the gamma ramp for the green channel, `...` for `red_size`. - @param blue_size The number of stops in the gamma ramp for the blue channel, `...` for `green_size`. - @param depth The depth of the gamma ramps. - ''' - if green_size is ...: green_size = red_size - if blue_size is ...: blue_size = green_size - - self._depth = depth - - from libgamma_native_method import libgamma_native_gamma_ramps8_create - from libgamma_native_method import libgamma_native_gamma_ramps16_create - from libgamma_native_method import libgamma_native_gamma_ramps32_create - from libgamma_native_method import libgamma_native_gamma_ramps64_create - from libgamma_native_method import libgamma_native_gamma_rampsf_create - from libgamma_native_method import libgamma_native_gamma_rampsd_create - if depth == 8: ramp_struct = libgamma_native_gamma_ramps8_create (red_size, green_size, blue_size) - elif depth == 16: ramp_struct = libgamma_native_gamma_ramps16_create(red_size, green_size, blue_size) - elif depth == 32: ramp_struct = libgamma_native_gamma_ramps32_create(red_size, green_size, blue_size) - elif depth == 64: ramp_struct = libgamma_native_gamma_ramps64_create(red_size, green_size, blue_size) - elif depth == -1: ramp_struct = libgamma_native_gamma_rampsf_create (red_size, green_size, blue_size) - elif depth == -2: ramp_struct = libgamma_native_gamma_rampsd_create (red_size, green_size, blue_size) - else: - raise ValueError('invalid gamma ramp depth') - if isinstance(ramp_struct, int): - import libgamma_native_error as c - error = OSError() - error.errno = ramp_struct - error.strerror = c.strerror(error.errno) - raise error - (self._ramps, red, green, blue) = ramp_struct - - self._red = GammaRamps.Ramp(red, red_size, depth) - self._green = GammaRamps.Ramp(green, green_size, depth) - self._blue = GammaRamps.Ramp(blue, blue_size, depth) - - - def __del__(self): - ''' - This function is called when the object is not longer in use. - ''' - from libgamma_native_method import libgamma_native_gamma_ramps8_free - from libgamma_native_method import libgamma_native_gamma_ramps16_free - from libgamma_native_method import libgamma_native_gamma_ramps32_free - from libgamma_native_method import libgamma_native_gamma_ramps64_free - from libgamma_native_method import libgamma_native_gamma_rampsf_free - from libgamma_native_method import libgamma_native_gamma_rampsd_free - if self._ramps == 0: - return - if self._depth == 8: libgamma_native_gamma_ramps8_free(self._ramps) - elif self._depth == 16: libgamma_native_gamma_ramps16_free(self._ramps) - elif self._depth == 32: libgamma_native_gamma_ramps32_free(self._ramps) - elif self._depth == 64: libgamma_native_gamma_ramps64_free(self._ramps) - elif self._depth == -1: libgamma_native_gamma_rampsf_free(self._ramps) - elif self._depth == -2: libgamma_native_gamma_rampsd_free(self._ramps) - - - @property - def red(self) -> Ramp: - ''' - Get the gamma ramp for the red channel. - - @return The gamma ramp for the red channel. - ''' - return self._red - - - @red.setter - def red(self, value): - ''' - It is not possible to change this attribute, but a setter is - required for the getter to function. - ''' - raise AttributeError('cannot change ramps') - - - @property - def green(self) -> Ramp: - ''' - Get the gamma ramp for the green channel. - - @return The gamma ramp for the green channel. - ''' - return self._green - - - @green.setter - def green(self, value) -> Ramp: - ''' - It is not possible to change this attribute, but a setter is - required for the getter to function. - ''' - raise AttributeError('cannot change ramps') - - - @property - def blue(self): - ''' - Get the gamma ramp for the blue channel. - - @return The gamma ramp for the blue channel. - ''' - return self._blue - - - @blue.setter - def blue(self, value): - ''' - It is not possible to change this attribute, but a setter is - required for the getter to function. - ''' - raise AttributeError('cannot change ramps') - - - @property - def size(self) -> tuple: - ''' - Get the ramps' sizes. - - @return :(red:int, green:int, blue:int) The size of each individual ramp. - ''' - return (self._red.size, self._green.size, self._blue.size) - - - @size.setter - def size(self, value): - ''' - It is not possible to change this attribute, but a setter is - required for the getter to function. - ''' - raise AttributeError('cannot resize ramps') - - - @property - def depth(self) -> int: - ''' - Get the depth of ramps. - - @return :int The ramps' depth in bits and -1 for single precision floating - point and -2 for doublesingle precision floating point. - ''' - return self._depth - - - @depth.setter - def depth(self, value): - ''' - It is not possible to change this attribute, but a setter is - required for the getter to function. - ''' - raise AttributeError('cannot change depth') - - - -class Site: - ''' - Site state. - - On operating systems that integrate a graphical environment - there is usually just one site. However, one systems with - pluggable graphics, like Unix-like systems such as GNU/Linux - and the BSD:s, there can usually be any (feasible) number of - sites. In X.org parlance they are called displays. - - @variable method:int The adjustment method of the site. - @variable site:str? The site identifier. - @variable partitions_available:int The number of paritions available in the site. - ''' - - def __init__(self, method : int, site : str = None): - ''' - Constructor. - - @param method:int The adjustment method of the site. - @param site:str? The site identifier. - ''' - from libgamma_native_facade import libgamma_native_site_create - (self._state, n) = libgamma_native_site_create(method, site) - if self._state == 0: - raise create_error(n) - self.partitions_available = n - self.method = method - self.site = site - - - def __del__(self): - ''' - This function is called when the object is not longer in use. - ''' - from libgamma_native_facade import libgamma_native_site_free - if not self._state == 0: - libgamma_native_site_free(self._state) - - - def restore(self): - ''' - Restore the gamma ramps all CRTC:s with the site to the system settings. - ''' - from libgamma_native_facade import libgamma_native_site_restore - r = libgamma_native_site_restore(self._state) - if not r == 0: - raise create_error(r) - - -class Partition: - ''' - Partition state. - - Probably the majority of display server only one partition - per site. However, X.org can, and traditional used to have - on multi-headed environments, multiple partitions per site. - In X.org partitions are called 'screens'. It is not to be - confused with monitor. A screen is a collection of monitors, - and the mapping from monitors to screens is a surjection. - On hardware-level adjustment methods, such as Direct - Rendering Manager, a partition is a graphics card - - @variable site:Site The site of the partition. - @variable partition:int The index of the partition. - @variable crtcs_available:int The number of CRTC:s available in the parition. - ''' - - def __init__(self, site : Site, partition : int): - ''' - Constructor. - - @param site The site of the partition. - @param partition The index of the partition. - ''' - from libgamma_native_facade import libgamma_native_partition_create - (self._state, n) = libgamma_native_partition_create(site._state, partition) - if self._state == 0: - raise create_error(n) - self.crtcs_available = n - self.site = site - self.partition = partition - - - def __del__(self): - ''' - This function is called when the object is not longer in use. - ''' - from libgamma_native_facade import libgamma_native_partition_free - if not self._state == 0: - libgamma_native_partition_free(self._state) - - - def restore(self): - ''' - Restore the gamma ramps all CRTC:s with the partition to the system settings. - ''' - from libgamma_native_facade import libgamma_native_partition_restore - r = libgamma_native_partition_restore(self._state) - if not r == 0: - raise create_error(r) - - -class CRTC: - ''' - Cathode ray tube controller state. - - The CRTC controls the gamma ramps for the - monitor that is plugged in to the connector - that the CRTC belongs to. - - @variable partition:Partition The partition of the CRTC. - @variable crtc:int The index of the CRTC. - ''' - - def __init__(self, partition : Partition, crtc : int): - ''' - Constructor. - - @param partition The partition the of the CRTC. - @param crtc The index of the CRTC. - ''' - from libgamma_native_facade import libgamma_native_crtc_create - (self._state, n) = libgamma_native_crtc_create(partition._state, crtc) - if self._state == 0: - raise create_error(n) - self.partition = partition - self.crtc = crtc - - - def __del__(self): - ''' - This function is called when the object is not longer in use. - ''' - from libgamma_native_facade import libgamma_native_crtc_free - if not self._state == 0: - libgamma_native_crtc_free(self._state) - - - def restore(self): - ''' - Restore the gamma ramps for a CRTC to the system settings for that CRTC. - ''' - from libgamma_native_facade import libgamma_native_crtc_restore - r = libgamma_native_crtc_restore(self._state) - if not r == 0: - raise create_error(r) - - - def information(self, fields : int) -> tuple: - ''' - Read information about a CRTC. - - @param field OR:ed identifiers for the information - about the CRTC that should be read. - @return :(:CRTCInformation, :bool) The information about the CRTC and - whether no errors occurred. - ''' - from libgamma_native_facade import libgamma_native_get_crtc_information - (data, e) = libgamma_native_get_crtc_information(self._state, fields) - return (CRTCInformation(data), e == 0) - - - def get_gamma(self, ramps : GammaRamps): - ''' - Get the current gamma ramps for the CRTC. - - @param ramps The gamma ramps to fill with the current values. - ''' - from libgamma_native_facade import libgamma_native_crtc_get_gamma_ramps8 - from libgamma_native_facade import libgamma_native_crtc_get_gamma_ramps16 - from libgamma_native_facade import libgamma_native_crtc_get_gamma_ramps32 - from libgamma_native_facade import libgamma_native_crtc_get_gamma_ramps64 - from libgamma_native_facade import libgamma_native_crtc_get_gamma_rampsf - from libgamma_native_facade import libgamma_native_crtc_get_gamma_rampsd - if ramps.depth == 8: r = libgamma_native_crtc_get_gamma_ramps8(self._state, ramps._ramps) - elif ramps.depth == 16: r = libgamma_native_crtc_get_gamma_ramps16(self._state, ramps._ramps) - elif ramps.depth == 32: r = libgamma_native_crtc_get_gamma_ramps32(self._state, ramps._ramps) - elif ramps.depth == 64: r = libgamma_native_crtc_get_gamma_ramps64(self._state, ramps._ramps) - elif ramps.depth == -1: r = libgamma_native_crtc_get_gamma_rampsf(self._state, ramps._ramps) - elif ramps.depth == -2: r = libgamma_native_crtc_get_gamma_rampsd(self._state, ramps._ramps) - if not r == 0: - raise create_error(r) - - - def set_gamma(self, ramps : GammaRamps): - ''' - Set gamma ramps for the CRTC. - - @param ramps The gamma ramps to apply. - ''' - from libgamma_native_facade import libgamma_native_crtc_set_gamma_ramps8 - from libgamma_native_facade import libgamma_native_crtc_set_gamma_ramps16 - from libgamma_native_facade import libgamma_native_crtc_set_gamma_ramps32 - from libgamma_native_facade import libgamma_native_crtc_set_gamma_ramps64 - from libgamma_native_facade import libgamma_native_crtc_set_gamma_rampsf - from libgamma_native_facade import libgamma_native_crtc_set_gamma_rampsd - if ramps.depth == 8: r = libgamma_native_crtc_set_gamma_ramps8(self._state, ramps._ramps) - elif ramps.depth == 16: r = libgamma_native_crtc_set_gamma_ramps16(self._state, ramps._ramps) - elif ramps.depth == 32: r = libgamma_native_crtc_set_gamma_ramps32(self._state, ramps._ramps) - elif ramps.depth == 64: r = libgamma_native_crtc_set_gamma_ramps64(self._state, ramps._ramps) - elif ramps.depth == -1: r = libgamma_native_crtc_set_gamma_rampsf(self._state, ramps._ramps) - elif ramps.depth == -2: r = libgamma_native_crtc_set_gamma_rampsd(self._state, ramps._ramps) - if not r == 0: - raise create_error(r) - diff --git a/src/libgamma_native_error.pyx b/src/libgamma_native_error.pyx deleted file mode 100644 index 6963a44..0000000 --- a/src/libgamma_native_error.pyx +++ /dev/null @@ -1,205 +0,0 @@ -# -*- python -*- -''' -pylibgamma — Python 3 wrapper for libgamma -Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) - -This library 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 library 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 library. If not, see . -''' - -cimport cython - -from posix.unistd cimport gid_t -from libc.string cimport strerror as c_strerror - - -cdef extern gid_t libgamma_group_gid_get() nogil -cdef extern void libgamma_group_gid_set(gid_t) nogil -''' -Group that the user needs to be a member of if -`LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned. -''' - -cdef extern const char* libgamma_group_name_get() nogil -cdef extern void libgamma_group_name_set(const char*) nogil -''' -Group that the user needs to be a member of if -`LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, -`NULL` if the name of the group `libgamma_group_gid` -cannot be determined. -''' - - -cdef extern void libgamma_perror(const char* name, int error_code) nogil -''' -Prints an error to stderr in a `perror` fashion, -however this function will not translate the `libgamma` -errors into human-readable strings, it will simply -print the name of the error. If the value `error_code` -is the value of `LIBGAMMA_ERRNO_SET`, `perror` will be -used to print the current error stored in `errno`. -If `error_code` is non-negative (an `errno` value`), that -value will be stored in `errno` and `perror` will be -used to print it. Additionally, if the `error_code` is -the value of `LIBGAMMA_DEVICE_REQUIRE_GROUP` the -required group will be printed with its numerical value -and, if known, its name. - -@param name The text to add at the beginning. -@param value The error code, may be an `errno` value. -''' - -cdef extern const char* libgamma_name_of_error(int value) nogil -''' -Returns the name of the definition associated with a `libgamma` error code. - -@param value The error code. -@return The name of the definition associated with the error code, - `NULL` if the error code does not exist. The return string - should not be `free`:d. -''' - -cdef extern int libgamma_value_of_error(const char* name) nogil -''' -Return the value of a `libgamma` error definition refered to by name. - -@param name The name of the definition associated with the error code. -@return The error code, zero if the name does is `NULL` - or does not refer to a `libgamma` error. -''' - - - -def libgamma_native_get_group_gid() -> int: - ''' - Getter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned. - ''' - return int(libgamma_group_gid_get()) - -def libgamma_native_set_group_gid(gid : int): - ''' - Setter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned. - ''' - libgamma_group_gid_set(gid) - - -def libgamma_native_get_group_name() -> str: - ''' - Getter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, - `None` if the name of the group `libgamma_group_gid` - cannot be determined. - ''' - cdef const char* group_name - cdef bytes bs - group_name = libgamma_group_name_get() - if group_name is NULL: - return None - bs = group_name - return bs.decode('utf-8', 'strict') - -def libgamma_native_set_group_name(name : str): - ''' - Setter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, - `None` if the name of the group `libgamma_group_gid` - cannot be determined. - ''' - cdef const char* group_name - cdef bytes bs - if name is None: - libgamma_group_name_set(NULL) - return - bs = name.encode('utf-8') + bytes([0]) - group_name = bs - libgamma_group_name_set(group_name) - - -def libgamma_native_perror(name : str, error_code : int): - ''' - Prints an error to stderr in a `perror` fashion, - however this function will not translate the `libgamma` - errors into human-readable strings, it will simply - print the name of the error. If the value `error_code` - is the value of `LIBGAMMA_ERRNO_SET`, `perror` will be - used to print the current error stored in `errno`. - If `error_code` is non-negative (an `errno` value`), that - value will be stored in `errno` and `perror` will be - used to print it. Additionally, if the `error_code` is - the value of `LIBGAMMA_DEVICE_REQUIRE_GROUP` the - required group will be printed with its numerical value - and, if known, its name. - - @param name The text to add at the beginning. - @param value The error code, may be an `errno` value. - ''' - cdef bytes bs - bs = name.encode('utf-8') + bytes([0]) - libgamma_perror(bs, error_code) - - -def libgamma_native_name_of_error(value : int) -> str: - ''' - Returns the name of the definition associated with a `libgamma` error code. - - @param value The error code. - @return The name of the definition associated with the error code, - `None` if the error code does not exist. - ''' - cdef const char* name - cdef bytes bs - name = libgamma_name_of_error(value) - if name is NULL: - return None - bs = name - return bs.decode('utf-8', 'strict') - - -def libgamma_native_value_of_error(name : str) -> int: - ''' - Return the value of a `libgamma` error definition refered to by name. - - @param name The name of the definition associated with the error code. - @return The error code, zero if the name is `None`, - or does not refer to a `libgamma` error. - ''' - cdef bytes bs - if name is None: - return 0 - bs = name.encode('utf-8') + bytes([0]) - return int(libgamma_value_of_error(bs)) - - -def strerror(error : int) -> str: - ''' - Get a textual description of an error. - - @param error The number of the error. - @return The description of the error. - ''' - cdef const char* text - cdef bytes bs - text = c_strerror(error) - bs = text - return bs.decode('utf-8', 'strict') - diff --git a/src/libgamma_native_error.w32.pyx b/src/libgamma_native_error.w32.pyx deleted file mode 100644 index abef314..0000000 --- a/src/libgamma_native_error.w32.pyx +++ /dev/null @@ -1,183 +0,0 @@ -# -*- python -*- -''' -pylibgamma — Python 3 wrapper for libgamma -Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) - -This library 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 library 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 library. If not, see . -''' - -cimport cython - - -cdef extern short libgamma_group_gid -''' -Group that the user needs to be a member of if -`LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned. -''' - -cdef extern const char* libgamma_group_name -''' -Group that the user needs to be a member of if -`LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, -`NULL` if the name of the group `libgamma_group_gid` -cannot be determined. -''' - - -cdef extern void libgamma_perror(const char* name, int error_code) nogil -''' -Prints an error to stderr in a `perror` fashion, -however this function will not translate the `libgamma` -errors into human-readable strings, it will simply -print the name of the error. If the value `error_code` -is the value of `LIBGAMMA_ERRNO_SET`, `perror` will be -used to print the current error stored in `errno`. -If `error_code` is non-negative (an `errno` value`), that -value will be stored in `errno` and `perror` will be -used to print it. Additionally, if the `error_code` is -the value of `LIBGAMMA_DEVICE_REQUIRE_GROUP` the -required group will be printed with its numerical value -and, if known, its name. - -@param name The text to add at the beginning. -@param value The error code, may be an `errno` value. -''' - -cdef extern const char* libgamma_name_of_error(int value) nogil -''' -Returns the name of the definition associated with a `libgamma` error code. - -@param value The error code. -@return The name of the definition associated with the error code, - `NULL` if the error code does not exist. The return string - should not be `free`:d. -''' - -cdef extern int libgamma_value_of_error(const char* name) nogil -''' -Return the value of a `libgamma` error definition refered to by name. - -@param name The name of the definition associated with the error code. -@return The error code, zero if the name does is `NULL` - or does not refer to a `libgamma` error. -''' - - - -def libgamma_native_get_group_gid() -> int: - ''' - Getter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned. - ''' - return int(libgamma_group_gid) - -def libgamma_native_set_group_gid(gid : int): - ''' - Setter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned. - ''' - libgamma_group_gid = gid - - -def libgamma_native_get_group_name() -> str: - ''' - Getter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, - `None` if the name of the group `libgamma_group_gid` - cannot be determined. - ''' - cdef bytes bs - if libgamma_group_name is NULL: - return None - bs = libgamma_group_name - return bs.decode('utf-8', 'strict') - -def libgamma_native_set_group_name(name : str): - ''' - Setter. - - Group that the user needs to be a member of if - `LIBGAMMA_DEVICE_REQUIRE_GROUP` is returned, - `None` if the name of the group `libgamma_group_gid` - cannot be determined. - ''' - cdef bytes bs - if name is None: - libgamma_group_name = NULL - return - bs = name.encode('utf-8') + bytes([0]) - libgamma_group_name = bs - - -def libgamma_native_perror(name : str, error_code : int): - ''' - Prints an error to stderr in a `perror` fashion, - however this function will not translate the `libgamma` - errors into human-readable strings, it will simply - print the name of the error. If the value `error_code` - is the value of `LIBGAMMA_ERRNO_SET`, `perror` will be - used to print the current error stored in `errno`. - If `error_code` is non-negative (an `errno` value`), that - value will be stored in `errno` and `perror` will be - used to print it. Additionally, if the `error_code` is - the value of `LIBGAMMA_DEVICE_REQUIRE_GROUP` the - required group will be printed with its numerical value - and, if known, its name. - - @param name The text to add at the beginning. - @param value The error code, may be an `errno` value. - ''' - cdef bytes bs - bs = name.encode('utf-8') + bytes([0]) - libgamma_perror(bs, error_code) - - -def libgamma_native_name_of_error(value : int) -> str: - ''' - Returns the name of the definition associated with a `libgamma` error code. - - @param value The error code. - @return The name of the definition associated with the error code, - `None` if the error code does not exist. The return string - should not be `free`:d. - ''' - cdef const char* name - cdef bytes bs - name = libgamma_name_of_error(value) - if name is NULL: - return None - bs = name - return bs.decode('utf-8', 'strict') - - -def libgamma_native_value_of_error(name : str) -> int: - ''' - Return the value of a `libgamma` error definition refered to by name. - - @param name The name of the definition associated with the error code. - @return The error code, zero if the name is `None`, - or does not refer to a `libgamma` error. - ''' - cdef bytes bs - if name is None: - return 0 - bs = name.encode('utf-8') + bytes([0]) - return int(libgamma_value_of_error(bs)) - diff --git a/src/libgamma_native_facade.pyx b/src/libgamma_native_facade.pyx deleted file mode 100644 index 32846e2..0000000 --- a/src/libgamma_native_facade.pyx +++ /dev/null @@ -1,1389 +0,0 @@ -# -*- python -*- -''' -pylibgamma — Python 3 wrapper for libgamma -Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) - -This library 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 library 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 library. If not, see . -''' - -cimport cython - -from libc.stddef cimport size_t -from libc.stdlib cimport malloc, free -from libc.stdint cimport int32_t, uint8_t, uint16_t, uint32_t, uint64_t -from libc.errno cimport errno - - -ctypedef int libgamma_subpixel_order_t -ctypedef int libgamma_connector_type_t - - -cdef extern from "include-libgamma.h": - - ctypedef struct libgamma_method_capabilities_t: - # Capabilities of adjustment methods. - - int32_t crtc_information - # OR of the CRTC information fields in `libgamma_crtc_information_t` - # that may (but can fail) be read successfully. - - unsigned default_site_known # : 1 - # Whether the default site is known, if true the site is integrated - # to the system or can be determined using environment variables. - - unsigned multiple_sites # : 1 - # Whether the adjustment method supports multiple sites rather - # than just the default site. - - unsigned multiple_partitions # : 1 - # Whether the adjustment method supports multiple partitions - # per site. - - unsigned multiple_crtcs # : 1 - # Whether the adjustment method supports multiple CRTC:s - # per partition per site. - - unsigned partitions_are_graphics_cards # : 1 - # Whether the partition to graphics card is a bijection. - - unsigned site_restore # : 1 - # Whether the adjustment method supports `libgamma_site_restore`. - - unsigned partition_restore # : 1 - # Whether the adjustment method supports `libgamma_partition_restore`. - - unsigned crtc_restore # : 1 - # Whether the adjustment method supports `libgamma_crtc_restore`. - - unsigned identical_gamma_sizes # : 1 - # Whether the `red_gamma_size`, `green_gamma_size` and `blue_gamma_size` - # fields in `libgamma_crtc_information_t` will always have the same - # values as each other for the adjustment method. - - unsigned fixed_gamma_size # : 1 - # Whether the `red_gamma_size`, `green_gamma_size` and `blue_gamma_size` - # fields in `libgamma_crtc_information_t` will always be filled with the - # same value for the adjustment method. - - unsigned fixed_gamma_depth # : 1 - # Whether the `gamma_depth` field in `libgamma_crtc_information_t` - # will always be filled with the same value for the adjustment method. - - unsigned real # : 1 - # Whether the adjustment method will actually perform adjustments. - - unsigned fake # : 1 - # Whether the adjustment method is implement using a translation layer. - - - ctypedef struct libgamma_site_state_t: - # Site state. - # - # On operating systems that integrate a graphical environment - # there is usually just one site. However, one systems with - # pluggable graphics, like Unix-like systems such as GNU/Linux - # and the BSD:s, there can usually be any (feasible) number of - # sites. In X.org parlance they are called displays. - - void* data - # Adjustment method implementation specific data. - # You as a user of this library should not touch this. - - int method - # This field specifies, for the methods if this library, - # which adjustment method (display server and protocol) - # is used to adjust the gamma ramps. - - char* site - # The site identifier. It can either be `NULL` or a string. - # `NULL` indicates the default site. On systems like the - # Unix-like systems, where the graphics are pluggable, this - # is usually resolved by an environment variable, such as - # "DISPLAY" for X.org. - - size_t partitions_available - # The number of partitions that is available on this site. - # Probably the majority of display server only one partition - # per site. However, X.org can, and traditional used to have - # on multi-headed environments, multiple partitions per site. - # In X.org partitions are called 'screens'. It is not to be - # confused with monitor. A screen is a collection of monitors, - # and the mapping from monitors to screens is a surjection. - # On hardware-level adjustment methods, such as Direct - # Rendering Manager, a partition is a graphics card. - - - ctypedef struct libgamma_partition_state_t: - # Partition state. - # - # Probably the majority of display server only one partition - # per site. However, X.org can, and traditional used to have - # on multi-headed environments, multiple partitions per site. - # In X.org partitions are called 'screens'. It is not to be - # confused with monitor. A screen is a collection of monitors, - # and the mapping from monitors to screens is a surjection. - # On hardware-level adjustment methods, such as Direct - # Rendering Manager, a partition is a graphics card. - - void* data - # Adjustment method implementation specific data. - # You as a user of this library should not touch this. - - libgamma_site_state_t* site - # The site this partition belongs to. - - size_t partition - # The index of the partition. - - size_t crtcs_available - # The number of CRTC:s that are available under this - # partition. Note that the CRTC:s are not necessarily - # online. - - - ctypedef struct libgamma_crtc_state_t: - # Cathode ray tube controller state. - # - # The CRTC controls the gamma ramps for the - # monitor that is plugged in to the connector - # that the CRTC belongs to. - - void* data - # Adjustment method implementation specific data. - # You as a user of this library should not touch this. - - libgamma_partition_state_t* partition - # The partition this CRTC belongs to. - - size_t crtc - # The index of the CRTC within its partition. - - - ctypedef struct libgamma_crtc_information_t: - # Cathode ray tube controller information data structure. - - unsigned char* edid - # The Extended Display Identification Data associated with - # the attached monitor. This is raw byte array that is usually - # 128 bytes long. It is not NUL-terminate, rather its length - # is stored in `edid_length`. - - size_t edid_length - # The length of `edid`. - - int edid_error - # Zero on success, positive it holds the value `errno` had - # when the reading failed, otherwise (negative) the value - # of an error identifier provided by this library. - - - size_t width_mm - # The phyical width, in millimetres, of the viewport of the - # attached monitor, as reported by the adjustment method. This - # value may be incorrect, which is a known issue with the X - # server where it is the result of the X server attempting - # the estimate the size on its own. - # Zero means that its is not applicable, which is the case - # for projectors. - - int width_mm_error - # Zero on success, positive it holds the value `errno` had - # when the reading failed, otherwise (negative) the value - # of an error identifier provided by this library. - - - size_t height_mm - # The phyical height, in millimetres, of the viewport of the - # attached monitor, as reported by the adjustment method. This - # value may be incorrect, which is a known issue with the X - # server where it is the result of the X server attempting - # the estimate the size on its own. - # Zero means that its is not applicable, which is the case - # for projectors. - - int height_mm_error - # Zero on success, positive it holds the value `errno` had - # when the reading failed, otherwise (negative) the value - # of an error identifier provided by this library. - - - size_t width_mm_edid - # The phyical width, in millimetres, of the viewport of the - # attached monitor, as reported by it the monitor's Extended - # Display Information Data. This value can only contain whole - # centimetres, which means that the result is always zero - # modulus ten. However, this could change with revisions of - # the EDID structure. - # Zero means that its is not applicable, which is the case - # for projectors. - - int width_mm_edid_error - # Zero on success, positive it holds the value `errno` had - # when the reading failed, otherwise (negative) the value - # of an error identifier provided by this library. - - - size_t height_mm_edid - # The phyical height, in millimetres, of the viewport of the - # attached monitor, as reported by it the monitor's Extended - # Display Information Data. This value can only contain whole - # centimetres, which means that the result is always zero - # modulus ten. However, this could change with revisions of - # the EDID structure. - # Zero means that its is not applicable, which is the case - # for projectors. - - int height_mm_edid_error - # Zero on success, positive it holds the value `errno` had - # when the reading failed, otherwise (negative) the value - # of an error identifier provided by this library. - - - size_t red_gamma_size - # The size of the encoding axis of the red gamma ramp. - - size_t green_gamma_size - # The size of the encoding axis of the green gamma ramp. - - size_t blue_gamma_size - # The size of the encoding axis of the blue gamma ramp. - - int gamma_size_error - # Zero on success, positive it holds the value `errno` had - # when the reading failed, otherwise (negative) the value - # of an error identifier provided by this library. - - - signed gamma_depth - # The bit-depth of the value axes of gamma ramps, - # -1 for single precision floating point, and -2 for - # double precision floating point. - - int gamma_depth_error - # Zero on success, positive it holds the value `errno` had - # when the reading failed, otherwise (negative) the value - # of an error identifier provided by this library. - - - int gamma_support - # Non-zero gamma ramp adjustments are supported. - - int gamma_support_error - # Zero on success, positive it holds the value `errno` had - # when the reading failed, otherwise (negative) the value - # of an error identifier provided by this library. - - - libgamma_subpixel_order_t subpixel_order - # The layout of the subpixels. - # You cannot count on this value --- especially for CRT:s --- - # but it is provided anyway as a means of distinguishing monitors. - - int subpixel_order_error - # Zero on success, positive it holds the value `errno` had - # when the reading failed, otherwise (negative) the value - # of an error identifier provided by this library. - - - int active - # Whether there is a monitors connected to the CRTC. - - int active_error - # Zero on success, positive it holds the value `errno` had - # when the reading failed, otherwise (negative) the value - # of an error identifier provided by this library. - - - char* connector_name - # The name of the connector as designated by the display - # server or as give by this library in case the display - # server lacks this feature. - - int connector_name_error - # Zero on success, positive it holds the value `errno` had - # when the reading failed, otherwise (negative) the value - # of an error identifier provided by this library. - - - libgamma_connector_type_t connector_type - # The type of the connector that is associated with the CRTC. - - int connector_type_error - # Zero on success, positive it holds the value `errno` had - # when the reading failed, otherwise (negative) the value - # of an error identifier provided by this library. - - - float gamma_red - # The gamma characteristics of the monitor as reported - # in its Extended Display Information Data. The value - # holds the value for the red channel. If you do not have - # and more accurate measurement of the gamma for the - # monitor this could be used to give a rought gamma - # correction; simply divide the value with 2.2 and use - # the result for the red channel in the gamma correction. - - float gamma_green - # The gamma characteristics of the monitor as reported - # in its Extended Display Information Data. The value - # holds the value for the green channel. If you do not have - # and more accurate measurement of the gamma for the - # monitor this could be used to give a rought gamma - # correction; simply divide the value with 2.2 and use - # the result for the green channel in the gamma correction. - - float gamma_blue - # The gamma characteristics of the monitor as reported - # in its Extended Display Information Data. The value - # holds the value for the blue channel. If you do not have - # and more accurate measurement of the gamma for the - # monitor this could be used to give a rought gamma - # correction; simply divide the value with 2.2 and use - # the result for the blue channel in the gamma correction. - - int gamma_error - # Zero on success, positive it holds the value `errno` had - # when the reading failed, otherwise (negative) the value - # of an error identifier provided by this library. - - - ctypedef struct libgamma_gamma_ramps8_t: - # Gamma ramp structure for 8-bit gamma ramps. - size_t red_size - # The size of `red`. - size_t green_size - # The size of `green`. - size_t blue_size - # The size of `blue`. - uint8_t* red - # The gamma ramp for the red channel. - uint8_t* green - # The gamma ramp for the green channel. - uint8_t* blue - # The gamma ramp for the blue channel. - - ctypedef struct libgamma_gamma_ramps16_t: - # Gamma ramp structure for 16-bit gamma ramps. - size_t red_size - # The size of `red`. - size_t green_size - # The size of `green`. - size_t blue_size - # The size of `blue`. - uint16_t* red - # The gamma ramp for the red channel. - uint16_t* green - # The gamma ramp for the green channel. - uint16_t* blue - # The gamma ramp for the blue channel. - - ctypedef struct libgamma_gamma_ramps32_t: - # Gamma ramp structure for 32-bit gamma ramps. - size_t red_size - # The size of `red`. - size_t green_size - # The size of `green`. - size_t blue_size - # The size of `blue`. - uint32_t* red - # The gamma ramp for the red channel. - uint32_t* green - # The gamma ramp for the green channel. - uint32_t* blue - # The gamma ramp for the blue channel. - - ctypedef struct libgamma_gamma_ramps64_t: - # Gamma ramp structure for 64-bit gamma ramps. - size_t red_size - # The size of `red`. - size_t green_size - # The size of `green`. - size_t blue_size - # The size of `blue`. - uint64_t* red - # The gamma ramp for the red channel. - uint64_t* green - # The gamma ramp for the green channel. - uint64_t* blue - # The gamma ramp for the blue channel. - - ctypedef struct libgamma_gamma_rampsf_t: - # Gamma ramp structure for `float` gamma ramps. - size_t red_size - # The size of `red`. - size_t green_size - # The size of `green`. - size_t blue_size - # The size of `blue`. - float* red - # The gamma ramp for the red channel. - float* green - # The gamma ramp for the green channel. - float* blue - # The gamma ramp for the blue channel. - - ctypedef struct libgamma_gamma_rampsd_t: - # Gamma ramp structure for `double` gamma ramps. - size_t red_size - # The size of `red`. - size_t green_size - # The size of `green`. - size_t blue_size - # The size of `blue`. - double* red - # The gamma ramp for the red channel. - double* green - # The gamma ramp for the green channel. - double* blue - # The gamma ramp for the blue channel. - - -cdef extern size_t libgamma_list_methods(int* methods, size_t buf_size, int operation) nogil -''' -List available adjustment methods by their order of preference based on the environment. - -@param methods Output array of methods, should be able to hold `LIBGAMMA_METHOD_COUNT` elements. -@param buf_size The number of elements that fits in `methods`, it should be `LIBGAMMA_METHOD_COUNT`, - This is used to avoid writing outside the output buffer if this library adds new - adjustment methods without the users of the library recompiling. -@param operation Allowed values: - 0: Methods that the environment suggests will work, excluding fake. - 1: Methods that the environment suggests will work, including fake. - 2: All real non-fake methods. - 3: All real methods. - 4: All methods. - Other values invoke undefined behaviour. -@return The number of element that have been stored in `methods`, or should - have been stored if the buffer was large enough. -''' - - -cdef extern int libgamma_is_method_available(int method) nogil -''' -Check whether an adjustment method is available, non-existing (invalid) methods will be -identified as not available under the rationale that the library may be out of date. - -@param method The adjustment method. -@return Whether the adjustment method is available. -''' - - -cdef extern void libgamma_method_capabilities(libgamma_method_capabilities_t* this, int method) nogil -''' -Return the capabilities of an adjustment method. - -@param this The data structure to fill with the method's capabilities -@param method The adjustment method (display server and protocol). -''' - - -cdef extern char* libgamma_method_default_site(int method) nogil -''' -Return the default site for an adjustment method. - -@param method The adjustment method (display server and protocol.) -@return The default site, `NULL` if it cannot be determined or - if multiple sites are not supported by the adjustment - method. This value should not be `free`:d. -''' - - -cdef extern const char* libgamma_method_default_site_variable(int method) nogil -''' -Return the default variable that determines -the default site for an adjustment method. - -@param method The adjustment method (display server and protocol.) -@return The environ variables that is used to determine the - default site. `NULL` if there is none, that is, if - the method does not support multiple sites. - This value should not be `free`:d. -''' - - - -cdef extern int libgamma_site_initialise(libgamma_site_state_t* this, int method, char* site) nogil -''' -Initialise an allocated site state. - -@param this The site state to initialise. -@param method The adjustment method (display server and protocol.) -@param site The site identifier, unless it is `NULL` it must a - `free`:able. One the state is destroyed the library - will attempt to free it. There you should not free - it yourself, and it must not be a string constant - or allocate on the stack. Note however that it will - not be `free`:d if this function fails. -@return Zero on success, otherwise (negative) the value of an - error identifier provided by this library. -''' - - -cdef extern void libgamma_site_free(libgamma_site_state_t* this) nogil -''' -Release all resources held by a site state -and free the site state pointer. - -@param this The site state. -''' - - -cdef extern int libgamma_site_restore(libgamma_site_state_t* this) nogil -''' -Restore the gamma ramps all CRTC:s with a site to the system settings. - -@param this The site state. -@return Zero on success, otherwise (negative) the value of an - error identifier provided by this library. -''' - - - -cdef extern int libgamma_partition_initialise(libgamma_partition_state_t* this, libgamma_site_state_t* site, size_t partition) nogil -''' -Initialise an allocated partition state. - -@param this The partition state to initialise. -@param site The site state for the site that the partition belongs to. -@param partition The index of the partition within the site. -@return Zero on success, otherwise (negative) the value of an - error identifier provided by this library. -''' - - -cdef extern void libgamma_partition_free(libgamma_partition_state_t* this) nogil -''' -Release all resources held by a partition state -and free the partition state pointer. - -@param this The partition state. -''' - - -cdef extern int libgamma_partition_restore(libgamma_partition_state_t* this) nogil -''' -Restore the gamma ramps all CRTC:s with a partition to the system settings. - -@param this The partition state. -@return Zero on success, otherwise (negative) the value of an - error identifier provided by this library. -''' - - - -cdef extern int libgamma_crtc_initialise(libgamma_crtc_state_t* this, libgamma_partition_state_t* partition, size_t crtc) nogil -''' -Initialise an allocated CRTC state. - -@param this The CRTC state to initialise. -@param partition The partition state for the partition that the CRTC belongs to. -@param crtc The index of the CRTC within the partition. -@return Zero on success, otherwise (negative) the value of an - error identifier provided by this library. -''' - - -cdef extern void libgamma_crtc_free(libgamma_crtc_state_t* this) nogil -''' -Release all resources held by a CRTC state -and free the CRTC state pointer. - -@param this The CRTC state. -''' - - -cdef extern int libgamma_crtc_restore(libgamma_crtc_state_t* this) nogil -''' -Restore the gamma ramps for a CRTC to the system settings for that CRTC. - -@param this The CRTC state -@return Zero on success, otherwise (negative) the value of an - error identifier provided by this library. -''' - - - -cdef extern int libgamma_get_crtc_information(libgamma_crtc_information_t* this, libgamma_crtc_state_t* crtc, int32_t fields) nogil -''' -Read information about a CRTC. - -@param this Instance of a data structure to fill with the information about the CRTC. -@param crtc The state of the CRTC whose information should be read. -@param fields OR:ed identifiers for the information about the CRTC that should be read. -@return Zero on success, -1 on error. On error refer to the error reports in `this`. -''' - - -cdef extern void libgamma_crtc_information_destroy(libgamma_crtc_information_t* this) nogil -''' -Release all resources in an information data structure for a CRTC. - -@param this The CRTC information. -''' - - - -cdef extern int libgamma_crtc_get_gamma_ramps8(libgamma_crtc_state_t* this, libgamma_gamma_ramps8_t* ramps) nogil -''' -Get the current gamma ramps for a CRTC, 8-bit gamma-depth version. - -@param this The CRTC state. -@param ramps The gamma ramps to fill with the current values -@return Zero on success, otherwise (negative) the value of an - error identifier provided by this library. -''' - - -cdef extern int libgamma_crtc_set_gamma_ramps8(libgamma_crtc_state_t* this, libgamma_gamma_ramps8_t ramps) nogil -''' -Set the gamma ramps for a CRTC, 8-bit gamma-depth version. - -@param this The CRTC state. -@param ramps The gamma ramps to apply. -@return Zero on success, otherwise (negative) the value of an - error identifier provided by this library. -''' - - - -cdef extern int libgamma_crtc_get_gamma_ramps16(libgamma_crtc_state_t* this, libgamma_gamma_ramps16_t* ramps) nogil -''' -Get the current gamma ramps for a CRTC, 16-bit gamma-depth version. - -@param this The CRTC state. -@param ramps The gamma ramps to fill with the current values -@return Zero on success, otherwise (negative) the value of an - error identifier provided by this library. -''' - - -cdef extern int libgamma_crtc_set_gamma_ramps16(libgamma_crtc_state_t* this, libgamma_gamma_ramps16_t ramps) nogil -''' -Set the gamma ramps for a CRTC, 16-bit gamma-depth version. - -@param this The CRTC state. -@param ramps The gamma ramps to apply. -@return Zero on success, otherwise (negative) the value of an - error identifier provided by this library. -''' - - - -cdef extern int libgamma_crtc_get_gamma_ramps32(libgamma_crtc_state_t* this, libgamma_gamma_ramps32_t* ramps) nogil -''' -Get the current gamma ramps for a CRTC, 32-bit gamma-depth version. - -@param this The CRTC state. -@param ramps The gamma ramps to fill with the current values. -@return Zero on success, otherwise (negative) the value of an - error identifier provided by this library. -''' - - -cdef extern int libgamma_crtc_set_gamma_ramps32(libgamma_crtc_state_t* this, libgamma_gamma_ramps32_t ramps) nogil -''' -Set the gamma ramps for a CRTC, 32-bit gamma-depth version. - -@param this The CRTC state. -@param ramps The gamma ramps to apply. -@return Zero on success, otherwise (negative) the value of an - error identifier provided by this library. -''' - - - -cdef extern int libgamma_crtc_get_gamma_ramps64(libgamma_crtc_state_t* this, libgamma_gamma_ramps64_t* ramps) nogil -''' -Get the current gamma ramps for a CRTC, 64-bit gamma-depth version. - -@param this The CRTC state. -@param ramps The gamma ramps to fill with the current values. -@return Zero on success, otherwise (negative) the value of an - error identifier provided by this library. -''' - - -cdef extern int libgamma_crtc_set_gamma_ramps64(libgamma_crtc_state_t* this, libgamma_gamma_ramps64_t ramps) nogil -''' -Set the gamma ramps for a CRTC, 64-bit gamma-depth version. - -@param this The CRTC state. -@param ramps The gamma ramps to apply. -@return Zero on success, otherwise (negative) the value of an - error identifier provided by this library. -''' - - - -cdef extern int libgamma_crtc_set_gamma_rampsf(libgamma_crtc_state_t* this, libgamma_gamma_rampsf_t ramps) nogil -''' -Set the gamma ramps for a CRTC, `float` version. - -@param this The CRTC state. -@param ramps The gamma ramps to apply. -@return Zero on success, otherwise (negative) the value of an - error identifier provided by this library. -''' - - -cdef extern int libgamma_crtc_get_gamma_rampsf(libgamma_crtc_state_t* this, libgamma_gamma_rampsf_t* ramps) nogil -''' -Get the current gamma ramps for a CRTC, `float` version. - -@param this The CRTC state. -@param ramps The gamma ramps to fill with the current values. -@return Zero on success, otherwise (negative) the value of an - error identifier provided by this library. -''' - - - -cdef extern int libgamma_crtc_get_gamma_rampsd(libgamma_crtc_state_t* this, libgamma_gamma_rampsd_t* ramps) nogil -''' -Get the current gamma ramps for a CRTC, `double` version. - -@param this The CRTC state. -@param ramps The gamma ramps to fill with the current values. -@return Zero on success, otherwise (negative) the value of an - error identifier provided by this library. -''' - - -cdef extern int libgamma_crtc_set_gamma_rampsd(libgamma_crtc_state_t* this, libgamma_gamma_rampsd_t ramps) nogil -''' -Set the gamma ramps for a CRTC, `double` version. - -@param this The CRTC state. -@param ramps The gamma ramps to apply. -@return Zero on success, otherwise (negative) the value of an - error identifier provided by this library. -''' - - - -def libgamma_native_list_methods(operation : int) -> list: - ''' - List available adjustment methods by their order of preference based on the environment. - - @param operation Allowed values: - 0: Methods that the environment suggests will work, excluding fake. - 1: Methods that the environment suggests will work, including fake. - 2: All real non-fake methods. - 3: All real methods. - 4: All methods. - Other values invoke undefined behaviour. - @return :list A list of available adjustment methods. - ''' - cdef int* methods - cdef size_t buf_size - cdef size_t r - buf_size = 6 - methods = malloc(buf_size * sizeof(size_t)) - if methods == NULL: - raise MemoryError() - r = libgamma_list_methods(methods, buf_size, operation) - if r > buf_size: - buf_size = r - free(methods) - methods = malloc(buf_size * sizeof(size_t)) - if methods == NULL: - raise MemoryError() - libgamma_list_methods(methods, buf_size, operation) - rc = [] - for i in range(r): - rc.append(methods[i]) - free(methods) - return rc - - -def libgamma_native_is_method_available(method : int) -> int: - ''' - Check whether an adjustment method is available, non-existing (invalid) methods will be - identified as not available under the rationale that the library may be out of date. - - @param method The adjustment method. - @return Whether the adjustment method is available. - ''' - return int(libgamma_is_method_available(method)) - - -def libgamma_native_method_capabilities(method : int) -> tuple: - ''' - Return the capabilities of an adjustment method. - - @param method The adjustment method (display server and protocol). - @return :(int, int) Input parameters for `MethodCapabilities.__init__`. - ''' - cdef libgamma_method_capabilities_t caps - libgamma_method_capabilities(&caps, method) - booleans = 0 - crtc_information = int(caps.crtc_information) - booleans |= (0 if caps.default_site_known == 0 else 1) << 0 - booleans |= (0 if caps.multiple_sites == 0 else 1) << 1 - booleans |= (0 if caps.multiple_partitions == 0 else 1) << 2 - booleans |= (0 if caps.multiple_crtcs == 0 else 1) << 3 - booleans |= (0 if caps.partitions_are_graphics_cards == 0 else 1) << 4 - booleans |= (0 if caps.site_restore == 0 else 1) << 5 - booleans |= (0 if caps.partition_restore == 0 else 1) << 6 - booleans |= (0 if caps.crtc_restore == 0 else 1) << 7 - booleans |= (0 if caps.identical_gamma_sizes == 0 else 1) << 8 - booleans |= (0 if caps.fixed_gamma_size == 0 else 1) << 9 - booleans |= (0 if caps.fixed_gamma_depth == 0 else 1) << 10 - booleans |= (0 if caps.real == 0 else 1) << 11 - booleans |= (0 if caps.fake == 0 else 1) << 12 - return (crtc_information, booleans) - - -def libgamma_native_method_default_site(method : int) -> str: - ''' - Return the default site for an adjustment method. - - @param method The adjustment method (display server and protocol.) - @return The default site, `None` if it cannot be determined or - if multiple sites are not supported by the adjustment - method. - ''' - cdef char* var - cdef bytes bs - var = libgamma_method_default_site(method) - if var is NULL: - return None - bs = var - return bs.decode('utf-8', 'strict') - - -def libgamma_native_method_default_site_variable(method : int) -> str: - ''' - Return the default variable that determines - the default site for an adjustment method. - - @param method The adjustment method (display server and protocol.) - @return The environ variables that is used to determine the - default site. `None` if there is none, that is, if - the method does not support multiple sites. - ''' - cdef const char* var - cdef bytes bs - var = libgamma_method_default_site_variable(method) - if var is NULL: - return None - bs = var - return bs.decode('utf-8', 'strict') - - - -def libgamma_native_site_create(method : int, site : str) -> tuple: - ''' - Create an allocated site state. - - @param method The adjustment method (display server and protocol.) - @param site The site identifier, unless it is `NULL` it must a - `free`:able. One the state is destroyed the library - will attempt to free it. There you should not free - it yourself, and it must not be a string constant - or allocate on the stack. Note however that it will - not be `free`:d if this function fails. - @return :(site:int, partitions:int) First value: The created site, zero on error - Second value: The number of partitions in the site, - on error: the value of the error identifier - provided by this library or `errno`. - ''' - cdef libgamma_site_state_t* this - cdef char* site_ - cdef size_t this_address - this = malloc(sizeof(libgamma_site_state_t)) - if this is NULL: - raise MemoryError() - this_address = this - site_ = NULL - if site is not None: - site_bs = site.encode('utf-8') + bytes([0]) - site_ = malloc(len(site_bs) * sizeof(char)) - if site_ is None: - free(this) - raise MemoryError() - for i in range(len(site_bs)): - site_[i] = (site_bs[i]) - r = int(libgamma_site_initialise(this, method, site_)) - if not r == 0: - libgamma_site_free(this) - return (0, int(errno) if r == -1 else r) - return (int(this_address), int(this.partitions_available)) - - -def libgamma_native_site_free(this : int): - ''' - Release all resources held by a site state - and free the CRTC state pointer. - - @param this The site state. - ''' - cdef size_t this_address - cdef libgamma_site_state_t* this_ - this_address = this - this_ = this_address - libgamma_site_free(this_) - - -def libgamma_native_site_restore(this : int) -> int: - ''' - Restore the gamma ramps all CRTC:s with a site to the system settings. - - @param this The site state. - @return Zero on success, otherwise the value of an error - identifier provided by this library or `errno`. - ''' - cdef size_t this_address - cdef libgamma_site_state_t* this_ - this_address = this - this_ = this_address - r = int(libgamma_site_restore(this_)) - return int(errno) if r == -1 else r - - - -def libgamma_native_partition_create(site : int, partition : int) -> tuple: - ''' - Create an allocated partition state. - - @param site The site state for the site that the partition belongs to. - @param partition The index of the partition within the site. - @return :(site:int, partitions:int) First value: The created partition, zero on error - Second value: The number of CRTC:s in the partition, - on error: the value of the error identifier - provided by this library or `errno`. - ''' - cdef libgamma_partition_state_t* this - cdef libgamma_site_state_t* site_ - cdef size_t this_address - cdef size_t site_address - site_address = site - site_ = site_address - this = malloc(sizeof(libgamma_partition_state_t)) - if this is NULL: - raise MemoryError() - this_address = this - r = int(libgamma_partition_initialise(this, site_, partition)) - if not r == 0: - libgamma_partition_free(this) - return (0, int(errno) if r == -1 else r) - return (int(this_address), int(this.crtcs_available)) - - -def libgamma_native_partition_free(this : int): - ''' - Release all resources held by a partition state - and free the partition state pointer. - - @param this The partition state. - ''' - cdef size_t this_address - cdef libgamma_partition_state_t* this_ - this_address = this - this_ = this_address - libgamma_partition_free(this_) - - -def libgamma_native_partition_restore(this : int) -> int: - ''' - Restore the gamma ramps all CRTC:s with a partition to the system settings. - - @param this The partition state. - @return Zero on success, otherwise the value of an error - identifier provided by this library or `errno`. - ''' - cdef size_t this_address - cdef libgamma_partition_state_t* this_ - this_address = this - this_ = this_address - r = int(libgamma_partition_restore(this_)) - return int(errno) if r == -1 else r - - - -def libgamma_native_crtc_create(partition : int, crtc : int) -> tuple: - ''' - Create an allocated CRTC state. - - @param partition The partition state for the partition that the CRTC belongs to. - @param crtc The index of the CRTC within the partition. - @return :(int, int) First value: The created CRTC, zero on error. - Second value: Zero on success, otherwise the value of an error - identifier provided by this library or `errno`. - ''' - cdef libgamma_crtc_state_t* this - cdef libgamma_partition_state_t* partition_ - cdef size_t this_address - cdef size_t partition_address - partition_address = partition - partition_ = partition_address - this = malloc(sizeof(libgamma_crtc_state_t)) - if this is NULL: - raise MemoryError() - this_address = this - r = int(libgamma_crtc_initialise(this, partition_, crtc)) - if not r == 0: - libgamma_crtc_free(this) - return (0, int(errno) if r == -1 else r) - return (int(this_address), 0) - - -def libgamma_native_crtc_free(this : int): - ''' - Release all resources held by a CRTC state - and free the CRTC state pointer. - - @param this The CRTC state. - ''' - cdef size_t this_address - cdef libgamma_crtc_state_t* this_ - this_address = this - this_ = this_address - libgamma_crtc_free(this_) - - -def libgamma_native_crtc_restore(this : int) -> int: - ''' - Restore the gamma ramps for a CRTC to the system settings for that CRTC. - - @param this The CRTC state - @return Zero on success, otherwise the value of an error - identifier provided by this library or `errno`. - ''' - cdef size_t this_address - cdef libgamma_crtc_state_t* this_ - this_address = this - this_ = this_address - r = int(libgamma_crtc_restore(this_)) - return int(errno) if r == -1 else r - - - -def libgamma_native_get_crtc_information(crtc : int, fields : int) -> tuple: - ''' - Read information about a CRTC. - - @param crtc The state of the CRTC whose information should be read. - @param field OR:ed identifiers for the information about the CRTC that should be read. - @return :(list, :int) First value: Input parametrs for `CRTCInformation.__init__` - Second value: Zero on success, -1 on error. On error refer to - the error reports in the return. - ''' - cdef libgamma_crtc_information_t info - cdef size_t crtc_address - cdef libgamma_crtc_state_t* crtc_ - cdef bytes bs - crtc_address = crtc - crtc_ = crtc_address - r = int(libgamma_get_crtc_information(&info, crtc_, fields)) - rc = [] - connector_name = None - if info.connector_name is not NULL: - bs = info.connector_name - connector_name = bs.decode('utf-8', 'strict') - edid = None - if info.edid is not NULL: - bs = info.edid[:info.edid_length] - edid = bs - rc.append(edid) - rc.append(int(info.edid_error)) - rc.append(int(info.width_mm)) - rc.append(int(info.width_mm_error)) - rc.append(int(info.height_mm)) - rc.append(int(info.height_mm_error)) - rc.append(int(info.width_mm_edid)) - rc.append(int(info.width_mm_edid_error)) - rc.append(int(info.height_mm_edid)) - rc.append(int(info.height_mm_edid_error)) - rc.append(int(info.red_gamma_size)) - rc.append(int(info.green_gamma_size)) - rc.append(int(info.blue_gamma_size)) - rc.append(int(info.gamma_size_error)) - rc.append(int(info.gamma_depth)) - rc.append(int(info.gamma_depth_error)) - rc.append(int(info.gamma_support)) - rc.append(int(info.gamma_support_error)) - rc.append(int(info.subpixel_order)) - rc.append(int(info.subpixel_order_error)) - rc.append(int(info.active)) - rc.append(int(info.active_error)) - rc.append(connector_name) - rc.append(int(info.connector_name_error)) - rc.append(int(info.connector_type)) - rc.append(int(info.connector_type_error)) - rc.append(float(info.gamma_red)) - rc.append(float(info.gamma_green)) - rc.append(float(info.gamma_blue)) - rc.append(int(info.gamma_error)) - libgamma_crtc_information_destroy(&info) - return (rc, r) - - - -def libgamma_native_crtc_get_gamma_ramps8(this : int, ramps : int) -> int: - ''' - Get the current gamma ramps for a CRTC, 8-bit gamma-depth version. - - @param this The CRTC state. - @param ramps The gamma ramps to fill with the current values. - @return Zero on success, otherwise the value of an error - identifier provided by this library or `errno`. - ''' - cdef size_t this_address - cdef size_t ramps_address - cdef libgamma_crtc_state_t* this_ - cdef libgamma_gamma_ramps8_t* ramps_ - this_address = this - ramps_address = ramps - this_ = this_address - ramps_ = ramps_address - r = int(libgamma_crtc_get_gamma_ramps8(this_, ramps_)) - return int(errno) if r == -1 else r - - -def libgamma_native_crtc_set_gamma_ramps8(this : int, ramps : int) -> int: - ''' - Set the gamma ramps for a CRTC, 8-bit gamma-depth version. - - @param this The CRTC state. - @param ramps The gamma ramps to apply. - @return Zero on success, otherwise the value of an error - identifier provided by this library or `errno`. - ''' - cdef size_t this_address - cdef size_t ramps_address - cdef libgamma_crtc_state_t* this_ - cdef libgamma_gamma_ramps8_t* ramps_ - this_address = this - ramps_address = ramps - this_ = this_address - ramps_ = ramps_address - r = int(libgamma_crtc_set_gamma_ramps8(this_, ramps_[0])) - return int(errno) if r == -1 else r - - - -def libgamma_native_crtc_get_gamma_ramps16(this : int, ramps : int) -> int: - ''' - Get the current gamma ramps for a CRTC, 16-bit gamma-depth version. - - @param this The CRTC state. - @param ramps The gamma ramps to fill with the current values. - @return Zero on success, otherwise the value of an error - identifier provided by this library or `errno`. - ''' - cdef size_t this_address - cdef size_t ramps_address - cdef libgamma_crtc_state_t* this_ - cdef libgamma_gamma_ramps16_t* ramps_ - this_address = this - ramps_address = ramps - this_ = this_address - ramps_ = ramps_address - r = int(libgamma_crtc_get_gamma_ramps16(this_, ramps_)) - return int(errno) if r == -1 else r - - -def libgamma_native_crtc_set_gamma_ramps16(this : int, ramps : int) -> int: - ''' - Set the gamma ramps for a CRTC, 16-bit gamma-depth version. - - @param this The CRTC state. - @param ramps The gamma ramps to apply. - @return Zero on success, otherwise the value of an error - identifier provided by this library or `errno`. - ''' - cdef size_t this_address - cdef size_t ramps_address - cdef libgamma_crtc_state_t* this_ - cdef libgamma_gamma_ramps16_t* ramps_ - this_address = this - ramps_address = ramps - this_ = this_address - ramps_ = ramps_address - r = int(libgamma_crtc_set_gamma_ramps16(this_, ramps_[0])) - return int(errno) if r == -1 else r - - - -def libgamma_native_crtc_get_gamma_ramps32(this : int, ramps : int) -> int: - ''' - Get the current gamma ramps for a CRTC, 32-bit gamma-depth version. - - @param this The CRTC state. - @param ramps The gamma ramps to fill with the current values. - @return Zero on success, otherwise the value of an error - identifier provided by this library or `errno`. - ''' - cdef size_t this_address - cdef size_t ramps_address - cdef libgamma_crtc_state_t* this_ - cdef libgamma_gamma_ramps32_t* ramps_ - this_address = this - ramps_address = ramps - this_ = this_address - ramps_ = ramps_address - r = int(libgamma_crtc_get_gamma_ramps32(this_, ramps_)) - return int(errno) if r == -1 else r - - -def libgamma_native_crtc_set_gamma_ramps32(this : int, ramps : int) -> int: - ''' - Set the gamma ramps for a CRTC, 32-bit gamma-depth version. - - @param this The CRTC state. - @param ramps The gamma ramps to apply. - @return Zero on success, otherwise the value of an error - identifier provided by this library or `errno`. - ''' - cdef size_t this_address - cdef size_t ramps_address - cdef libgamma_crtc_state_t* this_ - cdef libgamma_gamma_ramps32_t* ramps_ - this_address = this - ramps_address = ramps - this_ = this_address - ramps_ = ramps_address - r = int(libgamma_crtc_set_gamma_ramps32(this_, ramps_[0])) - return int(errno) if r == -1 else r - - - -def libgamma_native_crtc_get_gamma_ramps64(this : int, ramps : int) -> int: - ''' - Get the current gamma ramps for a CRTC, 64-bit gamma-depth version. - - @param this The CRTC state. - @param ramps The gamma ramps to fill with the current values. - @return Zero on success, otherwise the value of an error - identifier provided by this library or `errno`. - ''' - cdef size_t this_address - cdef size_t ramps_address - cdef libgamma_crtc_state_t* this_ - cdef libgamma_gamma_ramps64_t* ramps_ - this_address = this - ramps_address = ramps - this_ = this_address - ramps_ = ramps_address - r = int(libgamma_crtc_get_gamma_ramps64(this_, ramps_)) - return int(errno) if r == -1 else r - - -def libgamma_native_crtc_set_gamma_ramps64(this : int, ramps : int) -> int: - ''' - Set the gamma ramps for a CRTC, 64-bit gamma-depth version. - - @param this The CRTC state. - @param ramps The gamma ramps to apply. - @return Zero on success, otherwise the value of an error - identifier provided by this library or `errno`. - ''' - cdef size_t this_address - cdef size_t ramps_address - cdef libgamma_crtc_state_t* this_ - cdef libgamma_gamma_ramps64_t* ramps_ - this_address = this - ramps_address = ramps - this_ = this_address - ramps_ = ramps_address - r = int(libgamma_crtc_set_gamma_ramps64(this_, ramps_[0])) - return int(errno) if r == -1 else r - - - -def libgamma_native_crtc_get_gamma_rampsf(this : int, ramps : int) -> int: - ''' - Get the current gamma ramps for a CRTC, `float` version. - - @param this The CRTC state. - @param ramps The gamma ramps to fill with the current values. - @return Zero on success, otherwise the value of an error - identifier provided by this library or `errno`. - ''' - cdef size_t this_address - cdef size_t ramps_address - cdef libgamma_crtc_state_t* this_ - cdef libgamma_gamma_rampsf_t* ramps_ - this_address = this - ramps_address = ramps - this_ = this_address - ramps_ = ramps_address - r = int(libgamma_crtc_get_gamma_rampsf(this_, ramps_)) - return int(errno) if r == -1 else r - - -def libgamma_native_crtc_set_gamma_rampsf(this : int, ramps : int) -> int: - ''' - Set the gamma ramps for a CRTC, `float` version. - - @param this The CRTC state. - @param ramps The gamma ramps to apply. - @return Zero on success, otherwise the value of an error - identifier provided by this library or `errno`. - ''' - cdef size_t this_address - cdef size_t ramps_address - cdef libgamma_crtc_state_t* this_ - cdef libgamma_gamma_rampsf_t* ramps_ - this_address = this - ramps_address = ramps - this_ = this_address - ramps_ = ramps_address - r = int(libgamma_crtc_set_gamma_rampsf(this_, ramps_[0])) - return int(errno) if r == -1 else r - - - -def libgamma_native_crtc_get_gamma_rampsd(this : int, ramps : int) -> int: - ''' - Get the current gamma ramps for a CRTC, `double` version. - - @param this The CRTC state. - @param ramps The gamma ramps to fill with the current values. - @return Zero on success, otherwise the value of an error - identifier provided by this library or `errno`. - ''' - cdef size_t this_address - cdef size_t ramps_address - cdef libgamma_crtc_state_t* this_ - cdef libgamma_gamma_rampsd_t* ramps_ - this_address = this - ramps_address = ramps - this_ = this_address - ramps_ = ramps_address - r = int(libgamma_crtc_get_gamma_rampsd(this_, ramps_)) - return int(errno) if r == -1 else r - - -def libgamma_native_crtc_set_gamma_rampsd(this : int, ramps : int) -> int: - ''' - Set the gamma ramps for a CRTC, `double` version. - - @param this The CRTC state. - @param ramps The gamma ramps to apply. - @return Zero on success, otherwise the value of an error - identifier provided by this library or `errno`. - ''' - cdef size_t this_address - cdef size_t ramps_address - cdef libgamma_crtc_state_t* this_ - cdef libgamma_gamma_rampsd_t* ramps_ - this_address = this - ramps_address = ramps - this_ = this_address - ramps_ = ramps_address - r = int(libgamma_crtc_set_gamma_rampsd(this_, ramps_[0])) - return int(errno) if r == -1 else r - diff --git a/src/libgamma_native_method.pyx b/src/libgamma_native_method.pyx deleted file mode 100644 index 1550caf..0000000 --- a/src/libgamma_native_method.pyx +++ /dev/null @@ -1,682 +0,0 @@ -# -*- python -*- -''' -pylibgamma — Python 3 wrapper for libgamma -Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) - -This library 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 library 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 library. If not, see . -''' - -cimport cython - -from libc.stdint cimport * -from libc.stdlib cimport malloc -from libc.stddef cimport size_t -from libc.errno cimport errno - - -cdef extern from "include-libgamma.h": - ctypedef struct libgamma_gamma_ramps8_t: - # Gamma ramp structure for 8-bit gamma ramps. - size_t red_size - # The size of `red`. - size_t green_size - # The size of `green`. - size_t blue_size - # The size of `blue`. - uint8_t* red - # The gamma ramp for the red channel. - uint8_t* green - # The gamma ramp for the green channel. - uint8_t* blue - # The gamma ramp for the blue channel. - - ctypedef struct libgamma_gamma_ramps16_t: - # Gamma ramp structure for 16-bit gamma ramps. - size_t red_size - # The size of `red`. - size_t green_size - # The size of `green`. - size_t blue_size - # The size of `blue`. - uint16_t* red - # The gamma ramp for the red channel. - uint16_t* green - # The gamma ramp for the green channel. - uint16_t* blue - # The gamma ramp for the blue channel. - - ctypedef struct libgamma_gamma_ramps32_t: - # Gamma ramp structure for 32-bit gamma ramps. - size_t red_size - # The size of `red`. - size_t green_size - # The size of `green`. - size_t blue_size - # The size of `blue`. - uint32_t* red - # The gamma ramp for the red channel. - uint32_t* green - # The gamma ramp for the green channel. - uint32_t* blue - # The gamma ramp for the blue channel. - - ctypedef struct libgamma_gamma_ramps64_t: - # Gamma ramp structure for 64-bit gamma ramps. - size_t red_size - # The size of `red`. - size_t green_size - # The size of `green`. - size_t blue_size - # The size of `blue`. - uint64_t* red - # The gamma ramp for the red channel. - uint64_t* green - # The gamma ramp for the green channel. - uint64_t* blue - # The gamma ramp for the blue channel. - - ctypedef struct libgamma_gamma_rampsf_t: - # Gamma ramp structure for `float` gamma ramps. - size_t red_size - # The size of `red`. - size_t green_size - # The size of `green`. - size_t blue_size - # The size of `blue`. - float* red - # The gamma ramp for the red channel. - float* green - # The gamma ramp for the green channel. - float* blue - # The gamma ramp for the blue channel. - - ctypedef struct libgamma_gamma_rampsd_t: - # Gamma ramp structure for `double` gamma ramps. - size_t red_size - # The size of `red`. - size_t green_size - # The size of `green`. - size_t blue_size - # The size of `blue`. - double* red - # The gamma ramp for the red channel. - double* green - # The gamma ramp for the green channel. - double* blue - # The gamma ramp for the blue channel. - - -cdef extern int libgamma_gamma_ramps8_initialise(libgamma_gamma_ramps8_t* this) nogil -''' -Initialise a gamma ramp in the proper way that allows all adjustment -methods to read from and write to it without causing segmentation violation. - -The input must have `red_size`, `green_size` and `blue_size` set to the -sizes of the gamma ramps that should be allocated. - -@param this The gamma ramps. -@return Zero on success, -1 on allocation error, `errno` will be set accordingly. -''' - -cdef extern void libgamma_gamma_ramps8_free(libgamma_gamma_ramps8_t* this) nogil -''' -Release resources that are held by a gamma ramp strcuture that -has been allocated by `libgamma_gamma_ramps8_initialise` or otherwise -initialises in the proper manner, as well as release the pointer -to the structure. - -@param this The gamma ramps. -''' - - -cdef extern int libgamma_gamma_ramps16_initialise(libgamma_gamma_ramps16_t* this) nogil -''' -Initialise a gamma ramp in the proper way that allows all adjustment -methods to read from and write to it without causing segmentation violation. - -The input must have `red_size`, `green_size` and `blue_size` set to the -sizes of the gamma ramps that should be allocated. - -@param this The gamma ramps. -@return Zero on success, -1 on allocation error, `errno` will be set accordingly. -''' - -cdef extern void libgamma_gamma_ramps16_free(libgamma_gamma_ramps16_t* this) nogil -''' -Release resources that are held by a gamma ramp strcuture that -has been allocated by `libgamma_gamma_ramps16_initialise` or otherwise -initialises in the proper manner, as well as release the pointer -to the structure. - -@param this The gamma ramps. -''' - - -cdef extern int libgamma_gamma_ramps32_initialise(libgamma_gamma_ramps32_t* this) nogil -''' -Initialise a gamma ramp in the proper way that allows all adjustment -methods to read from and write to it without causing segmentation violation. - -The input must have `red_size`, `green_size` and `blue_size` set to the -sizes of the gamma ramps that should be allocated. - -@param this The gamma ramps. -@return Zero on success, -1 on allocation error, `errno` will be set accordingly. -''' - -cdef extern void libgamma_gamma_ramps32_free(libgamma_gamma_ramps32_t* this) nogil -''' -Release resources that are held by a gamma ramp strcuture that -has been allocated by `libgamma_gamma_ramps32_initialise` or otherwise -initialises in the proper manner, as well as release the pointer -to the structure. - -@param this The gamma ramps. -''' - - -cdef extern int libgamma_gamma_ramps64_initialise(libgamma_gamma_ramps64_t* this) nogil -''' -Initialise a gamma ramp in the proper way that allows all adjustment -methods to read from and write to it without causing segmentation violation. - -The input must have `red_size`, `green_size` and `blue_size` set to the -sizes of the gamma ramps that should be allocated. - -@param this The gamma ramps. -@return Zero on success, -1 on allocation error, `errno` will be set accordingly. -''' - -cdef extern void libgamma_gamma_ramps64_free(libgamma_gamma_ramps64_t* this) nogil -''' -Release resources that are held by a gamma ramp strcuture that -has been allocated by `libgamma_gamma_ramps64_initialise` or otherwise -initialises in the proper manner, as well as release the pointer -to the structure. - -@param this The gamma ramps. -''' - - -cdef extern int libgamma_gamma_rampsf_initialise(libgamma_gamma_rampsf_t* this) nogil -''' -Initialise a gamma ramp in the proper way that allows all adjustment -methods to read from and write to it without causing segmentation violation. - -The input must have `red_size`, `green_size` and `blue_size` set to the -sizes of the gamma ramps that should be allocated. - -@param this The gamma ramps. -@return Zero on success, -1 on allocation error, `errno` will be set accordingly. -''' - -cdef extern void libgamma_gamma_rampsf_free(libgamma_gamma_rampsf_t* this) nogil -''' -Release resources that are held by a gamma ramp strcuture that -has been allocated by `libgamma_gamma_rampsf_initialise` or otherwise -initialises in the proper manner, as well as release the pointer -to the structure. - -@param this The gamma ramps. -''' - - -cdef extern int libgamma_gamma_rampsd_initialise(libgamma_gamma_rampsd_t* this) nogil -''' -Initialise a gamma ramp in the proper way that allows all adjustment -methods to read from and write to it without causing segmentation violation. - -The input must have `red_size`, `green_size` and `blue_size` set to the -sizes of the gamma ramps that should be allocated. - -@param this The gamma ramps -@return Zero on success, -1 on allocation error, `errno` will be set accordingly. -''' - -cdef extern void libgamma_gamma_rampsd_free(libgamma_gamma_rampsd_t* this) nogil -''' -Release resources that are held by a gamma ramp strcuture that -has been allocated by `libgamma_gamma_rampsd_initialise` or otherwise -initialises in the proper manner, as well as release the pointer -to the structure. - -@param this The gamma ramps. -''' - - - -def libgamma_native_gamma_ramps8_create(red_size : int, green_size : int, blue_size : int): - ''' - Create a gamma ramp in the proper way that allows all adjustment - methods to read from and write to it without causing segmentation violation. - - @param red_size The size of the gamma ramp for the red channel - @param green_size The size of the gamma ramp for the green channel - @param blue_size The size of the gamma ramp for the blue channel - @return :(int){4}|int The tuple that describes the created data, `errno` on failure: - Element 1: The address of the gamma ramp structure - Element 2: The address of the gamma ramp for the red channel - Element 3: The address of the gamma ramp for the green channel - Element 4: The address of the gamma ramp for the blue channel - ''' - cdef void* allocation = malloc(sizeof(libgamma_gamma_ramps8_t)) - cdef libgamma_gamma_ramps8_t* item = allocation - cdef size_t red, green, blue - if item is NULL: - return int(errno) - item.red_size = red_size - item.green_size = green_size - item.blue_size = blue_size - if libgamma_gamma_ramps8_initialise(item) < 0: - return int(errno) - red = (item.red) - green = (item.green) - blue = (item.blue) - return (int(allocation), int(red), int(green), int(blue)) - - -def libgamma_native_gamma_ramps8_free(this : int): - ''' - Release resources that are held by a gamma ramp strcuture that - has been allocated by `libgamma_native_gamma_ramps8_create` or otherwise - created in the proper manner, as well as release the pointer - to the structure. - - @param this The gamma ramps. - ''' - cdef void* address = this - cdef libgamma_gamma_ramps8_t* item = address - libgamma_gamma_ramps8_free(item) - - -def libgamma_native_gamma_ramps8_get(this : int, index : int) -> int: - ''' - Read a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @return The value of the gamma ramp stop. - ''' - cdef void* address = this - cdef uint8_t* ramp = address - return int(ramp[index]) - - -def libgamma_native_gamma_ramps8_set(this : int, index : int, value : int): - ''' - Modify a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @param value The value of the gamma ramp stop. - ''' - cdef void* address = this - cdef uint8_t* ramp = address - ramp[index] = value - - - -def libgamma_native_gamma_ramps16_create(red_size : int, green_size : int, blue_size : int): - ''' - Create a gamma ramp in the proper way that allows all adjustment - methods to read from and write to it without causing segmentation violation. - - @param red_size The size of the gamma ramp for the red channel - @param green_size The size of the gamma ramp for the green channel - @param blue_size The size of the gamma ramp for the blue channel - @return :(int){4}|int The tuple that describes the created data, `errno` on failure: - Element 1: The address of the gamma ramp structure - Element 2: The address of the gamma ramp for the red channel - Element 3: The address of the gamma ramp for the green channel - Element 4: The address of the gamma ramp for the blue channel - ''' - cdef void* allocation = malloc(sizeof(libgamma_gamma_ramps16_t)) - cdef libgamma_gamma_ramps16_t* item = allocation - cdef size_t red, green, blue - if item is NULL: - return int(errno) - item.red_size = red_size - item.green_size = green_size - item.blue_size = blue_size - if libgamma_gamma_ramps16_initialise(item) < 0: - return int(errno) - red = (item.red) - green = (item.green) - blue = (item.blue) - return (int(allocation), int(red), int(green), int(blue)) - - -def libgamma_native_gamma_ramps16_free(this : int): - ''' - Release resources that are held by a gamma ramp strcuture that - has been allocated by `libgamma_native_gamma_ramps16_create` or otherwise - created in the proper manner, as well as release the pointer - to the structure. - - @param this The gamma ramps. - ''' - cdef void* address = this - cdef libgamma_gamma_ramps16_t* item = address - libgamma_gamma_ramps16_free(item) - - -def libgamma_native_gamma_ramps16_get(this : int, index : int) -> int: - ''' - Read a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @return The value of the gamma ramp stop. - ''' - cdef void* address = this - cdef uint16_t* ramp = address - return int(ramp[index]) - - -def libgamma_native_gamma_ramps16_set(this : int, index : int, value : int): - ''' - Modify a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @param value The value of the gamma ramp stop. - ''' - cdef void* address = this - cdef uint16_t* ramp = address - ramp[index] = value - - - -def libgamma_native_gamma_ramps32_create(red_size : int, green_size : int, blue_size : int): - ''' - Create a gamma ramp in the proper way that allows all adjustment - methods to read from and write to it without causing segmentation violation. - - @param red_size The size of the gamma ramp for the red channel - @param green_size The size of the gamma ramp for the green channel - @param blue_size The size of the gamma ramp for the blue channel - @return :(int){4}|int The tuple that describes the created data, `errno` on failure: - Element 1: The address of the gamma ramp structure - Element 2: The address of the gamma ramp for the red channel - Element 3: The address of the gamma ramp for the green channel - Element 4: The address of the gamma ramp for the blue channel - ''' - cdef void* allocation = malloc(sizeof(libgamma_gamma_ramps32_t)) - cdef libgamma_gamma_ramps32_t* item = allocation - cdef size_t red, green, blue - if item is NULL: - return int(errno) - item.red_size = red_size - item.green_size = green_size - item.blue_size = blue_size - if libgamma_gamma_ramps32_initialise(item) < 0: - return int(errno) - red = (item.red) - green = (item.green) - blue = (item.blue) - return (int(allocation), int(red), int(green), int(blue)) - - -def libgamma_native_gamma_ramps32_free(this : int): - ''' - Release resources that are held by a gamma ramp strcuture that - has been allocated by `libgamma_native_gamma_ramps32_create` or otherwise - created in the proper manner, as well as release the pointer - to the structure. - - @param this The gamma ramps. - ''' - cdef void* address = this - cdef libgamma_gamma_ramps32_t* item = address - libgamma_gamma_ramps32_free(item) - - -def libgamma_native_gamma_ramps32_get(this : int, index : int) -> int: - ''' - Read a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @return The value of the gamma ramp stop. - ''' - cdef void* address = this - cdef uint32_t* ramp = address - return int(ramp[index]) - - -def libgamma_native_gamma_ramps32_set(this : int, index : int, value : int): - ''' - Modify a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @param value The value of the gamma ramp stop. - ''' - cdef void* address = this - cdef uint32_t* ramp = address - ramp[index] = value - - - -def libgamma_native_gamma_ramps64_create(red_size : int, green_size : int, blue_size : int): - ''' - Create a gamma ramp in the proper way that allows all adjustment - methods to read from and write to it without causing segmentation violation. - - @param red_size The size of the gamma ramp for the red channel - @param green_size The size of the gamma ramp for the green channel - @param blue_size The size of the gamma ramp for the blue channel - @return :(int){4}|int The tuple that describes the created data, `errno` on failure: - Element 1: The address of the gamma ramp structure - Element 2: The address of the gamma ramp for the red channel - Element 3: The address of the gamma ramp for the green channel - Element 4: The address of the gamma ramp for the blue channel - ''' - cdef void* allocation = malloc(sizeof(libgamma_gamma_ramps64_t)) - cdef libgamma_gamma_ramps64_t* item = allocation - cdef size_t red, green, blue - if item is NULL: - return int(errno) - item.red_size = red_size - item.green_size = green_size - item.blue_size = blue_size - if libgamma_gamma_ramps64_initialise(item) < 0: - return int(errno) - red = (item.red) - green = (item.green) - blue = (item.blue) - return (int(allocation), int(red), int(green), int(blue)) - - -def libgamma_native_gamma_ramps64_free(this : int): - ''' - Release resources that are held by a gamma ramp strcuture that - has been allocated by `libgamma_native_gamma_ramps64_create` or otherwise - created in the proper manner, as well as release the pointer - to the structure. - - @param this The gamma ramps. - ''' - cdef void* address = this - cdef libgamma_gamma_ramps64_t* item = address - libgamma_gamma_ramps64_free(item) - - -def libgamma_native_gamma_ramps64_get(this : int, index : int) -> int: - ''' - Read a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @return The value of the gamma ramp stop. - ''' - cdef void* address = this - cdef uint64_t* ramp = address - return int(ramp[index]) - - -def libgamma_native_gamma_ramps64_set(this : int, index : int, value : int): - ''' - Modify a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @param value The value of the gamma ramp stop. - ''' - cdef void* address = this - cdef uint64_t* ramp = address - ramp[index] = value - - - -def libgamma_native_gamma_rampsf_create(red_size : int, green_size : int, blue_size : int): - ''' - Create a gamma ramp in the proper way that allows all adjustment - methods to read from and write to it without causing segmentation violation. - - @param red_size The size of the gamma ramp for the red channel - @param green_size The size of the gamma ramp for the green channel - @param blue_size The size of the gamma ramp for the blue channel - @return :(int){4}|int The tuple that describes the created data, `errno` on failure: - Element 1: The address of the gamma ramp structure - Element 2: The address of the gamma ramp for the red channel - Element 3: The address of the gamma ramp for the green channel - Element 4: The address of the gamma ramp for the blue channel - ''' - cdef void* allocation = malloc(sizeof(libgamma_gamma_rampsf_t)) - cdef libgamma_gamma_rampsf_t* item = allocation - cdef size_t red, green, blue - if item is NULL: - return int(errno) - item.red_size = red_size - item.green_size = green_size - item.blue_size = blue_size - if libgamma_gamma_rampsf_initialise(item) < 0: - return int(errno) - red = (item.red) - green = (item.green) - blue = (item.blue) - return (int(allocation), int(red), int(green), int(blue)) - - -def libgamma_native_gamma_rampsf_free(this : int): - ''' - Release resources that are held by a gamma ramp strcuture that - has been allocated by `libgamma_native_gamma_rampsf_create` or otherwise - created in the proper manner, as well as release the pointer - to the structure. - - @param this The gamma ramps. - ''' - cdef void* address = this - cdef libgamma_gamma_rampsf_t* item = address - libgamma_gamma_rampsf_free(item) - - -def libgamma_native_gamma_rampsf_get(this : int, index : int) -> float: - ''' - Read a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @return The value of the gamma ramp stop. - ''' - cdef void* address = this - cdef float* ramp = address - return float(ramp[index]) - - -def libgamma_native_gamma_rampsf_set(this : int, index : int, value : float): - ''' - Modify a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @param value The value of the gamma ramp stop. - ''' - cdef void* address = this - cdef float* ramp = address - ramp[index] = value - - - -def libgamma_native_gamma_rampsd_create(red_size : int, green_size : int, blue_size : int): - ''' - Create a gamma ramp in the proper way that allows all adjustment - methods to read from and write to it without causing segmentation violation. - - @param red_size The size of the gamma ramp for the red channel - @param green_size The size of the gamma ramp for the green channel - @param blue_size The size of the gamma ramp for the blue channel - @return :(int){4}|int The tuple that describes the created data, `errno` on failure: - Element 1: The address of the gamma ramp structure - Element 2: The address of the gamma ramp for the red channel - Element 3: The address of the gamma ramp for the green channel - Element 4: The address of the gamma ramp for the blue channel - ''' - cdef void* allocation = malloc(sizeof(libgamma_gamma_rampsd_t)) - cdef libgamma_gamma_rampsd_t* item = allocation - cdef size_t red, green, blue - if item is NULL: - return int(errno) - item.red_size = red_size - item.green_size = green_size - item.blue_size = blue_size - if libgamma_gamma_rampsd_initialise(item) < 0: - return int(errno) - red = (item.red) - green = (item.green) - blue = (item.blue) - return (int(allocation), int(red), int(green), int(blue)) - - -def libgamma_native_gamma_rampsd_free(this : int): - ''' - Release resources that are held by a gamma ramp strcuture that - has been allocated by `libgamma_native_gamma_rampsd_create` or otherwise - created in the proper manner, as well as release the pointer - to the structure. - - @param this The gamma ramps. - ''' - cdef void* address = this - cdef libgamma_gamma_rampsd_t* item = address - libgamma_gamma_rampsd_free(item) - - -def libgamma_native_gamma_rampsd_get(this : int, index : int) -> float: - ''' - Read a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @return The value of the gamma ramp stop. - ''' - cdef void* address = this - cdef double* ramp = address - return float(ramp[index]) - - -def libgamma_native_gamma_rampsd_set(this : int, index : int, value : float): - ''' - Modify a stop in a gamma ramp. - - @param this The gamma ramp. - @param index The index of the gamma ramp stop. - @param value The value of the gamma ramp stop. - ''' - cdef void* address = this - cdef double* ramp = address - ramp[index] = value - diff --git a/src/test.py b/src/test.py deleted file mode 100755 index 58ed78e..0000000 --- a/src/test.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python3 -# -*- python -*- -''' -pylibgamma — Python 3 wrapper for libgamma -Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) - -This library 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 library 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 library. If not, see . -''' - -import libgamma -from time import sleep - - -method = libgamma.list_methods(0)[0] -assert libgamma.is_method_available(method) == True - -print('\033[1mMethod capabilities\033[m') -print(libgamma.method_capabilities(method).__dict__) -print() - -print('\033[1mMethod default site variable and default site\033[m') -print(repr(libgamma.method_default_site_variable(method))) -print(repr(libgamma.method_default_site(method))) -print() - -print('\033[1mUnhexing b"0123456789ABCDEF" and b"0123456789abcdef"\033[m') -print(repr(libgamma.unhex_edid('0123456789ABCDEF'))) -print(repr(libgamma.unhex_edid('0123456789abcdef'))) -print('\033[1mUnhexing and rehexing "0123456789abcdef"\033[m') -print(repr(libgamma.behex_edid(libgamma.unhex_edid('0123456789abcdef')))) -print(repr(libgamma.behex_edid_lowercase(libgamma.unhex_edid('0123456789abcdef')))) -print(repr(libgamma.behex_edid_uppercase(libgamma.unhex_edid('0123456789abcdef')))) -print() - -print('\033[1mPrinting required group ID, setting to 10, and reprinting\033[m') -print(libgamma.group.gid) -libgamma.group.gid = 10 -print(libgamma.group.gid) -print() - -print('\033[1mPrinting required group name, setting to "group", and reprinting\033[m') -print(repr(libgamma.group.name)) -libgamma.group.name = 'group' -print(repr(libgamma.group.name)) -print() - -print('\033[1mPrint description for errors: 0, ERRNO_SET and NO_SUCH_ADJUSTMENT_METHOD\033[m') -libgamma.perror('test', 0) -libgamma.perror('test', libgamma.LIBGAMMA_ERRNO_SET) -libgamma.perror('test', libgamma.LIBGAMMA_NO_SUCH_ADJUSTMENT_METHOD) -print() - -print('\033[1mGetting name and value of error NO_SUCH_SITE\033[m') -print(repr(libgamma.name_of_error(libgamma.LIBGAMMA_NO_SUCH_SITE))) -print(repr(libgamma.value_of_error('LIBGAMMA_NO_SUCH_SITE'))) -print(libgamma.LIBGAMMA_NO_SUCH_SITE) -print() - -print('\033[1mCreating errors: 1, 0, -1 and -2\033[m') -print(libgamma.create_error(1)) -print(libgamma.create_error(0)) -print(libgamma.create_error(-1)) -print(libgamma.create_error(-2)) -print() - -print('\033[1mGetting partition count, crtc count for partition 0, and info for crtc 0.0\033[m') -site = libgamma.Site(method) -print(site.partitions_available) -partition = libgamma.Partition(site, 0) -print(partition.crtcs_available) -crtc = libgamma.CRTC(partition, 0) -info = crtc.information(~0)[0] -print(info.__dict__) -print() - -ramp_sizes = (info.red_gamma_size, info.green_gamma_size, info.blue_gamma_size) -ramps = libgamma.GammaRamps(*ramp_sizes, depth = info.gamma_depth) -crtc.get_gamma(ramps) -print('\033[1mCurrent red gamma ramp\033[m') -print(list(ramps.red)) -print() -print('\033[1mCurrent green gamma ramp\033[m') -print(list(ramps.green)) -print() -print('\033[1mCurrent blue gamma ramp\033[m') -print(list(ramps.blue)) -print() - -saved_red = list(ramps.red) -saved_green = list(ramps.green) -saved_blue = list(ramps.blue) - -ramps.red[:] = list(map(lambda x : x // 2, saved_red)) -ramps.green[:] = list(map(lambda x : x // 2, saved_green)) -ramps.blue[:] = list(map(lambda x : x // 2, saved_blue)) - -crtc.set_gamma(ramps) - -sleep(1) - -ramps.red[:] = saved_red -ramps.green[:] = saved_green -ramps.blue[:] = saved_blue - -crtc.set_gamma(ramps) - -# If not done expressively, if in the root scope, -# we sometimes get ignored errors on exit -del site -del partition -del crtc -del ramps - diff --git a/test.py b/test.py new file mode 100755 index 0000000..5286c07 --- /dev/null +++ b/test.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python3 +# See LICENSE file for copyright and license details. +import libgamma +from time import sleep + + +method = libgamma.list_methods(0)[0] +assert libgamma.is_method_available(method) == True + +print('\033[1mMethod capabilities\033[m') +print(libgamma.method_capabilities(method).__dict__) +print() + +print('\033[1mMethod default site variable and default site\033[m') +print(repr(libgamma.method_default_site_variable(method))) +print(repr(libgamma.method_default_site(method))) +print() + +print('\033[1mUnhexing b"0123456789ABCDEF" and b"0123456789abcdef"\033[m') +print(repr(libgamma.unhex_edid('0123456789ABCDEF'))) +print(repr(libgamma.unhex_edid('0123456789abcdef'))) +print('\033[1mUnhexing and rehexing "0123456789abcdef"\033[m') +print(repr(libgamma.behex_edid(libgamma.unhex_edid('0123456789abcdef')))) +print(repr(libgamma.behex_edid_lowercase(libgamma.unhex_edid('0123456789abcdef')))) +print(repr(libgamma.behex_edid_uppercase(libgamma.unhex_edid('0123456789abcdef')))) +print() + +print('\033[1mPrinting required group ID, setting to 10, and reprinting\033[m') +print(libgamma.group.gid) +libgamma.group.gid = 10 +print(libgamma.group.gid) +print() + +print('\033[1mPrinting required group name, setting to "group", and reprinting\033[m') +print(repr(libgamma.group.name)) +libgamma.group.name = 'group' +print(repr(libgamma.group.name)) +print() + +print('\033[1mPrint description for errors: 0, ERRNO_SET and NO_SUCH_ADJUSTMENT_METHOD\033[m') +libgamma.perror('test', 0) +libgamma.perror('test', libgamma.LIBGAMMA_ERRNO_SET) +libgamma.perror('test', libgamma.LIBGAMMA_NO_SUCH_ADJUSTMENT_METHOD) +print() + +print('\033[1mGetting name and value of error NO_SUCH_SITE\033[m') +print(repr(libgamma.name_of_error(libgamma.LIBGAMMA_NO_SUCH_SITE))) +print(repr(libgamma.value_of_error('LIBGAMMA_NO_SUCH_SITE'))) +print(libgamma.LIBGAMMA_NO_SUCH_SITE) +print() + +print('\033[1mCreating errors: 1, 0, -1 and -2\033[m') +print(libgamma.create_error(1)) +print(libgamma.create_error(0)) +print(libgamma.create_error(-1)) +print(libgamma.create_error(-2)) +print() + +print('\033[1mGetting partition count, crtc count for partition 0, and info for crtc 0.0\033[m') +site = libgamma.Site(method) +print(site.partitions_available) +partition = libgamma.Partition(site, 0) +print(partition.crtcs_available) +crtc = libgamma.CRTC(partition, 0) +info = crtc.information(~0)[0] +print(info.__dict__) +print() + +ramp_sizes = (info.red_gamma_size, info.green_gamma_size, info.blue_gamma_size) +ramps = libgamma.GammaRamps(*ramp_sizes, depth = info.gamma_depth) +crtc.get_gamma(ramps) +print('\033[1mCurrent red gamma ramp\033[m') +print(list(ramps.red)) +print() +print('\033[1mCurrent green gamma ramp\033[m') +print(list(ramps.green)) +print() +print('\033[1mCurrent blue gamma ramp\033[m') +print(list(ramps.blue)) +print() + +saved_red = list(ramps.red) +saved_green = list(ramps.green) +saved_blue = list(ramps.blue) + +ramps.red[:] = list(map(lambda x : x // 2, saved_red)) +ramps.green[:] = list(map(lambda x : x // 2, saved_green)) +ramps.blue[:] = list(map(lambda x : x // 2, saved_blue)) + +crtc.set_gamma(ramps) + +sleep(1) + +ramps.red[:] = saved_red +ramps.green[:] = saved_green +ramps.blue[:] = saved_blue + +crtc.set_gamma(ramps) + +# If not done expressively, if in the root scope, +# we sometimes get ignored errors on exit +del site +del partition +del crtc +del ramps -- cgit v1.2.3-70-g09d2