├── .editorconfig ├── .gitignore ├── CHANGELOG.txt ├── Chocolatey ├── NegativeScreen.exe.gui ├── NegativeScreenX86.exe.gui ├── negativescreen.nuspec └── tools │ ├── LICENSE.txt │ └── VERIFICATION.txt ├── ClearType ├── 1 cleartype off.png ├── 1 cleartype on.png ├── 2 cleartype off.png ├── 2 cleartype on.png ├── 3 rgb.png └── 4 bgr.png ├── Icon.psd ├── LICENSE.txt ├── License.txt ├── NegativeScreen.sln ├── NegativeScreen ├── AboutBox.Designer.cs ├── AboutBox.cs ├── AlreadyRegisteredHotKeyException.cs ├── Api.cs ├── BuiltinMatrices.cs ├── Configuration.cs ├── ConfigurationParser.cs ├── Icon.ico ├── NativeMethods.cs ├── NativeStructures.cs ├── NegativeScreen.csproj ├── OverlayManager.Designer.cs ├── OverlayManager.cs ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx └── app.config ├── README.md ├── TODO.txt └── create-release.sh /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | 6 | [*.cs] 7 | indent_style = tab 8 | end_of_line = crlf 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | # DNX 42 | project.lock.json 43 | artifacts/ 44 | 45 | *_i.c 46 | *_p.c 47 | *_i.h 48 | *.ilk 49 | *.meta 50 | *.obj 51 | *.pch 52 | *.pdb 53 | *.pgc 54 | *.pgd 55 | *.rsp 56 | *.sbr 57 | *.tlb 58 | *.tli 59 | *.tlh 60 | *.tmp 61 | *.tmp_proj 62 | *.log 63 | *.vspscc 64 | *.vssscc 65 | .builds 66 | *.pidb 67 | *.svclog 68 | *.scc 69 | 70 | # Chutzpah Test files 71 | _Chutzpah* 72 | 73 | # Visual C++ cache files 74 | ipch/ 75 | *.aps 76 | *.ncb 77 | *.opensdf 78 | *.sdf 79 | *.cachefile 80 | 81 | # Visual Studio profiler 82 | *.psess 83 | *.vsp 84 | *.vspx 85 | 86 | # TFS 2012 Local Workspace 87 | $tf/ 88 | 89 | # Guidance Automation Toolkit 90 | *.gpState 91 | 92 | # ReSharper is a .NET coding add-in 93 | _ReSharper*/ 94 | *.[Rr]e[Ss]harper 95 | *.DotSettings.user 96 | 97 | # JustCode is a .NET coding add-in 98 | .JustCode 99 | 100 | # TeamCity is a build add-in 101 | _TeamCity* 102 | 103 | # DotCover is a Code Coverage Tool 104 | *.dotCover 105 | 106 | # NCrunch 107 | _NCrunch_* 108 | .*crunch*.local.xml 109 | 110 | # MightyMoose 111 | *.mm.* 112 | AutoTest.Net/ 113 | 114 | # Web workbench (sass) 115 | .sass-cache/ 116 | 117 | # Installshield output folder 118 | [Ee]xpress/ 119 | 120 | # DocProject is a documentation generator add-in 121 | DocProject/buildhelp/ 122 | DocProject/Help/*.HxT 123 | DocProject/Help/*.HxC 124 | DocProject/Help/*.hhc 125 | DocProject/Help/*.hhk 126 | DocProject/Help/*.hhp 127 | DocProject/Help/Html2 128 | DocProject/Help/html 129 | 130 | # Click-Once directory 131 | publish/ 132 | 133 | # Publish Web Output 134 | *.[Pp]ublish.xml 135 | *.azurePubxml 136 | ## TODO: Comment the next line if you want to checkin your 137 | ## web deploy settings but do note that will include unencrypted 138 | ## passwords 139 | #*.pubxml 140 | 141 | *.publishproj 142 | 143 | # NuGet Packages 144 | *.nupkg 145 | # The packages folder can be ignored because of Package Restore 146 | **/packages/* 147 | # except build/, which is used as an MSBuild target. 148 | !**/packages/build/ 149 | # Uncomment if necessary however generally it will be regenerated when needed 150 | #!**/packages/repositories.config 151 | 152 | # Windows Azure Build Output 153 | csx/ 154 | *.build.csdef 155 | 156 | # Windows Store app package directory 157 | AppPackages/ 158 | 159 | # Visual Studio cache files 160 | # files ending in .cache can be ignored 161 | *.[Cc]ache 162 | # but keep track of directories ending in .cache 163 | !*.[Cc]ache/ 164 | 165 | # Others 166 | ClientBin/ 167 | [Ss]tyle[Cc]op.* 168 | ~$* 169 | *~ 170 | *.dbmdl 171 | *.dbproj.schemaview 172 | *.pfx 173 | *.publishsettings 174 | node_modules/ 175 | orleans.codegen.cs 176 | 177 | # RIA/Silverlight projects 178 | Generated_Code/ 179 | 180 | # Backup & report files from converting an old project file 181 | # to a newer Visual Studio version. Backup files are not needed, 182 | # because we have git ;-) 183 | _UpgradeReport_Files/ 184 | Backup*/ 185 | UpgradeLog*.XML 186 | UpgradeLog*.htm 187 | 188 | # SQL Server files 189 | *.mdf 190 | *.ldf 191 | 192 | # Business Intelligence projects 193 | *.rdl.data 194 | *.bim.layout 195 | *.bim_*.settings 196 | 197 | # Microsoft Fakes 198 | FakesAssemblies/ 199 | 200 | # Node.js Tools for Visual Studio 201 | .ntvs_analysis.dat 202 | 203 | # Visual Studio 6 build log 204 | *.plg 205 | 206 | # Visual Studio 6 workspace options file 207 | *.opt 208 | 209 | # LightSwitch generated files 210 | GeneratedArtifacts/ 211 | _Pvt_Extensions/ 212 | ModelManifest.xml 213 | 214 | *.vcxproj.filters -------------------------------------------------------------------------------- /CHANGELOG.txt: -------------------------------------------------------------------------------- 1 | Version 2.6.1, 2021-04-10 2 | ------------------------ 3 | - [changed] target .NET 4.5 (see https://zerowidthjoiner.net/negativescreen#comment-534224) 4 | 5 | Version 2.6, 2018-12-05 6 | ------------------------ 7 | - [added] new matrices (color blindness simulation, and binary) added to the default configuration file 8 | - [fixed] color effect sometimes randomly activated by other running programs on the system 9 | 10 | Version 2.5, 2017-05-28 11 | ------------------------ 12 | - [fixed] when an instance is already running, enable its color effect instead of showing an unhelpful message about it 13 | - [fixed] no longer crash when trying to set a color effect while the Windows Magnifier color inversion is enabled 14 | - [added] a basic web api is now part of NegativeScreen! See the readme for more information 15 | - [added] new EnableApi configuration option, defaults to false 16 | - [added] new ApiListeningUri configuration option, defaults to listening on port 8990, localhost only 17 | - [added] new About window, available from the systray menu 18 | - [added] add a retro-compatible user-specific fallback location for the configuration file: 19 | - if the file "%AppData%/NegativeScreen/negativescreen.conf" exists, it will be used in priority. 20 | - if the "negativescreen.conf" file beside the executable cannot be modified, 21 | trying to edit the current configuration will result in a configuration in AppData being created. 22 | 23 | Version 2.4, 2014-11-30 24 | ------------------------ 25 | - [fixed] force the working directory to be the one of the executable (so the .conf file is found when starting from the cli) 26 | 27 | Version 2.3, 2014-03-28 28 | ------------------------ 29 | - [fixed] crash if more than one custom color effect is added without an associated hot key 30 | - [added] (re)added the ShowAeroWarning configuration option from the version 1.* 31 | - [added] check box next to the current color effect in the right click menu 32 | 33 | Version 2.2, 2013-02-17 34 | ------------------------ 35 | - [fixed] avoid crash if a hot key cannot be registered 36 | - [added] new ActiveOnStartup configuration option 37 | 38 | Version 2.1, 2012-12-22 39 | ------------------------ 40 | - [fixed] crash on Windows 8 due to inter-threads calls 41 | (this was not a problem on Windows 7) 42 | - [added] new MainLoopRefreshTime configuration option 43 | 44 | Version 2.0, 2012-12-14 45 | ------------------------ 46 | Major update: 47 | - reworked entirely 48 | - better performances 49 | - smooth transitions 50 | - graphic interface (minimal) 51 | - configuration file: 52 | - fine grained configuration 53 | - custom hotkeys 54 | - custom color effects 55 | 56 | Version 1.14, 2014-11-30 57 | ------------------------ 58 | - [fixed] force the working directory to be the one of the executable (so the .conf file is found when starting from the cli) 59 | 60 | Version 1.13, 2013-07-04 61 | ------------------------ 62 | - [added] implemented the configuration file for the version 1.* 63 | - [added] configuration option to disable the message warning about aero being disabled 64 | 65 | Version 1.12, 2012-12-14 66 | ------------------------ 67 | - [fixed] crash on Windows 8 68 | 69 | Version 1.11, 2012-06-26 70 | ------------------------ 71 | - [added] new red and negative red filters bound on F9 and F10 72 | 73 | Version 1.10, 2012-05-15 74 | ------------------------ 75 | - [fixed] infinite flickering on Vista (introduced in 1.8) 76 | 77 | Version 1.9, 2012-04-16 78 | ------------------------ 79 | - [fixed] stupid bug if the Windows taskbar is vertical 80 | 81 | Version 1.8, 2012-03-22 82 | ------------------------ 83 | - [fixed] execution is no longer prevented if aero is disabled (previous bug corrected) 84 | however, the performances will still be horrible 85 | 86 | Version 1.7, 2012-03-21 87 | ------------------------ 88 | - [fixed] works as expected when using custom DPI settings 89 | 90 | Version 1.6, 2012-02-27 91 | ------------------------ 92 | - [fixed] crash on X86 on launch 93 | - [fixed] prevent execution if aero is disabled 94 | (prevent undesirable behaviours: black screens, 100% CPU usage...) 95 | 96 | Version 1.5, 2012-02-16 97 | ------------------------ 98 | - [fixed] (internal) ColorMatrix implementation 99 | - [added] new feature: choice between 9 inversion modes 100 | (smart mode, etc... see readme for details) 101 | 102 | Version 1.4, 2012-02-09 103 | ------------------------ 104 | - [fixed] does not crash anymore on Windows Vista 105 | 106 | Version 1.3, 2012-02-01 107 | ------------------------ 108 | - [fixed] multi-screen should finally work! 109 | after a lot of tests and coding, I re-thought completely the architecture 110 | - [knownbug] in some screen configurations, if the primary screen if smaller than the other screen, 111 | the second larger screen has a black border at its bottom. 112 | It could be a bug in the Windows API... 113 | 114 | Version 1.2, 2011-09-18 115 | ------------------------ 116 | - [fixed] multi-screen support (again) : bug with main screen on the right 117 | 118 | Version 1.1, 2011-09-13 119 | ------------------------ 120 | - [fixed] multi-screen support 121 | - [fixed] when halted while paused, the application never stopped 122 | 123 | Version 1.0, 2011-09-06 124 | ------------------------ 125 | - Initial release -------------------------------------------------------------------------------- /Chocolatey/NegativeScreen.exe.gui: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlaily/NegativeScreen/4608df1669b2fcfede8f25a0c6d5407521d54f09/Chocolatey/NegativeScreen.exe.gui -------------------------------------------------------------------------------- /Chocolatey/NegativeScreenX86.exe.gui: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlaily/NegativeScreen/4608df1669b2fcfede8f25a0c6d5407521d54f09/Chocolatey/NegativeScreenX86.exe.gui -------------------------------------------------------------------------------- /Chocolatey/negativescreen.nuspec: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | negativescreen 26 | 27 | 28 | 29 | 2.6 30 | https://github.com/mlaily/NegativeScreen/blob/master/Chocolatey/negativescreen.nuspec 31 | 32 | Melvyn Laïly 33 | 34 | 35 | 36 | 37 | NegativeScreen 38 | Melvyn Laïly 39 | 40 | https://zerowidthjoiner.net/negativescreen 41 | https://zerowidthjoiner.net/Uploads/negativescreen/Icon256.png 42 | 2011-2018 Melvyn Laïly 43 | 44 | https://www.gnu.org/copyleft/gpl.html 45 | true 46 | https://github.com/mlaily/NegativeScreen 47 | 48 | 49 | https://github.com/mlaily/NegativeScreen/issues 50 | negativescreen tool utility negative accessibility 51 | NegativeScreen is a Windows application allowing you to invert your screen colors. 52 | NegativeScreen is a Windows application that allows you to invert your screen's colors. 53 | Appart from accessibility matters, this software is especially useful when you are surfing on the internet in a dark room, and the screen is dazzling you. 54 | 55 | The name "NegativeScreen" stuck, but you can now use it to apply any color effect that can be modeled as a color transformation matrix. 56 | 57 | https://zerowidthjoiner.net/Uploads/negativescreen/CHANGELOG.txt 58 | 59 | 60 | 61 | 69 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /Chocolatey/tools/VERIFICATION.txt: -------------------------------------------------------------------------------- 1 | VERIFICATION 2 | Verification is intended to assist the Chocolatey moderators and community 3 | in verifying that this package's contents are trustworthy. 4 | 5 | I (the creator of this package) am the author of the packaged software. 6 | 7 | If you want to verify the content of this package, you can compare it to the 8 | content of the https://zerowidthjoiner.net/Uploads/negativescreen/Binary.zip files 9 | published on my website. They are supposed to stay in sync. 10 | -------------------------------------------------------------------------------- /ClearType/1 cleartype off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlaily/NegativeScreen/4608df1669b2fcfede8f25a0c6d5407521d54f09/ClearType/1 cleartype off.png -------------------------------------------------------------------------------- /ClearType/1 cleartype on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlaily/NegativeScreen/4608df1669b2fcfede8f25a0c6d5407521d54f09/ClearType/1 cleartype on.png -------------------------------------------------------------------------------- /ClearType/2 cleartype off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlaily/NegativeScreen/4608df1669b2fcfede8f25a0c6d5407521d54f09/ClearType/2 cleartype off.png -------------------------------------------------------------------------------- /ClearType/2 cleartype on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlaily/NegativeScreen/4608df1669b2fcfede8f25a0c6d5407521d54f09/ClearType/2 cleartype on.png -------------------------------------------------------------------------------- /ClearType/3 rgb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlaily/NegativeScreen/4608df1669b2fcfede8f25a0c6d5407521d54f09/ClearType/3 rgb.png -------------------------------------------------------------------------------- /ClearType/4 bgr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlaily/NegativeScreen/4608df1669b2fcfede8f25a0c6d5407521d54f09/ClearType/4 bgr.png -------------------------------------------------------------------------------- /Icon.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlaily/NegativeScreen/4608df1669b2fcfede8f25a0c6d5407521d54f09/Icon.psd -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /NegativeScreen.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30110.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NegativeScreen", "NegativeScreen\NegativeScreen.csproj", "{D0472F56-4C64-4695-B62F-34CE6218D479}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {D0472F56-4C64-4695-B62F-34CE6218D479}.Debug|x64.ActiveCfg = Debug|x64 17 | {D0472F56-4C64-4695-B62F-34CE6218D479}.Debug|x64.Build.0 = Debug|x64 18 | {D0472F56-4C64-4695-B62F-34CE6218D479}.Debug|x86.ActiveCfg = Debug|x86 19 | {D0472F56-4C64-4695-B62F-34CE6218D479}.Debug|x86.Build.0 = Debug|x86 20 | {D0472F56-4C64-4695-B62F-34CE6218D479}.Release|x64.ActiveCfg = Release|x64 21 | {D0472F56-4C64-4695-B62F-34CE6218D479}.Release|x64.Build.0 = Release|x64 22 | {D0472F56-4C64-4695-B62F-34CE6218D479}.Release|x86.ActiveCfg = Release|x86 23 | {D0472F56-4C64-4695-B62F-34CE6218D479}.Release|x86.Build.0 = Release|x86 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /NegativeScreen/AboutBox.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace NegativeScreen 2 | { 3 | partial class AboutBox 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | protected override void Dispose(bool disposing) 14 | { 15 | if (disposing && (components != null)) 16 | { 17 | components.Dispose(); 18 | } 19 | base.Dispose(disposing); 20 | } 21 | 22 | #region Windows Form Designer generated code 23 | 24 | /// 25 | /// Required method for Designer support - do not modify 26 | /// the contents of this method with the code editor. 27 | /// 28 | private void InitializeComponent() 29 | { 30 | this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); 31 | this.pictureBox1 = new System.Windows.Forms.PictureBox(); 32 | this.labelProductName = new System.Windows.Forms.RichTextBox(); 33 | this.labelVersion = new System.Windows.Forms.RichTextBox(); 34 | this.labelCopyright = new System.Windows.Forms.RichTextBox(); 35 | this.textBoxDescription = new System.Windows.Forms.RichTextBox(); 36 | this.okButton = new System.Windows.Forms.Button(); 37 | this.tableLayoutPanel.SuspendLayout(); 38 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); 39 | this.SuspendLayout(); 40 | // 41 | // tableLayoutPanel 42 | // 43 | this.tableLayoutPanel.ColumnCount = 2; 44 | this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 70F)); 45 | this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); 46 | this.tableLayoutPanel.Controls.Add(this.pictureBox1, 0, 0); 47 | this.tableLayoutPanel.Controls.Add(this.labelProductName, 1, 1); 48 | this.tableLayoutPanel.Controls.Add(this.labelVersion, 1, 2); 49 | this.tableLayoutPanel.Controls.Add(this.labelCopyright, 0, 3); 50 | this.tableLayoutPanel.Controls.Add(this.textBoxDescription, 0, 4); 51 | this.tableLayoutPanel.Controls.Add(this.okButton, 1, 5); 52 | this.tableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill; 53 | this.tableLayoutPanel.Location = new System.Drawing.Point(9, 9); 54 | this.tableLayoutPanel.Name = "tableLayoutPanel"; 55 | this.tableLayoutPanel.RowCount = 6; 56 | this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 5F)); 57 | this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 13.13956F)); 58 | this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 13.13956F)); 59 | this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 12.98766F)); 60 | this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50.53677F)); 61 | this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10.19646F)); 62 | this.tableLayoutPanel.Size = new System.Drawing.Size(483, 278); 63 | this.tableLayoutPanel.TabIndex = 0; 64 | // 65 | // pictureBox1 66 | // 67 | this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill; 68 | this.pictureBox1.Location = new System.Drawing.Point(3, 3); 69 | this.pictureBox1.Name = "pictureBox1"; 70 | this.tableLayoutPanel.SetRowSpan(this.pictureBox1, 3); 71 | this.pictureBox1.Size = new System.Drawing.Size(64, 69); 72 | this.pictureBox1.TabIndex = 1; 73 | this.pictureBox1.TabStop = false; 74 | // 75 | // labelProductName 76 | // 77 | this.labelProductName.BorderStyle = System.Windows.Forms.BorderStyle.None; 78 | this.labelProductName.Dock = System.Windows.Forms.DockStyle.Fill; 79 | this.labelProductName.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 80 | this.labelProductName.Location = new System.Drawing.Point(73, 8); 81 | this.labelProductName.Multiline = false; 82 | this.labelProductName.Name = "labelProductName"; 83 | this.labelProductName.ReadOnly = true; 84 | this.labelProductName.Size = new System.Drawing.Size(407, 29); 85 | this.labelProductName.TabIndex = 19; 86 | this.labelProductName.Text = "Product Name"; 87 | // 88 | // labelVersion 89 | // 90 | this.labelVersion.BorderStyle = System.Windows.Forms.BorderStyle.None; 91 | this.labelVersion.Dock = System.Windows.Forms.DockStyle.Fill; 92 | this.labelVersion.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 93 | this.labelVersion.Location = new System.Drawing.Point(73, 43); 94 | this.labelVersion.Multiline = false; 95 | this.labelVersion.Name = "labelVersion"; 96 | this.labelVersion.ReadOnly = true; 97 | this.labelVersion.Size = new System.Drawing.Size(407, 29); 98 | this.labelVersion.TabIndex = 0; 99 | this.labelVersion.Text = "Version"; 100 | // 101 | // labelCopyright 102 | // 103 | this.labelCopyright.BorderStyle = System.Windows.Forms.BorderStyle.None; 104 | this.tableLayoutPanel.SetColumnSpan(this.labelCopyright, 2); 105 | this.labelCopyright.Dock = System.Windows.Forms.DockStyle.Fill; 106 | this.labelCopyright.Location = new System.Drawing.Point(3, 78); 107 | this.labelCopyright.Multiline = false; 108 | this.labelCopyright.Name = "labelCopyright"; 109 | this.labelCopyright.ReadOnly = true; 110 | this.labelCopyright.Size = new System.Drawing.Size(477, 29); 111 | this.labelCopyright.TabIndex = 21; 112 | this.labelCopyright.Text = "Copyright"; 113 | // 114 | // textBoxDescription 115 | // 116 | this.textBoxDescription.BorderStyle = System.Windows.Forms.BorderStyle.None; 117 | this.tableLayoutPanel.SetColumnSpan(this.textBoxDescription, 2); 118 | this.textBoxDescription.Dock = System.Windows.Forms.DockStyle.Fill; 119 | this.textBoxDescription.Location = new System.Drawing.Point(3, 113); 120 | this.textBoxDescription.Name = "textBoxDescription"; 121 | this.textBoxDescription.ReadOnly = true; 122 | this.textBoxDescription.Size = new System.Drawing.Size(477, 131); 123 | this.textBoxDescription.TabIndex = 23; 124 | this.textBoxDescription.TabStop = false; 125 | this.textBoxDescription.Text = "Description"; 126 | this.textBoxDescription.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.textBoxDescription_LinkClicked); 127 | // 128 | // okButton 129 | // 130 | this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 131 | this.okButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; 132 | this.okButton.Name = "okButton"; 133 | this.okButton.TabIndex = 24; 134 | this.okButton.Text = "&OK"; 135 | // 136 | // AboutBox 137 | // 138 | this.AcceptButton = this.okButton; 139 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 140 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 141 | this.ClientSize = new System.Drawing.Size(501, 296); 142 | this.Controls.Add(this.tableLayoutPanel); 143 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; 144 | this.MaximizeBox = false; 145 | this.MinimizeBox = false; 146 | this.Name = "AboutBox"; 147 | this.Padding = new System.Windows.Forms.Padding(9); 148 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 149 | this.Text = "AboutBox1"; 150 | this.tableLayoutPanel.ResumeLayout(false); 151 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); 152 | this.ResumeLayout(false); 153 | 154 | } 155 | 156 | #endregion 157 | 158 | private System.Windows.Forms.TableLayoutPanel tableLayoutPanel; 159 | private System.Windows.Forms.RichTextBox labelProductName; 160 | private System.Windows.Forms.RichTextBox labelVersion; 161 | private System.Windows.Forms.RichTextBox labelCopyright; 162 | private System.Windows.Forms.RichTextBox textBoxDescription; 163 | private System.Windows.Forms.Button okButton; 164 | private System.Windows.Forms.PictureBox pictureBox1; 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /NegativeScreen/AboutBox.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Diagnostics; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Reflection; 8 | using System.Windows.Forms; 9 | 10 | namespace NegativeScreen 11 | { 12 | partial class AboutBox : Form 13 | { 14 | public AboutBox() 15 | { 16 | InitializeComponent(); 17 | 18 | this.Icon = Properties.Resources.Icon; 19 | this.pictureBox1.Image = Properties.Resources.Icon.ToBitmap(); 20 | 21 | this.Text = String.Format("About {0}", AssemblyTitle); 22 | this.labelProductName.Text = AssemblyProduct; 23 | this.labelVersion.Text = String.Format("Version {0}", AssemblyVersion); 24 | this.labelCopyright.Text = AssemblyCopyright; 25 | this.textBoxDescription.Text = AssemblyDescription; 26 | } 27 | 28 | #region Assembly Attribute Accessors 29 | 30 | public string AssemblyTitle 31 | { 32 | get 33 | { 34 | object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false); 35 | if (attributes.Length > 0) 36 | { 37 | AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0]; 38 | if (titleAttribute.Title != "") 39 | { 40 | return titleAttribute.Title; 41 | } 42 | } 43 | return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase); 44 | } 45 | } 46 | 47 | public string AssemblyVersion 48 | { 49 | get 50 | { 51 | return Assembly.GetExecutingAssembly().GetName().Version.ToString(); 52 | } 53 | } 54 | 55 | public string AssemblyDescription 56 | { 57 | get 58 | { 59 | object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false); 60 | if (attributes.Length == 0) 61 | { 62 | return ""; 63 | } 64 | return ((AssemblyDescriptionAttribute)attributes[0]).Description; 65 | } 66 | } 67 | 68 | public string AssemblyProduct 69 | { 70 | get 71 | { 72 | object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false); 73 | if (attributes.Length == 0) 74 | { 75 | return ""; 76 | } 77 | return ((AssemblyProductAttribute)attributes[0]).Product; 78 | } 79 | } 80 | 81 | public string AssemblyCopyright 82 | { 83 | get 84 | { 85 | object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); 86 | if (attributes.Length == 0) 87 | { 88 | return ""; 89 | } 90 | return ((AssemblyCopyrightAttribute)attributes[0]).Copyright; 91 | } 92 | } 93 | 94 | public string AssemblyCompany 95 | { 96 | get 97 | { 98 | object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false); 99 | if (attributes.Length == 0) 100 | { 101 | return ""; 102 | } 103 | return ((AssemblyCompanyAttribute)attributes[0]).Company; 104 | } 105 | } 106 | #endregion 107 | 108 | private void textBoxDescription_LinkClicked(object sender, LinkClickedEventArgs e) 109 | { 110 | Process.Start(new ProcessStartInfo(e.LinkText) { UseShellExecute = true }); 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /NegativeScreen/AlreadyRegisteredHotKeyException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Windows.Forms; 6 | 7 | namespace NegativeScreen 8 | { 9 | [Serializable] 10 | class AlreadyRegisteredHotKeyException : Exception 11 | { 12 | public HotKey HotKey { get; protected set; } 13 | 14 | public AlreadyRegisteredHotKeyException(HotKey hotkey, Exception innerException = null) 15 | : base(string.Format("Unable to register \"{0}\", this hot key is already registered.", hotkey), innerException) 16 | { 17 | HotKey = hotkey; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /NegativeScreen/Api.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2017 Melvyn Laïly 2 | // https://zerowidthjoiner.net 3 | 4 | // This file is part of NegativeScreen. 5 | 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | using System; 20 | using System.Collections.Generic; 21 | using System.Diagnostics; 22 | using System.IO; 23 | using System.Linq; 24 | using System.Net; 25 | using System.Text; 26 | using System.Threading; 27 | using System.Windows.Forms; 28 | 29 | namespace NegativeScreen 30 | { 31 | class Api : IDisposable 32 | { 33 | private OverlayManager _overlayManager; 34 | private HttpListener _listener; 35 | public Api(OverlayManager overlayManager) 36 | { 37 | _overlayManager = overlayManager; 38 | _listener = new HttpListener() { IgnoreWriteExceptions = true }; 39 | _listener.Prefixes.Add(Configuration.Current.ApiListeningUri); 40 | try 41 | { 42 | _listener.Start(); 43 | } 44 | catch (HttpListenerException ex) 45 | { 46 | overlayManager.ShowBalloonTip(4000, "Warning", "Unable to start the api!\n" + ex.Message, ToolTipIcon.Warning); 47 | return; 48 | } 49 | 50 | Thread t = new Thread(ThreadLoop) { Name = "Api Listener Thread" }; 51 | t.Start(); 52 | } 53 | 54 | private void ThreadLoop() 55 | { 56 | int previousErrorCount = 0; 57 | const int maxSuccessiveErrorCount = 10; 58 | while (_listener.IsListening) 59 | { 60 | try 61 | { 62 | var context = _listener.GetContext(); 63 | if (context.Request.HttpMethod == "POST") 64 | { 65 | const int maxRead = 1024; 66 | byte[] buffer = new byte[maxRead]; 67 | var read = context.Request.InputStream.Read(buffer, 0, maxRead); 68 | string body = Encoding.UTF8.GetString(buffer, 0, read); 69 | switch (body) 70 | { 71 | case "TOGGLE": 72 | _overlayManager.Toggle(); 73 | WriteResponse(context.Response, "Ok."); 74 | break; 75 | case "ENABLE": 76 | _overlayManager.Enable(); 77 | WriteResponse(context.Response, "Ok."); 78 | break; 79 | case "DISABLE": 80 | _overlayManager.Disable(); 81 | WriteResponse(context.Response, "Ok."); 82 | break; 83 | default: 84 | const string setEffectCommand = "SET "; 85 | if (body.StartsWith(setEffectCommand)) 86 | { 87 | var effectName = body.Substring(setEffectCommand.Length); 88 | var effectExists = _overlayManager.TrySetColorEffectByName(effectName); 89 | if (effectExists) 90 | { 91 | WriteResponse(context.Response, "Ok."); 92 | } 93 | else 94 | { 95 | WriteResponse(context.Response, "Effect not found."); 96 | } 97 | break; 98 | } 99 | else 100 | { 101 | WriteResponse(context.Response, "Unrecognized command."); 102 | } 103 | break; 104 | } 105 | } 106 | else 107 | { 108 | WriteResponse(context.Response, $"NegativeScreen {Application.ProductVersion}."); 109 | } 110 | context.Response.Close(); 111 | previousErrorCount = 0; // Reset the error count upon successful request. 112 | } 113 | catch 114 | { 115 | #if DEBUG 116 | Debugger.Break(); 117 | #endif 118 | previousErrorCount++; 119 | if (previousErrorCount >= maxSuccessiveErrorCount) 120 | { 121 | // Something is wrong, take the api down. 122 | Exit(); 123 | } 124 | } 125 | } 126 | } 127 | 128 | private void WriteResponse(HttpListenerResponse response, string body) 129 | { 130 | response.KeepAlive = false; 131 | response.SendChunked = false; 132 | var buffer = Encoding.UTF8.GetBytes($"{body}\r\n"); 133 | response.ContentLength64 = buffer.Length; 134 | response.OutputStream.Write(buffer, 0, buffer.Length); 135 | response.OutputStream.Close(); 136 | } 137 | 138 | 139 | public void Exit() 140 | { 141 | _listener.Close(); 142 | } 143 | 144 | public void Dispose() 145 | { 146 | Exit(); 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /NegativeScreen/BuiltinMatrices.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2017 Melvyn Laïly 2 | // https://zerowidthjoiner.net 3 | 4 | // This file is part of NegativeScreen. 5 | 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | using System; 20 | using System.Collections.Generic; 21 | using System.Text; 22 | using System.Runtime.InteropServices; 23 | 24 | namespace NegativeScreen 25 | { 26 | /// 27 | /// Store various built in ColorMatrix 28 | /// 29 | public static class BuiltinMatrices 30 | { 31 | /// 32 | /// no color transformation 33 | /// 34 | public static float[,] Identity { get; } 35 | /// 36 | /// simple colors transformations 37 | /// 38 | public static float[,] Negative { get; } 39 | public static float[,] GrayScale { get; } 40 | public static float[,] Sepia { get; } 41 | public static float[,] Red { get; } 42 | public static float[,] HueShift180 { get; } 43 | 44 | public static float[,] NegativeGrayScale { get; } 45 | public static float[,] NegativeSepia { get; } 46 | public static float[,] NegativeRed { get; } 47 | 48 | /// 49 | /// theoretical optimal transfomation (but ugly desaturated pure colors due to "overflows"...) 50 | /// Many thanks to Tom MacLeod who gave me the idea for these inversion modes 51 | /// 52 | public static float[,] NegativeHueShift180 { get; } 53 | /// 54 | /// high saturation, good pure colors 55 | /// 56 | public static float[,] NegativeHueShift180Variation1 { get; } 57 | /// 58 | /// overall desaturated, yellows and blue plain bad. actually relaxing and very usable 59 | /// 60 | public static float[,] NegativeHueShift180Variation2 { get; } 61 | /// 62 | /// high saturation. yellows and blues plain bad. actually quite readable 63 | /// 64 | public static float[,] NegativeHueShift180Variation3 { get; } 65 | /// 66 | /// not so readable, good colors (CMY colors a bit desaturated, still more saturated than normal) 67 | /// 68 | public static float[,] NegativeHueShift180Variation4 { get; } 69 | 70 | static BuiltinMatrices() 71 | { 72 | Identity = new float[,] { 73 | { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f }, 74 | { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f }, 75 | { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f }, 76 | { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }, 77 | { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } 78 | }; 79 | Negative = new float[,] { 80 | { -1.0f, 0.0f, 0.0f, 0.0f, 0.0f }, 81 | { 0.0f, -1.0f, 0.0f, 0.0f, 0.0f }, 82 | { 0.0f, 0.0f, -1.0f, 0.0f, 0.0f }, 83 | { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }, 84 | { 1.0f, 1.0f, 1.0f, 0.0f, 1.0f } 85 | }; 86 | GrayScale = new float[,] { 87 | { 0.3f, 0.3f, 0.3f, 0.0f, 0.0f }, 88 | { 0.6f, 0.6f, 0.6f, 0.0f, 0.0f }, 89 | { 0.1f, 0.1f, 0.1f, 0.0f, 0.0f }, 90 | { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }, 91 | { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } 92 | }; 93 | NegativeGrayScale = Multiply(Negative, GrayScale); 94 | Red = new float[,] { 95 | { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f }, 96 | { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }, 97 | { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }, 98 | { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }, 99 | { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } 100 | }; 101 | Red = Multiply(GrayScale, Red); 102 | NegativeRed = Multiply(NegativeGrayScale, Red); 103 | Sepia = new float[,] { 104 | { .393f, .349f, .272f, 0.0f, 0.0f}, 105 | { .769f, .686f, .534f, 0.0f, 0.0f}, 106 | { .189f, .168f, .131f, 0.0f, 0.0f}, 107 | { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f}, 108 | { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f} 109 | }; 110 | NegativeSepia = Multiply(Negative, Sepia); 111 | HueShift180 = new float[,] { 112 | { -0.3333333f, 0.6666667f, 0.6666667f, 0.0f, 0.0f }, 113 | { 0.6666667f, -0.3333333f, 0.6666667f, 0.0f, 0.0f }, 114 | { 0.6666667f, 0.6666667f, -0.3333333f, 0.0f, 0.0f }, 115 | { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }, 116 | { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } 117 | }; 118 | NegativeHueShift180 = Multiply(Negative, HueShift180); 119 | NegativeHueShift180Variation1 = new float[,] { 120 | // most simple working method for shifting hue 180deg. 121 | { 1.0f, -1.0f, -1.0f, 0.0f, 0.0f }, 122 | { -1.0f, 1.0f, -1.0f, 0.0f, 0.0f }, 123 | { -1.0f, -1.0f, 1.0f, 0.0f, 0.0f }, 124 | { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }, 125 | { 1.0f, 1.0f, 1.0f, 0.0f, 1.0f } 126 | }; 127 | NegativeHueShift180Variation2 = new float[,] { 128 | // generated with QColorMatrix http://www.codeguru.com/Cpp/G-M/gdi/gdi/article.php/c3667 129 | { 0.39f, -0.62f, -0.62f, 0.0f, 0.0f }, 130 | { -1.21f, -0.22f, -1.22f, 0.0f, 0.0f }, 131 | { -0.16f, -0.16f, 0.84f, 0.0f, 0.0f }, 132 | { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }, 133 | { 1.0f, 1.0f, 1.0f, 0.0f, 1.0f } 134 | }; 135 | NegativeHueShift180Variation3 = new float[,] { 136 | { 1.089508f, -0.9326327f, -0.932633042f, 0.0f, 0.0f }, 137 | { -1.81771779f, 0.1683074f, -1.84169245f, 0.0f, 0.0f }, 138 | { -0.244589478f, -0.247815639f, 1.7621845f, 0.0f, 0.0f }, 139 | { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }, 140 | { 1.0f, 1.0f, 1.0f, 0.0f, 1.0f } 141 | }; 142 | NegativeHueShift180Variation4 = new float[,] { 143 | { 0.50f, -0.78f, -0.78f, 0.0f, 0.0f }, 144 | { -0.56f, 0.72f, -0.56f, 0.0f, 0.0f }, 145 | { -0.94f, -0.94f, 0.34f, 0.0f, 0.0f }, 146 | { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }, 147 | { 1.0f, 1.0f, 1.0f, 0.0f, 1.0f } 148 | }; 149 | } 150 | 151 | private static string MatrixToString(float[,] matrix) 152 | { 153 | int maxDecimal = 0; 154 | foreach (var item in matrix) 155 | { 156 | string toString = item.ToString("0.#######", System.Globalization.NumberFormatInfo.InvariantInfo); 157 | int indexOfDot = toString.IndexOf('.'); 158 | int currentMax = indexOfDot >= 0 ? toString.Length - indexOfDot - 1 : 0; 159 | if (currentMax > maxDecimal) 160 | { 161 | maxDecimal = currentMax; 162 | } 163 | } 164 | string format = "0." + new string('0', maxDecimal); 165 | 166 | StringBuilder sb = new StringBuilder(); 167 | for (int i = 0; i < matrix.GetLength(0); i++) 168 | { 169 | sb.Append("{ "); 170 | for (int j = 0; j < matrix.GetLength(1); j++) 171 | { 172 | if (matrix[i, j] >= 0) 173 | { 174 | // align negative signs 175 | sb.Append(" "); 176 | } 177 | sb.Append(matrix[i, j].ToString(format, System.Globalization.NumberFormatInfo.InvariantInfo)); 178 | if (j < matrix.GetLength(1) - 1) 179 | { 180 | sb.Append(", "); 181 | } 182 | } 183 | sb.Append(" }\n"); 184 | } 185 | return sb.ToString(); 186 | } 187 | 188 | public static float[,] Multiply(float[,] a, float[,] b) 189 | { 190 | if (a.GetLength(1) != b.GetLength(0)) 191 | { 192 | throw new Exception("a.GetLength(1) != b.GetLength(0)"); 193 | } 194 | float[,] c = new float[a.GetLength(0), b.GetLength(1)]; 195 | for (int i = 0; i < c.GetLength(0); i++) 196 | { 197 | for (int j = 0; j < c.GetLength(1); j++) 198 | { 199 | for (int k = 0; k < a.GetLength(1); k++) // k transitions = Interpolate(fromMatrix, toMatrix); 221 | foreach (float[,] item in transitions) 222 | { 223 | ChangeColorEffect(item); 224 | System.Threading.Thread.Sleep(timeBetweenFrames); 225 | System.Windows.Forms.Application.DoEvents(); 226 | } 227 | } 228 | 229 | public static float[,] MoreBlue(float[,] colorMatrix) 230 | { 231 | float[,] temp = (float[,])colorMatrix.Clone(); 232 | temp[2, 4] += 0.1f;//or remove 0.1 off the red 233 | return temp; 234 | } 235 | 236 | public static float[,] MoreGreen(float[,] colorMatrix) 237 | { 238 | float[,] temp = (float[,])colorMatrix.Clone(); 239 | temp[1, 4] += 0.1f; 240 | return temp; 241 | } 242 | 243 | public static float[,] MoreRed(float[,] colorMatrix) 244 | { 245 | float[,] temp = (float[,])colorMatrix.Clone(); 246 | temp[0, 4] += 0.1f; 247 | return temp; 248 | } 249 | 250 | public static List Interpolate(float[,] A, float[,] B) 251 | { 252 | const int STEPS = 10; 253 | const int SIZE = 5; 254 | 255 | if (A.GetLength(0) != SIZE || 256 | A.GetLength(1) != SIZE || 257 | B.GetLength(0) != SIZE || 258 | B.GetLength(1) != SIZE) 259 | { 260 | throw new ArgumentException(); 261 | } 262 | 263 | List result = new List(STEPS); 264 | 265 | for (int i = 0; i < STEPS; i++) 266 | { 267 | result.Add(new float[SIZE, SIZE]); 268 | 269 | for (int x = 0; x < SIZE; x++) 270 | { 271 | for (int y = 0; y < SIZE; y++) 272 | { 273 | // f(x)=ya+(x-xa)*(yb-ya)/(xb-xa) 274 | // calculate 10 steps, from 1 to 10 (we don't need 0, as we start from there) 275 | result[i][x, y] = A[x, y] + (i + 1/*-0*/) * (B[x, y] - A[x, y]) / (STEPS/*-0*/); 276 | } 277 | } 278 | } 279 | 280 | return result; 281 | } 282 | } 283 | 284 | 285 | [Serializable] 286 | public class CannotChangeColorEffectException : Exception 287 | { 288 | public CannotChangeColorEffectException() { } 289 | public CannotChangeColorEffectException(string message) : base(message) { } 290 | public CannotChangeColorEffectException(string message, Exception inner) : base(message, inner) { } 291 | protected CannotChangeColorEffectException( 292 | System.Runtime.Serialization.SerializationInfo info, 293 | System.Runtime.Serialization.StreamingContext context) : base(info, context) 294 | { } 295 | } 296 | } 297 | -------------------------------------------------------------------------------- /NegativeScreen/Configuration.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2017 Melvyn Laïly 2 | // https://zerowidthjoiner.net 3 | 4 | // This file is part of NegativeScreen. 5 | 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | using System; 20 | using System.Collections.Generic; 21 | using System.Text; 22 | using System.Windows.Forms; 23 | using System.Linq; 24 | using System.IO; 25 | using System.Diagnostics; 26 | using System.Security.Permissions; 27 | 28 | namespace NegativeScreen 29 | { 30 | class Configuration : IConfigurable 31 | { 32 | public string WorkingDirectoryConfigurationFileName { get; } = 33 | Path.Combine(Environment.CurrentDirectory, "negativescreen.conf"); 34 | public string AppDataConfigurationFileName { get; } = 35 | Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "NegativeScreen/negativescreen.conf"); 36 | public ConfigurationLocation Source { get; private set; } 37 | 38 | #region Default configuration 39 | public const string DefaultConfiguration = 40 | @"# comments: if the character '#' is found, the rest of the line is ignored. 41 | # quotes: allow to place a '#' inside a value. they do not appear in the final result. 42 | # i.e. blah=""hello #1!"" will create a parameter blah with a value of: hello #1! 43 | # To place a quotation mark inside quotes, double it. 44 | # i.e. blah=""hello"""""" will create a parameter blah with a value of: hello"" 45 | 46 | #Predefined keys 47 | # You can use the following modifiers: alt, ctrl, shift, win 48 | # and a key from http://msdn.microsoft.com/en-us/library/system.windows.forms.keys%28v=vs.71%29.aspx 49 | # You can either use its textual representation, or its numerical value. 50 | # WARNING: if the key is not valid, the program will probably crash... 51 | 52 | Toggle=win+alt+N 53 | Exit=win+alt+H 54 | 55 | SmoothTransitions=true 56 | SmoothToggles=true 57 | 58 | # in miliseconds 59 | MainLoopRefreshTime=100 60 | 61 | InitialColorEffect=""Smart Inversion"" 62 | 63 | ActiveOnStartup=true 64 | 65 | ShowAeroWarning=true 66 | 67 | EnableApi=false 68 | # A URI prefix string is composed of a scheme (http), a host, an optional port, and an optional path. The trailing slash is mandatory. 69 | # To specify that the HttpListener accepts all requests sent to a port, replace the host element with the ""+"" character: ""https://+:8080"". 70 | # More information on listening prefixes can be found here: https://msdn.microsoft.com/en-us/library/system.net.httplistener%28v=vs.110%29.aspx 71 | # Please note setting a host other than localhost will require admin privileges. 72 | # If you do so, also remember to add an exception to your firewall. 73 | ApiListeningUri=http://localhost:8990/ 74 | 75 | # Matrices definitions 76 | # The left hand is used as a description, while the right hand is broken down in two parts: 77 | # - the hot key combination, followed by a new line, (this part is optional) 78 | # - the matrix definition, with or without new lines between rows. 79 | # The matrices must have 5 rows and 5 columns, 80 | # each line between curved brackets, 81 | # the elements separated by commas. 82 | # The decimal separator is a dot. 83 | 84 | # I'm not too keen on the maths, so maybe I'm missing some things, 85 | # but here is my basic understanding of what does what in a color matrix, when applied to a color vector: 86 | # r*=x g+=x*r b+=x*r a+=x*r 0 87 | # r+=x*g g*=x b+=x*g a+=x*g 0 88 | # r+=x*b g+=x*b b*=x a+=x*b 0 89 | # r+=x*a g+=x*a b+=x*a a*=x 0 90 | # r+=x g+=x b+=x a+=x 1 91 | 92 | # where x is the value in the matrix. 93 | 94 | Simple Inversion=win+alt+F1 95 | { -1, 0, 0, 0, 0 } 96 | { 0, -1, 0, 0, 0 } 97 | { 0, 0, -1, 0, 0 } 98 | { 0, 0, 0, 1, 0 } 99 | { 1, 1, 1, 0, 1 } 100 | 101 | # Theoretical optimal transfomation (but ugly desaturated pure colors due to ""overflows""...) 102 | # Many thanks to Tom MacLeod who gave me the idea for these inversion modes. 103 | Smart Inversion=win+alt+F2 104 | { 0.3333333, -0.6666667, -0.6666667, 0.0000000, 0.0000000 } 105 | { -0.6666667, 0.3333333, -0.6666667, 0.0000000, 0.0000000 } 106 | { -0.6666667, -0.6666667, 0.3333333, 0.0000000, 0.0000000 } 107 | { 0.0000000, 0.0000000, 0.0000000, 1.0000000, 0.0000000 } 108 | { 1.0000000, 1.0000000, 1.0000000, 0.0000000, 1.0000000 } 109 | 110 | # High saturation, good pure colors. 111 | Smart Inversion Alt 1=win+alt+F3 112 | { 1, -1, -1, 0, 0 } 113 | { -1, 1, -1, 0, 0 } 114 | { -1, -1, 1, 0, 0 } 115 | { 0, 0, 0, 1, 0 } 116 | { 1, 1, 1, 0, 1 } 117 | 118 | # Overall desaturated, yellows and blue plain bad. actually relaxing and very usable. 119 | Smart Inversion Alt 2=win+alt+F4 120 | { 0.39, -0.62, -0.62, 0.00, 0.00 } 121 | { -1.21, -0.22, -1.22, 0.00, 0.00 } 122 | { -0.16, -0.16, 0.84, 0.00, 0.00 } 123 | { 0.00, 0.00, 0.00, 1.00, 0.00 } 124 | { 1.00, 1.00, 1.00, 0.00, 1.00 } 125 | 126 | # High saturation. yellows and blues plain bad. actually quite readable. 127 | Smart Inversion Alt 3=win+alt+F5 128 | { 1.0895080, -0.9326327, -0.9326330, 0.0000000, 0.0000000 } 129 | { -1.8177180, 0.1683074, -1.8416920, 0.0000000, 0.0000000 } 130 | { -0.2445895, -0.2478156, 1.7621850, 0.0000000, 0.0000000 } 131 | { 0.0000000, 0.0000000, 0.0000000, 1.0000000, 0.0000000 } 132 | { 1.0000000, 1.0000000, 1.0000000, 0.0000000, 1.0000000 } 133 | 134 | # Not so readable, good colors (CMY colors a bit desaturated, still more saturated than normal). 135 | Smart Inversion Alt 4=win+alt+F6 136 | { 0.50, -0.78, -0.78, 0.00, 0.00 } 137 | { -0.56, 0.72, -0.56, 0.00, 0.00 } 138 | { -0.94, -0.94, 0.34, 0.00, 0.00 } 139 | { 0.00, 0.00, 0.00, 1.00, 0.00 } 140 | { 1.00, 1.00, 1.00, 0.00, 1.00 } 141 | 142 | Negative Sepia=win+alt+F7 143 | { -0.393, -0.349, -0.272, 0.000, 0.000 } 144 | { -0.769, -0.686, -0.534, 0.000, 0.000 } 145 | { -0.189, -0.168, -0.131, 0.000, 0.000 } 146 | { 0.000, 0.000, 0.000, 1.000, 0.000 } 147 | { 1.351, 1.203, 0.937, 0.000, 1.000 } 148 | 149 | Negative Grayscale=win+alt+F8 150 | { -0.3, -0.3, -0.3, 0.0, 0.0 } 151 | { -0.6, -0.6, -0.6, 0.0, 0.0 } 152 | { -0.1, -0.1, -0.1, 0.0, 0.0 } 153 | { 0.0, 0.0, 0.0, 1.0, 0.0 } 154 | { 1.0, 1.0, 1.0, 0.0, 1.0 } 155 | 156 | #Grayscaled 157 | Negative Red=win+alt+F9 158 | { -0.3, 0.0, 0.0, 0.0, 0.0 } 159 | { -0.6, 0.0, 0.0, 0.0, 0.0 } 160 | { -0.1, 0.0, 0.0, 0.0, 0.0 } 161 | { 0.0, 0.0, 0.0, 1.0, 0.0 } 162 | { 1.0, 0.0, 0.0, 0.0, 1.0 } 163 | 164 | #Grayscaled 165 | Red=win+alt+F10 166 | { 0.3, 0.0, 0.0, 0.0, 0.0 } 167 | { 0.6, 0.0, 0.0, 0.0, 0.0 } 168 | { 0.1, 0.0, 0.0, 0.0, 0.0 } 169 | { 0.0, 0.0, 0.0, 1.0, 0.0 } 170 | { 0.0, 0.0, 0.0, 0.0, 1.0 } 171 | 172 | Grayscale=win+alt+F11 173 | { 0.3, 0.3, 0.3, 0.0, 0.0 } 174 | { 0.6, 0.6, 0.6, 0.0, 0.0 } 175 | { 0.1, 0.1, 0.1, 0.0, 0.0 } 176 | { 0.0, 0.0, 0.0, 1.0, 0.0 } 177 | { 0.0, 0.0, 0.0, 0.0, 1.0 } 178 | 179 | # Color blindness simulation matrices 180 | # Source: http://web.archive.org/web/20081014161121/http://www.colorjack.com/labs/colormatrix/ 181 | 182 | # http://www.color-blindness.com/protanopia-red-green-color-blindness/ 183 | # Red-Green Color Blindness - Male Population: 1.01%, Female 0.02 184 | Color blindness simulation: Protanopia (Red-Green Color Blindness)= 185 | { 0.567, 0.558, 0, 0, 0 } 186 | { 0.433, 0.442, 0.242, 0, 0 } 187 | { 0, 0, 0.758, 0, 0 } 188 | { 0, 0, 0, 1, 0 } 189 | { 0, 0, 0, 0, 1 } 190 | 191 | 192 | # http://www.color-blindness.com/protanopia-red-green-color-blindness/ 193 | # Protanomaly (red-weak) - Male Population: 1.08%, 0.03% 194 | Color blindness simulation: Protanomaly (red-weak)= 195 | { 0.817, 0.333, 0, 0, 0 } 196 | { 0.183, 0.667, 0.125, 0, 0 } 197 | { 0, 0, 0.875, 0, 0 } 198 | { 0, 0, 0, 1, 0 } 199 | { 0, 0, 0, 0, 1 } 200 | 201 | 202 | # http://www.color-blindness.com/deuteranopia-red-green-color-blindness/ 203 | # http://www.colour-blindness.com/general/prevalence/ 204 | # Deuteranopia (also called green-blind) - Male Population: 1%, Female Population: 0.1% 205 | Color blindness simulation: Deuteranopia (green-blind)= 206 | { 0.625, 0.7, 0, 0, 0 } 207 | { 0.375, 0.3, 0.3, 0, 0 } 208 | { 0, 0, 0.7, 0, 0 } 209 | { 0, 0, 0, 1, 0 } 210 | { 0, 0, 0, 0, 1 } 211 | 212 | 213 | # http://www.colour-blindness.com/general/prevalence/ 214 | # Deuteranomaly (green-weak) - Male Population: 5%, Female Population: 0.35% 215 | Color blindness simulation: Deuteranomaly (green-weak)= 216 | { 0.8, 0.258, 0, 0, 0 } 217 | { 0.2, 0.742, 0.142, 0, 0 } 218 | { 0, 0, 0.858, 0, 0 } 219 | { 0, 0, 0, 1, 0 } 220 | { 0, 0, 0, 0, 1 } 221 | 222 | 223 | # http://www.color-blindness.com/tritanopia-blue-yellow-color-blindness/ 224 | # http://www.colour-blindness.com/general/prevalence/ 225 | # Tritanopia – Blue-Yellow Color Blindness - rare. Some sources estimate 0.008% 226 | Color blindness simulation: Tritanopia (Blue-Yellow Color Blindness - rare)= 227 | { 0.95, 0, 0, 0, 0 } 228 | { 0.05, 0.433, 0.475, 0, 0 } 229 | { 0, 0.567, 0.525, 0, 0 } 230 | { 0, 0, 0, 1, 0 } 231 | { 0, 0, 0, 0, 1 } 232 | 233 | 234 | # http://www.color-blindness.com/tritanopia-blue-yellow-color-blindness/ 235 | # http://www.colour-blindness.com/general/prevalence/ 236 | # Tritanomaly (blue-yellow weak) - Male 0.01%, Female 0.01% 237 | Color blindness simulation: Tritanomaly (blue-yellow weak)= 238 | { 0.967, 0, 0, 0, 0 } 239 | { 0.033, 0.733, 0.183, 0, 0 } 240 | { 0, 0.267, 0.817, 0, 0 } 241 | { 0, 0, 0, 1, 0 } 242 | { 0, 0, 0, 0, 1 } 243 | 244 | 245 | # http://www.color-blindness.com/2007/07/20/monochromacy-complete-color-blindness/ 246 | # Total color blindness - Occurrences are estimated to be between 1 : 30’000 and 1 : 50’000. 247 | Color blindness simulation: Achromatopsia (Total color blindness)= 248 | { 0.299, 0.299, 0.299, 0, 0 } 249 | { 0.587, 0.587, 0.587, 0, 0 } 250 | { 0.114, 0.114, 0.114, 0, 0 } 251 | { 0, 0, 0, 1, 0 } 252 | { 0, 0, 0, 0, 1 } 253 | 254 | 255 | # http://www.color-blindness.com/2007/07/20/monochromacy-complete-color-blindness/ 256 | # All color-weak - Different sources vary between 1 in 33’000 to 100’000 (0.001%). 257 | Color blindness simulation: Achromatomaly (Total color weakness)= 258 | { 0.618, 0.163, 0.163, 0, 0 } 259 | { 0.32, 0.775, 0.32, 0, 0 } 260 | { 0.062, 0.062, 0.516, 0, 0 } 261 | { 0, 0, 0, 1, 0 } 262 | { 0, 0, 0, 0, 1 } 263 | 264 | Binary (Black and white)= 265 | { 127, 127, 127, 0, 0 } 266 | { 127, 127, 127, 0, 0 } 267 | { 127, 127, 127, 0, 0 } 268 | { 0, 0, 0, 1, 0 } 269 | { -180, -180, -180, 0, 1 } 270 | "; 271 | #endregion 272 | 273 | private static Configuration _current; 274 | public static Configuration Current 275 | { 276 | get 277 | { 278 | Initialize(); 279 | return _current; 280 | } 281 | } 282 | 283 | public static void Initialize() 284 | { 285 | if (_current == null) 286 | { 287 | _current = new Configuration(); 288 | } 289 | } 290 | 291 | private Configuration() 292 | { 293 | ColorEffects = new List>(); 294 | 295 | string configFileContent = ReadCurrentConfiguration(); 296 | 297 | Parser.AssignConfiguration(configFileContent, this, new HotKeyParser(), new MatrixParser()); 298 | if (!string.IsNullOrWhiteSpace(InitialColorEffectName)) 299 | { 300 | try 301 | { 302 | this.InitialColorEffect = this.ColorEffects.Single(x => 303 | x.Value.Description.ToLowerInvariant() == InitialColorEffectName.ToLowerInvariant()).Value; 304 | } 305 | catch (Exception) 306 | { 307 | // probably not ideal 308 | this.InitialColorEffect = new ScreenColorEffect(BuiltinMatrices.Negative, "Negative"); 309 | } 310 | } 311 | } 312 | 313 | private string ReadCurrentConfiguration() 314 | { 315 | try 316 | { 317 | // First try to read the AppData conf 318 | Source = ConfigurationLocation.AppData; 319 | return File.ReadAllText(AppDataConfigurationFileName); 320 | } 321 | catch (Exception) 322 | { 323 | try 324 | { 325 | // If we can't access it, try the one in the working directory 326 | Source = ConfigurationLocation.WorkingDirectory; 327 | return File.ReadAllText(WorkingDirectoryConfigurationFileName); 328 | } 329 | catch (Exception) 330 | { 331 | // If all else fails, read the default embedded one 332 | Source = ConfigurationLocation.Embedded; 333 | return DefaultConfiguration; 334 | } 335 | } 336 | } 337 | 338 | private void EnsureAppDataConfigurationFileExists() 339 | { 340 | Directory.CreateDirectory(Path.GetDirectoryName(AppDataConfigurationFileName)); 341 | if (!File.Exists(AppDataConfigurationFileName)) 342 | { 343 | File.WriteAllText(AppDataConfigurationFileName, DefaultConfiguration); 344 | } 345 | } 346 | 347 | public static void UserEditCurrentConfiguration() 348 | { 349 | void EditPath(string path) 350 | { 351 | Process.Start("notepad", path); 352 | } 353 | 354 | switch (Current.Source) 355 | { 356 | case ConfigurationLocation.AppData: 357 | // If the source is AppData, use it: 358 | EditPath(Current.AppDataConfigurationFileName); 359 | break; 360 | case ConfigurationLocation.WorkingDirectory: 361 | case ConfigurationLocation.Embedded: 362 | default: 363 | // If the source is the working directory, or no config file exists yet, try there first: 364 | // (File.GetAccessControl() looks very scary and error prone, so we just try to open the file...) 365 | try 366 | { 367 | if (!File.Exists(Current.WorkingDirectoryConfigurationFileName)) 368 | { 369 | // create it with the default configuration template 370 | File.WriteAllText(Current.WorkingDirectoryConfigurationFileName, DefaultConfiguration); 371 | } 372 | else 373 | { 374 | // just check we can access it 375 | using (new FileStream(Current.WorkingDirectoryConfigurationFileName, FileMode.Open, FileAccess.ReadWrite)) { } 376 | } 377 | // Edit the working directory conf if we can 378 | EditPath(Current.WorkingDirectoryConfigurationFileName); 379 | } 380 | catch (Exception) 381 | { 382 | // If we can't access the working directory conf, use the AppData one instead 383 | Current.EnsureAppDataConfigurationFileExists(); 384 | EditPath(Current.AppDataConfigurationFileName); 385 | } 386 | break; 387 | } 388 | } 389 | 390 | [MatchingKey("Toggle", CustomParameter = HotKey.ToggleKeyId)] 391 | public HotKey ToggleKey { get; protected set; } 392 | 393 | [MatchingKey("Exit", CustomParameter = HotKey.ExitKeyId)] 394 | public HotKey ExitKey { get; protected set; } 395 | 396 | [MatchingKey("SmoothTransitions")] 397 | public bool SmoothTransitions { get; protected set; } 398 | 399 | [MatchingKey("SmoothToggles")] 400 | public bool SmoothToggles { get; protected set; } 401 | 402 | [MatchingKey("MainLoopRefreshTime", CustomParameter = 100)] 403 | public int MainLoopRefreshTime { get; protected set; } 404 | 405 | [MatchingKey("ActiveOnStartup", CustomParameter = true)] 406 | public bool ActiveOnStartup { get; protected set; } 407 | 408 | [MatchingKey("ShowAeroWarning", CustomParameter = true)] 409 | public bool ShowAeroWarning { get; protected set; } 410 | 411 | [MatchingKey("EnableApi", CustomParameter = false)] 412 | public bool EnableApi { get; protected set; } 413 | 414 | [MatchingKey("ApiListeningUri", CustomParameter = "http://localhost:8990/")] 415 | public string ApiListeningUri { get; protected set; } 416 | 417 | [MatchingKey("InitialColorEffect")] 418 | public string InitialColorEffectName { get; protected set; } 419 | 420 | public ScreenColorEffect InitialColorEffect { get; protected set; } 421 | 422 | public List> ColorEffects { get; protected set; } 423 | 424 | public void HandleDynamicKey(string key, string value) 425 | { 426 | // value is already trimmed 427 | if (value.StartsWith("{")) 428 | { 429 | // no hotkey 430 | this.ColorEffects.Add(new KeyValuePair( 431 | HotKey.Empty, 432 | new ScreenColorEffect(MatrixParser.StaticParseMatrix(value), key))); 433 | } 434 | else 435 | { 436 | // first part is the hotkey, second part is the matrix 437 | var splitted = value.Split(new char[] { '\n' }, 2); 438 | if (splitted.Length < 2) 439 | { 440 | throw new Exception(string.Format( 441 | "The value assigned to \"{0}\" is unexpected. The hotkey must be separated from the matrix by a new line.", 442 | key)); 443 | } 444 | this.ColorEffects.Add(new KeyValuePair( 445 | HotKeyParser.StaticParse(splitted[0]), 446 | new ScreenColorEffect(MatrixParser.StaticParseMatrix(splitted[1]), key))); 447 | } 448 | } 449 | } 450 | 451 | class HotKeyParser : ICustomParser 452 | { 453 | 454 | public Type ReturnType => typeof(HotKey); 455 | 456 | public object Parse(string rawValue, object customParameter) 457 | { 458 | int defaultId = -1; 459 | if (customParameter is int) 460 | { 461 | defaultId = (int)customParameter; 462 | } 463 | return StaticParse(rawValue, defaultId); 464 | } 465 | 466 | public static HotKey StaticParse(string rawValue, int defaultId = -1) 467 | { 468 | KeyModifiers modifiers = KeyModifiers.NONE; 469 | Keys key = Keys.None; 470 | string trimmed = rawValue.Trim(); 471 | var splitted = trimmed.Split('+'); 472 | foreach (var item in splitted) 473 | { 474 | // modifier 475 | switch (item.ToLowerInvariant()) 476 | { 477 | case "alt": 478 | modifiers |= KeyModifiers.MOD_ALT; 479 | break; 480 | case "ctrl": 481 | modifiers |= KeyModifiers.MOD_CONTROL; 482 | break; 483 | case "shift": 484 | modifiers |= KeyModifiers.MOD_SHIFT; 485 | break; 486 | case "win": 487 | modifiers |= KeyModifiers.MOD_WIN; 488 | break; 489 | default: 490 | // key 491 | if (!Enum.TryParse(item, true, out key)) 492 | { 493 | // try to parse numeric value 494 | if (int.TryParse(item, out int numericValue)) 495 | { 496 | if (Enum.IsDefined(typeof(Keys), numericValue)) 497 | { 498 | key = (Keys)numericValue; 499 | } 500 | } 501 | } 502 | break; 503 | } 504 | 505 | } 506 | return new HotKey(modifiers, key, defaultId); 507 | } 508 | } 509 | 510 | class MatrixParser : ICustomParser 511 | { 512 | 513 | public Type ReturnType => typeof(float[,]); 514 | 515 | public object Parse(string rawValue, object customParameter) 516 | => StaticParseMatrix(rawValue); 517 | 518 | public static float[,] StaticParseMatrix(string rawValue) 519 | { 520 | float[,] matrix = new float[5, 5]; 521 | var rows = System.Text.RegularExpressions.Regex.Matches(rawValue, @"{(?.*?)}", 522 | System.Text.RegularExpressions.RegexOptions.ExplicitCapture); 523 | if (rows.Count != 5) 524 | { 525 | throw new Exception("The matrices must have 5 rows."); 526 | } 527 | for (int x = 0; x < rows.Count; x++) 528 | { 529 | var row = rows[x]; 530 | var columnSplit = row.Groups["row"].Value.Split(','); 531 | if (columnSplit.Length != 5) 532 | { 533 | throw new Exception("The matrices must have 5 columns."); 534 | } 535 | for (int y = 0; y < matrix.GetLength(1); y++) 536 | { 537 | if (!float.TryParse(columnSplit[y], 538 | System.Globalization.NumberStyles.Float, 539 | System.Globalization.NumberFormatInfo.InvariantInfo, 540 | out float value)) 541 | { 542 | throw new Exception(string.Format("Unable to parse \"{0}\" to a float.", columnSplit[y])); 543 | } 544 | matrix[x, y] = value; 545 | } 546 | } 547 | return matrix; 548 | } 549 | } 550 | 551 | struct HotKey 552 | { 553 | public const int ToggleKeyId = 42; 554 | public const int ExitKeyId = 43; 555 | 556 | private static int CurrentId = 100; 557 | 558 | public static readonly HotKey Empty = new HotKey() 559 | { 560 | Id = 0, 561 | Key = Keys.None, 562 | Modifiers = KeyModifiers.NONE 563 | }; 564 | 565 | public KeyModifiers Modifiers { get; private set; } 566 | public Keys Key { get; private set; } 567 | public int Id { get; private set; } 568 | 569 | public HotKey(KeyModifiers modifiers, Keys key, int id = -1) 570 | : this() 571 | { 572 | Modifiers = modifiers; 573 | // 65535 574 | Key = key & Keys.KeyCode; 575 | if (id == -1) 576 | { 577 | Id = CurrentId; 578 | CurrentId++; 579 | } 580 | else 581 | { 582 | Id = id; 583 | } 584 | } 585 | 586 | public override int GetHashCode() 587 | => (int)Key | (int)Modifiers << 16 | Id << 20; 588 | 589 | public override bool Equals(object obj) 590 | { 591 | if (obj == null) 592 | { 593 | return false; 594 | } 595 | if (obj is HotKey) 596 | { 597 | return obj.GetHashCode() == this.GetHashCode(); 598 | } 599 | else 600 | { 601 | return false; 602 | } 603 | } 604 | 605 | public static bool operator ==(HotKey a, HotKey b) 606 | => a.GetHashCode() == b.GetHashCode(); 607 | 608 | public static bool operator !=(HotKey a, HotKey b) 609 | => a.GetHashCode() != b.GetHashCode(); 610 | 611 | public override string ToString() 612 | { 613 | StringBuilder sb = new StringBuilder(); 614 | if (Modifiers.HasFlag(KeyModifiers.MOD_ALT)) 615 | { 616 | sb.Append("Alt+"); 617 | } 618 | if (Modifiers.HasFlag(KeyModifiers.MOD_CONTROL)) 619 | { 620 | sb.Append("Ctrl+"); 621 | } 622 | if (Modifiers.HasFlag(KeyModifiers.MOD_SHIFT)) 623 | { 624 | sb.Append("Shift+"); 625 | } 626 | if (Modifiers.HasFlag(KeyModifiers.MOD_WIN)) 627 | { 628 | sb.Append("Win+"); 629 | } 630 | sb.Append(Enum.GetName(typeof(Keys), Key) ?? ((int)Key).ToString()); 631 | return sb.ToString(); 632 | } 633 | } 634 | 635 | struct ScreenColorEffect 636 | { 637 | public float[,] Matrix { get; } 638 | public string Description { get; } 639 | 640 | public ScreenColorEffect(float[,] matrix, string description) 641 | : this() 642 | { 643 | Matrix = matrix; 644 | Description = description; 645 | } 646 | 647 | } 648 | 649 | enum ConfigurationLocation 650 | { 651 | Embedded, 652 | AppData, 653 | WorkingDirectory, 654 | } 655 | } 656 | -------------------------------------------------------------------------------- /NegativeScreen/ConfigurationParser.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2017 Melvyn Laïly 2 | // https://zerowidthjoiner.net 3 | 4 | // This file is part of NegativeScreen. 5 | 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | using System; 20 | using System.Collections.Generic; 21 | using System.Linq; 22 | using System.Text; 23 | using System.Reflection; 24 | 25 | namespace NegativeScreen 26 | { 27 | /// 28 | /// Represents the class storing the parsed key-value pairs from the configuration file. 29 | /// 30 | public interface IConfigurable 31 | { 32 | /// 33 | /// This method is automatically called when a key from the configuration file 34 | /// does not match any property marked with a . 35 | /// This allows to handle dynamically declared keys in the configuration file. 36 | /// 37 | /// 38 | /// 39 | void HandleDynamicKey(string key, string value); 40 | } 41 | 42 | /// 43 | /// Represents a custom parser for a given type. 44 | /// This allows a better control over the values' parsing. 45 | /// 46 | public interface ICustomParser 47 | { 48 | /// 49 | /// Type this custom parser handles. 50 | /// 51 | Type ReturnType { get; } 52 | /// 53 | /// 54 | /// 55 | /// 56 | /// Raw value to parse, trimmed from any whitespace. 57 | /// 58 | /// 59 | /// A custom parameter, from the . 60 | /// Its behaviour is left to the implementer's discretion. 61 | /// 62 | /// 63 | object Parse(string rawValue, object customParameter); 64 | } 65 | 66 | /// 67 | /// Mark a property as the storage for a matching key in the configuration file. 68 | /// All keys are case insensitive. 69 | /// A custom parameter can be provided, which will be passed to the parser handling this property type. 70 | /// 71 | [AttributeUsage(AttributeTargets.Property, Inherited = true, AllowMultiple = false)] 72 | public sealed class MatchingKeyAttribute : Attribute 73 | { 74 | public string Key { get; } 75 | 76 | public MatchingKeyAttribute(string key) 77 | { 78 | Key = key.ToLowerInvariant(); 79 | } 80 | 81 | public object CustomParameter { get; set; } 82 | } 83 | 84 | /// 85 | /// Static class allowing to parse configuration files. 86 | /// 87 | public static class Parser 88 | { 89 | 90 | /// 91 | /// 92 | /// 93 | /// Raw configuration file content. 94 | /// The configuration object, implementing IConfigurable. 95 | /// Optional array of parser allowing to parse any type the way you want. 96 | public static void AssignConfiguration(string content, IConfigurable configuration, params ICustomParser[] customParsers) 97 | { 98 | Dictionary rawConfiguration = ParseConfiguration(content); 99 | var configurableProperties = 100 | (from p in configuration.GetType().GetProperties() 101 | let attr = p.GetCustomAttributes(typeof(MatchingKeyAttribute), true) 102 | where attr.Length == 1 103 | select new { Property = p, Attribute = attr.First() as MatchingKeyAttribute }) 104 | .ToList(); 105 | foreach (var item in rawConfiguration) 106 | { 107 | string key = item.Key.ToLowerInvariant(); 108 | var matchingProps = configurableProperties.Where(x => x.Attribute.Key == key); 109 | PropertyInfo matchingProp = null; 110 | MatchingKeyAttribute matchingAttribute = null; 111 | if (matchingProps.Any()) 112 | { 113 | try 114 | { 115 | // try to find a matching property for this key 116 | var single = matchingProps.Single(); 117 | matchingProp = single.Property; 118 | matchingAttribute = single.Attribute; 119 | configurableProperties.Remove(single); 120 | } 121 | catch (Exception ex) 122 | { 123 | throw new Exception(string.Format("The key \"{0}\" was found multiple times!", key), ex); 124 | } 125 | // parse value 126 | var appropriateParser = customParsers.FirstOrDefault(x => x.ReturnType == matchingProp.PropertyType); 127 | if (appropriateParser != null) 128 | { 129 | object parsed = appropriateParser.Parse(item.Value, matchingAttribute.CustomParameter); 130 | matchingProp.SetValue(configuration, parsed, null); 131 | } 132 | // default parsers 133 | else if (matchingProp.PropertyType == typeof(string)) 134 | { 135 | // todo: handle default values for strings 136 | matchingProp.SetValue(configuration, item.Value, null); 137 | } 138 | else if (matchingProp.PropertyType == typeof(bool)) 139 | { 140 | if (matchingAttribute.CustomParameter is bool) 141 | { 142 | matchingProp.SetValue(configuration, ParseBool(item.Value, (bool)matchingAttribute.CustomParameter), null); 143 | } 144 | else 145 | { 146 | matchingProp.SetValue(configuration, ParseBool(item.Value), null); 147 | } 148 | } 149 | else if (matchingProp.PropertyType == typeof(int)) 150 | { 151 | if (matchingAttribute.CustomParameter is int) 152 | { 153 | matchingProp.SetValue(configuration, ParseInt(item.Value, (int)matchingAttribute.CustomParameter), null); 154 | } 155 | else 156 | { 157 | matchingProp.SetValue(configuration, ParseInt(item.Value), null); 158 | } 159 | } 160 | // TODO: default parser for other simple types (int, float...) 161 | else 162 | { 163 | throw new Exception(string.Format("Could not find a parser for type \"{0}\"!", matchingProp.PropertyType)); 164 | } 165 | } 166 | else 167 | { 168 | // no matching assignable property 169 | configuration.HandleDynamicKey(item.Key, item.Value); 170 | } 171 | } 172 | // assign default value if present for remaining properties not found in configuration 173 | foreach (var remainingPropery in configurableProperties) 174 | { 175 | // todo : throw exception if no default parameter to avoid impredictable errors? 176 | // >> need to differentiate default null from provided null 177 | if (remainingPropery.Attribute.CustomParameter != null) 178 | { 179 | remainingPropery.Property.SetValue(configuration, remainingPropery.Attribute.CustomParameter, null); 180 | } 181 | } 182 | } 183 | 184 | /// 185 | /// comments: if the character '#' is found, the rest of the line is ignored 186 | /// quotes: allow to place a '#' inside a value. they do not appear in the final result 187 | /// i.e. blah="hello #1!" will create a parameter blah with a value of: hello #1! 188 | /// to place a quotation mark inside quotes, double it 189 | /// i.e. blah="hello""" will create a parameter blah with a value of: hello " 190 | /// 191 | /// The keys and values are always trimmed from any white space. 192 | /// 193 | private static Dictionary ParseConfiguration(string content) 194 | { 195 | var cleanedContent = content.Replace("\r\n", "\n").Replace('\r', '\n'); 196 | int i = 0; 197 | Dictionary parsed = new Dictionary(); 198 | StringBuilder left = new StringBuilder(); 199 | StringBuilder right = new StringBuilder(); 200 | bool insideQuotes = false; 201 | while (i < cleanedContent.Length) 202 | { 203 | char read = cleanedContent[i]; 204 | switch (read) 205 | { 206 | case '"': 207 | if (insideQuotes) 208 | { 209 | // handle double quotes inside quotation marks 210 | if (i + 1 < cleanedContent.Length && cleanedContent[i + 1] == '"') 211 | { 212 | right.Append('"'); 213 | i++; 214 | break; 215 | } 216 | } 217 | insideQuotes = !insideQuotes; 218 | break; 219 | case '#': 220 | if (insideQuotes) 221 | { 222 | goto default; 223 | } 224 | // ignore line 225 | do 226 | { 227 | i++; 228 | } while (i < cleanedContent.Length && cleanedContent[i] != '\n'); 229 | // include the new line 230 | i--; 231 | break; 232 | case '=': 233 | if (insideQuotes) 234 | { 235 | goto default; 236 | } 237 | int indexOfLastLine = right.Length - 1; 238 | while (indexOfLastLine > 0 && right[indexOfLastLine] != '\n') 239 | { 240 | indexOfLastLine--; 241 | } 242 | if (left.Length > 0) 243 | { 244 | string key = left.ToString().Trim(); 245 | // the last declaration overwrite any existing one 246 | if (parsed.ContainsKey(key)) 247 | { 248 | parsed[key] = right.ToString(0, indexOfLastLine).Trim(); 249 | } 250 | else 251 | { 252 | parsed.Add(key, right.ToString(0, indexOfLastLine).Trim()); 253 | } 254 | } 255 | left = right.Remove(0, indexOfLastLine > 0 ? indexOfLastLine + 1 : 0); 256 | right = new StringBuilder(); 257 | break; 258 | default: 259 | right.Append(read); 260 | break; 261 | } 262 | i++; 263 | } 264 | parsed.Add(left.ToString().Trim(), right.ToString().Trim()); 265 | return parsed; 266 | } 267 | 268 | private static bool ParseBool(string rawValue, bool? @default = null) 269 | { 270 | string trimmed = rawValue.Trim(); 271 | switch (trimmed.ToLowerInvariant()) 272 | { 273 | case "true": 274 | return true; 275 | case "false": 276 | return false; 277 | default: 278 | if (@default.HasValue) 279 | { 280 | return @default.Value; 281 | } 282 | else 283 | { 284 | throw new Exception("Could not parse a boolean value!"); 285 | } 286 | } 287 | } 288 | 289 | private static int ParseInt(string rawValue, int? @default = null) 290 | { 291 | string trimmed = rawValue.Trim(); 292 | if (int.TryParse(trimmed, out int value)) 293 | { 294 | return value; 295 | } 296 | else 297 | { 298 | if (@default.HasValue) 299 | { 300 | return @default.Value; 301 | } 302 | else 303 | { 304 | throw new Exception("Could not parse an integer value!"); 305 | } 306 | } 307 | } 308 | 309 | } 310 | } 311 | -------------------------------------------------------------------------------- /NegativeScreen/Icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mlaily/NegativeScreen/4608df1669b2fcfede8f25a0c6d5407521d54f09/NegativeScreen/Icon.ico -------------------------------------------------------------------------------- /NegativeScreen/NativeMethods.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2017 Melvyn Laïly 2 | // https://zerowidthjoiner.net 3 | 4 | // This file is part of NegativeScreen. 5 | 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | using System; 20 | using System.Runtime.InteropServices; 21 | using System.Windows.Forms; 22 | using System.Diagnostics; 23 | 24 | namespace NegativeScreen 25 | { 26 | /// 27 | /// Based on http://delphi32.blogspot.com/2010/09/windows-magnification-api-net.html 28 | /// 29 | internal static class NativeMethods 30 | { 31 | 32 | #region "User32.dll" 33 | /// 34 | /// Places the window above all non-topmost windows. The window maintains its topmost position even when it is deactivated. 35 | /// (SetWindowPos() parameter) 36 | /// 37 | public static IntPtr HWND_TOPMOST = new IntPtr(-1); 38 | 39 | /// 40 | /// Places the window at the top of the Z order. 41 | /// (SetWindowPos() parameter) 42 | /// 43 | public static IntPtr HWND_TOP = new IntPtr(0); 44 | 45 | /// 46 | /// http://msdn.microsoft.com/en-us/library/ms633545%28v=vs.85%29.aspx 47 | /// 48 | /// 49 | /// 50 | /// 51 | /// 52 | /// 53 | /// 54 | /// 55 | /// 56 | [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, SetLastError = true)] 57 | [return: MarshalAs(UnmanagedType.Bool)] 58 | public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, int flags); 59 | 60 | /// 61 | /// Sets a new extended window style. 62 | /// (SetWindowLong() parameter) 63 | /// 64 | public const int GWL_EXSTYLE = -20; 65 | /// 66 | /// Sets a new window style. 67 | /// (SetWindowLong() parameter) 68 | /// 69 | public const int GWL_STYLE = -16; 70 | 71 | [return: MarshalAs(UnmanagedType.Bool)] 72 | [DllImport("user32.dll", SetLastError = true)] 73 | public static extern bool PostThreadMessage(uint threadId, uint msg, IntPtr wParam, IntPtr lParam); 74 | 75 | /// 76 | /// http://msdn.microsoft.com/en-us/library/ms633591%28v=vs.85%29.aspx 77 | /// 78 | /// 79 | /// GWL_EXSTYLE, GWL_STYLE, [...] 80 | /// 81 | /// 82 | [DllImport("user32.dll", SetLastError = true)] 83 | public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); 84 | 85 | /// 86 | /// http://msdn.microsoft.com/en-us/library/ms632680%28v=vs.85%29.aspx 87 | /// 88 | /// 89 | /// 90 | /// 91 | /// 92 | /// 93 | /// 94 | /// 95 | /// 96 | /// 97 | /// 98 | /// 99 | /// 100 | /// 101 | [DllImport("user32.dll", EntryPoint = "CreateWindowExW", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall, SetLastError = true)] 102 | public extern static IntPtr CreateWindowEx( 103 | int dwExStyle, 104 | string lpClassName, 105 | string lpWindowName, 106 | int dwStyle, 107 | int x, 108 | int y, 109 | int nWidth, 110 | int nHeight, 111 | IntPtr hWndParent, 112 | IntPtr hMenu, 113 | IntPtr hInstance, 114 | IntPtr lParam); 115 | 116 | /// 117 | /// http://msdn.microsoft.com/en-us/library/ms633540%28v=vs.85%29.aspx 118 | /// 119 | /// 120 | /// 121 | /// 122 | /// 123 | /// 124 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Portability", "CA1901:PInvokeDeclarationsShouldBePortable", MessageId = "2")] 125 | [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)] 126 | [return: MarshalAs(UnmanagedType.Bool)] 127 | public static extern bool SetLayeredWindowAttributes(IntPtr hwnd, int crKey, byte bAlpha, LayeredWindowAttributeFlags dwFlags); 128 | 129 | /// 130 | /// http://msdn.microsoft.com/en-us/library/dd145002%28v=vs.85%29.aspx 131 | /// 132 | /// 133 | /// 134 | /// 135 | /// 136 | [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, SetLastError = true)] 137 | [return: MarshalAs(UnmanagedType.Bool)] 138 | public static extern bool InvalidateRect(IntPtr hWnd, IntPtr rect, [MarshalAs(UnmanagedType.Bool)] bool erase); 139 | 140 | /// 141 | /// 142 | /// handle to window 143 | /// hot key identifier 144 | /// key-modifier options 145 | /// virtual-key code 146 | /// 147 | [DllImport("user32.dll", SetLastError = true)] 148 | [return: MarshalAs(UnmanagedType.Bool)] 149 | public static extern bool RegisterHotKey(IntPtr hWnd, int id, KeyModifiers fsModifiers, Keys vk); 150 | 151 | /// 152 | /// 153 | /// handle to window 154 | /// hot key identifier 155 | /// 156 | [DllImport("user32.dll", SetLastError = true)] 157 | [return: MarshalAs(UnmanagedType.Bool)] 158 | public static extern bool UnregisterHotKey(IntPtr hWnd, int id); 159 | 160 | /// 161 | /// http://msdn.microsoft.com/en-us/library/ms633543.aspx 162 | /// 163 | /// 164 | [DllImport("user32.dll", SetLastError = true)] 165 | public static extern bool SetProcessDPIAware(); 166 | 167 | /// 168 | /// Undocumented function. 169 | /// http://msdn.microsoft.com/en-us/library/windows/desktop/hh162714%28v=vs.85%29.aspx 170 | /// 171 | /// 172 | /// 173 | /// 174 | /// 175 | [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)] 176 | [return: MarshalAs(UnmanagedType.Bool)] 177 | public static extern bool SetMagnificationDesktopMagnification(double scale, int x, int y); 178 | 179 | /// 180 | /// Undocumented function. 181 | /// http://msdn.microsoft.com/en-us/library/windows/desktop/hh162710%28v=vs.85%29.aspx 182 | /// 183 | /// 184 | /// 185 | /// 186 | /// 187 | [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)] 188 | [return: MarshalAs(UnmanagedType.Bool)] 189 | public static extern bool GetMagnificationDesktopMagnification(out double scale, out int x, out int y); 190 | 191 | /// 192 | /// Undocumented function. 193 | /// http://msdn.microsoft.com/en-us/library/windows/desktop/hh162709%28v=vs.85%29.aspx 194 | /// 195 | /// 196 | /// 197 | [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)] 198 | [return: MarshalAs(UnmanagedType.Bool)] 199 | public static extern bool GetMagnificationDesktopColorEffect(out ColorEffect pEffect); 200 | 201 | /// 202 | /// Undocumented function. 203 | /// http://msdn.microsoft.com/en-us/library/windows/desktop/hh162713%28v=vs.85%29.aspx 204 | /// 205 | /// 206 | /// 207 | [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)] 208 | [return: MarshalAs(UnmanagedType.Bool)] 209 | public static extern bool SetMagnificationDesktopColorEffect(ref ColorEffect pEffect); 210 | 211 | /// 212 | /// Undocumented function. 213 | /// http://msdn.microsoft.com/en-us/library/windows/desktop/hh162716%28v=vs.85%29.aspx 214 | /// 215 | /// 216 | /// 217 | [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)] 218 | [return: MarshalAs(UnmanagedType.Bool)] 219 | public static extern bool ShowSystemCursor(bool fShowCursor); 220 | 221 | [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)] 222 | [return: MarshalAs(UnmanagedType.Bool)] 223 | public static extern bool SystemParametersInfo(int uiAction, int uiParam, ref int pvParam, int fWinIni); 224 | 225 | #endregion 226 | 227 | #region "Kernel32.dll" 228 | 229 | /// 230 | /// http://msdn.microsoft.com/en-us/library/ms683199%28v=vs.85%29.aspx 231 | /// 232 | /// 233 | /// 234 | [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] 235 | public static extern IntPtr GetModuleHandle([MarshalAs(UnmanagedType.LPWStr)] string modName); 236 | 237 | [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)] 238 | [return: MarshalAs(UnmanagedType.Bool)] 239 | public static extern bool IsWow64Process(IntPtr hProcess, out bool lpSystemInfo); 240 | 241 | public static bool IsX86InWow64Mode() 242 | { 243 | IsWow64Process(Process.GetCurrentProcess().Handle, out bool retVal); 244 | return retVal; 245 | } 246 | 247 | /// 248 | /// Actually useful, combined with HRESULT_FROM_WIN32() and Marshal.GetExceptionForHR(). 249 | /// works with undocumented functions SetMagnificationDesktopColorEffect() etc... 250 | /// where other last error functions do nothing. 251 | /// 252 | /// 253 | [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] 254 | public static extern int GetLastError(); 255 | 256 | /// 257 | /// http://msdn.microsoft.com/en-us/library/windows/desktop/ms680746%28v=vs.85%29.aspx 258 | /// 259 | /// output of GetLastError() 260 | /// 261 | public static int HRESULT_FROM_WIN32(ulong x) 262 | { 263 | const int FACILITY_WIN32 = 7; 264 | return (int)(x) <= 0 ? (int)(x) : (int)(((x) & 0x0000FFFF) | (FACILITY_WIN32 << 16) | 0x80000000); 265 | } 266 | 267 | /// 268 | /// Utility function to ease the pain of calling Marshal.GetExceptionForHR(HRESULT_FROM_WIN32((ulong)GetLastError()))... 269 | /// 270 | /// 271 | public static Exception GetExceptionForLastError() 272 | => Marshal.GetExceptionForHR(HRESULT_FROM_WIN32((ulong)GetLastError())); 273 | 274 | #endregion 275 | 276 | #region "Magnification.dll" 277 | 278 | // http://msdn.microsoft.com/en-us/library/ms692402%28v=vs.85%29.aspx 279 | 280 | /// 281 | /// Window class of the magnifier control 282 | /// 283 | public const string WC_MAGNIFIER = "Magnifier"; 284 | 285 | [DllImport("Magnification.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)] 286 | [return: MarshalAs(UnmanagedType.Bool)] 287 | public static extern bool MagInitialize(); 288 | 289 | [DllImport("Magnification.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)] 290 | [return: MarshalAs(UnmanagedType.Bool)] 291 | public static extern bool MagUninitialize(); 292 | 293 | [DllImport("Magnification.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)] 294 | [return: MarshalAs(UnmanagedType.Bool)] 295 | public static extern bool MagSetWindowSource(IntPtr hwnd, RECT rect); 296 | 297 | [DllImport("Magnification.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)] 298 | [return: MarshalAs(UnmanagedType.Bool)] 299 | public static extern bool MagGetWindowSource(IntPtr hwnd, ref RECT pRect); 300 | 301 | [DllImport("Magnification.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)] 302 | [return: MarshalAs(UnmanagedType.Bool)] 303 | public static extern bool MagSetWindowTransform(IntPtr hwnd, ref Transformation pTransform); 304 | 305 | [DllImport("Magnification.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)] 306 | [return: MarshalAs(UnmanagedType.Bool)] 307 | public static extern bool MagGetWindowTransform(IntPtr hwnd, ref Transformation pTransform); 308 | 309 | [DllImport("Magnification.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)] 310 | [return: MarshalAs(UnmanagedType.Bool)] 311 | // ref keyword necessary for X86, not sure why... (crash on call otherwise) 312 | public static extern bool MagSetColorEffect(IntPtr hwnd, ref ColorEffect pEffect); 313 | 314 | [DllImport("Magnification.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)] 315 | [return: MarshalAs(UnmanagedType.Bool)] 316 | public static extern bool MagGetColorEffect(IntPtr hwnd, ref ColorEffect pEffect); 317 | 318 | [DllImport("Magnification.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)] 319 | [return: MarshalAs(UnmanagedType.Bool)] 320 | public static extern bool MagGetFullscreenColorEffect(ref ColorEffect pEffect); 321 | 322 | [DllImport("Magnification.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)] 323 | [return: MarshalAs(UnmanagedType.Bool)] 324 | public static extern bool MagGetFullscreenTransform(ref float pMagLevel, ref int pxOffset, ref int pyOffset); 325 | 326 | [DllImport("Magnification.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)] 327 | [return: MarshalAs(UnmanagedType.Bool)] 328 | public static extern bool MagSetFullscreenColorEffect(ref ColorEffect pEffect); 329 | 330 | [DllImport("Magnification.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)] 331 | [return: MarshalAs(UnmanagedType.Bool)] 332 | public static extern bool MagSetFullscreenTransform(float magLevel, int xOffset, int yOffset); 333 | 334 | [DllImport("Magnification.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)] 335 | public static extern int MagGetWindowFilterList(IntPtr hwnd, ref MagnifierFilterMode pdwFilterMode, int count, IntPtr pHWND); 336 | 337 | [DllImport("Magnification.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)] 338 | [return: MarshalAs(UnmanagedType.Bool)] 339 | public static extern bool MagSetWindowFilterList(IntPtr hwnd, MagnifierFilterMode pdwFilterMode, int count, IntPtr pHWND); 340 | 341 | public static bool MagSetWindowFilterList(IntPtr hwnd, MagnifierFilterMode filterMode, IntPtr[] pHWND) 342 | { 343 | int arraySize = Marshal.SizeOf(typeof(IntPtr)) * pHWND.Length; 344 | IntPtr ptrDest = Marshal.AllocHGlobal(arraySize); 345 | Marshal.Copy(pHWND, 0, ptrDest, pHWND.Length); 346 | return MagSetWindowFilterList(hwnd, filterMode, pHWND.Length, ptrDest); 347 | } 348 | 349 | [DllImport("Magnification.dll", CallingConvention = CallingConvention.Winapi, SetLastError = true)] 350 | [return: MarshalAs(UnmanagedType.Bool)] 351 | public static extern bool MagShowSystemCursor(bool fShowCursor); 352 | 353 | #endregion 354 | 355 | #region "DWM API" 356 | 357 | // http://msdn.microsoft.com/en-us/library/aa969540%28v=vs.85%29.aspx 358 | 359 | // WARNING! : program must be compiled for x64 or the call will fail! 360 | 361 | [DllImport("dwmapi.dll", PreserveSig = false, SetLastError = true)] 362 | public static extern int DwmSetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE attr, ref DWMWINDOWATTRIBUTE attrValue, int attrSize); 363 | 364 | [DllImport("dwmapi.dll", PreserveSig = false, SetLastError = true)] 365 | public static extern int DwmSetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE attr, ref DWMNCRENDERINGPOLICY attrValue, int attrSize); 366 | 367 | [DllImport("dwmapi.dll", PreserveSig = false, SetLastError = true)] 368 | public static extern int DwmSetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE attr, ref bool attrValue, int attrSize); 369 | 370 | [DllImport("dwmapi.dll", PreserveSig = false, SetLastError = true)] 371 | public static extern int DwmSetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE attr, ref DWMFLIP3DWINDOWPOLICY attrValue, int attrSize); 372 | 373 | 374 | [DllImport("dwmapi.dll", PreserveSig = false, SetLastError = true)] 375 | public static extern bool DwmIsCompositionEnabled(); 376 | 377 | #endregion 378 | } 379 | } -------------------------------------------------------------------------------- /NegativeScreen/NegativeScreen.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | x86 6 | 8.0.30703 7 | 2.0 8 | {D0472F56-4C64-4695-B62F-34CE6218D479} 9 | WinExe 10 | Properties 11 | NegativeScreen 12 | NegativeScreen 13 | v4.5 14 | 15 | 16 | 512 17 | false 18 | publish\ 19 | true 20 | Disk 21 | false 22 | Foreground 23 | 7 24 | Days 25 | false 26 | false 27 | true 28 | 0 29 | 1.0.0.%2a 30 | false 31 | true 32 | 33 | 34 | x86 35 | true 36 | full 37 | false 38 | bin\Debug\ 39 | DEBUG;TRACE 40 | prompt 41 | 4 42 | false 43 | 44 | 45 | x86 46 | pdbonly 47 | true 48 | bin\Release\ 49 | TRACE 50 | prompt 51 | 4 52 | true 53 | false 54 | 55 | 56 | 57 | 58 | 59 | true 60 | bin\x64\Debug\ 61 | DEBUG;TRACE 62 | full 63 | x64 64 | prompt 65 | false 66 | 67 | 68 | bin\x64\Release\ 69 | TRACE 70 | true 71 | pdbonly 72 | x64 73 | prompt 74 | true 75 | false 76 | 77 | 78 | Icon.ico 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | Form 90 | 91 | 92 | AboutBox.cs 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | Form 101 | 102 | 103 | OverlayManager.cs 104 | 105 | 106 | 107 | 108 | 109 | 110 | True 111 | True 112 | Resources.resx 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | False 122 | Microsoft .NET Framework 4 Client Profile %28x86 and x64%29 123 | true 124 | 125 | 126 | False 127 | .NET Framework 3.5 SP1 Client Profile 128 | false 129 | 130 | 131 | False 132 | .NET Framework 3.5 SP1 133 | false 134 | 135 | 136 | False 137 | Windows Installer 3.1 138 | true 139 | 140 | 141 | 142 | 143 | ResXFileCodeGenerator 144 | Resources.Designer.cs 145 | 146 | 147 | 148 | 155 | -------------------------------------------------------------------------------- /NegativeScreen/OverlayManager.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace NegativeScreen 2 | { 3 | partial class OverlayManager 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | #region Windows Form Designer generated code 11 | 12 | /// 13 | /// Required method for Designer support - do not modify 14 | /// the contents of this method with the code editor. 15 | /// 16 | private void InitializeComponent() 17 | { 18 | this.components = new System.ComponentModel.Container(); 19 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(OverlayManager)); 20 | this.trayIcon = new System.Windows.Forms.NotifyIcon(this.components); 21 | this.trayIconContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); 22 | this.toggleInversionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 23 | this.changeModeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 24 | this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); 25 | this.editConfigurationToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 26 | this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); 27 | this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 28 | this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 29 | this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); 30 | this.trayIconContextMenuStrip.SuspendLayout(); 31 | this.SuspendLayout(); 32 | // 33 | // trayIcon 34 | // 35 | this.trayIcon.ContextMenuStrip = this.trayIconContextMenuStrip; 36 | this.trayIcon.Text = "NegativeScreen"; 37 | this.trayIcon.Visible = true; 38 | this.trayIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(this.trayIcon_MouseClick); 39 | // 40 | // trayIconContextMenuStrip 41 | // 42 | this.trayIconContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 43 | this.toggleInversionToolStripMenuItem, 44 | this.changeModeToolStripMenuItem, 45 | this.toolStripSeparator1, 46 | this.editConfigurationToolStripMenuItem, 47 | this.toolStripSeparator2, 48 | this.aboutToolStripMenuItem, 49 | this.toolStripSeparator3, 50 | this.exitToolStripMenuItem}); 51 | this.trayIconContextMenuStrip.Name = "trayIconContextMenuStrip"; 52 | this.trayIconContextMenuStrip.Size = new System.Drawing.Size(172, 154); 53 | // 54 | // toggleInversionToolStripMenuItem 55 | // 56 | this.toggleInversionToolStripMenuItem.Name = "toggleInversionToolStripMenuItem"; 57 | this.toggleInversionToolStripMenuItem.Size = new System.Drawing.Size(171, 22); 58 | this.toggleInversionToolStripMenuItem.Text = "&Toggle Inversion"; 59 | this.toggleInversionToolStripMenuItem.Click += new System.EventHandler(this.toggleInversionToolStripMenuItem_Click); 60 | // 61 | // changeModeToolStripMenuItem 62 | // 63 | this.changeModeToolStripMenuItem.Name = "changeModeToolStripMenuItem"; 64 | this.changeModeToolStripMenuItem.Size = new System.Drawing.Size(171, 22); 65 | this.changeModeToolStripMenuItem.Text = "Change Mode"; 66 | // 67 | // toolStripSeparator1 68 | // 69 | this.toolStripSeparator1.Name = "toolStripSeparator1"; 70 | this.toolStripSeparator1.Size = new System.Drawing.Size(168, 6); 71 | // 72 | // editConfigurationToolStripMenuItem 73 | // 74 | this.editConfigurationToolStripMenuItem.Name = "editConfigurationToolStripMenuItem"; 75 | this.editConfigurationToolStripMenuItem.Size = new System.Drawing.Size(171, 22); 76 | this.editConfigurationToolStripMenuItem.Text = "Edit &Configuration"; 77 | this.editConfigurationToolStripMenuItem.Click += new System.EventHandler(this.editConfigurationToolStripMenuItem_Click); 78 | // 79 | // toolStripSeparator2 80 | // 81 | this.toolStripSeparator2.Name = "toolStripSeparator2"; 82 | this.toolStripSeparator2.Size = new System.Drawing.Size(168, 6); 83 | // 84 | // exitToolStripMenuItem 85 | // 86 | this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; 87 | this.exitToolStripMenuItem.Size = new System.Drawing.Size(171, 22); 88 | this.exitToolStripMenuItem.Text = "&Exit"; 89 | this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); 90 | // 91 | // aboutToolStripMenuItem 92 | // 93 | this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem"; 94 | this.aboutToolStripMenuItem.Size = new System.Drawing.Size(171, 22); 95 | this.aboutToolStripMenuItem.Text = "&About"; 96 | this.aboutToolStripMenuItem.Click += new System.EventHandler(this.aboutToolStripMenuItem_Click); 97 | // 98 | // toolStripSeparator3 99 | // 100 | this.toolStripSeparator3.Name = "toolStripSeparator3"; 101 | this.toolStripSeparator3.Size = new System.Drawing.Size(168, 6); 102 | // 103 | // OverlayManager 104 | // 105 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 106 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 107 | this.ClientSize = new System.Drawing.Size(284, 262); 108 | this.Name = "OverlayManager"; 109 | this.Text = "NegativeScreen"; 110 | this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.OverlayManager_FormClosed); 111 | this.trayIconContextMenuStrip.ResumeLayout(false); 112 | this.ResumeLayout(false); 113 | 114 | } 115 | 116 | #endregion 117 | 118 | private System.Windows.Forms.NotifyIcon trayIcon; 119 | private System.Windows.Forms.ContextMenuStrip trayIconContextMenuStrip; 120 | private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; 121 | private System.Windows.Forms.ToolStripMenuItem toggleInversionToolStripMenuItem; 122 | private System.Windows.Forms.ToolStripMenuItem changeModeToolStripMenuItem; 123 | private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; 124 | private System.Windows.Forms.ToolStripMenuItem editConfigurationToolStripMenuItem; 125 | private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; 126 | private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem; 127 | private System.Windows.Forms.ToolStripSeparator toolStripSeparator3; 128 | } 129 | } -------------------------------------------------------------------------------- /NegativeScreen/OverlayManager.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2017 Melvyn Laïly 2 | // https://zerowidthjoiner.net 3 | 4 | // This file is part of NegativeScreen. 5 | 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | using System; 20 | using System.Collections.Generic; 21 | using System.Text; 22 | using System.Windows.Forms; 23 | using System.Runtime.InteropServices; 24 | using System.Drawing; 25 | using System.Collections.Concurrent; 26 | using System.Linq; 27 | 28 | namespace NegativeScreen 29 | { 30 | /// 31 | /// inherits from Form so that hot keys can be bound to its message loop 32 | /// 33 | partial class OverlayManager : Form 34 | { 35 | private AboutBox aboutForm = new AboutBox(); 36 | 37 | /// 38 | /// control whether the main loop is paused or not. 39 | /// 40 | private bool mainLoopPaused = false; 41 | 42 | /// 43 | /// allow to exit the main loop 44 | /// 45 | private bool exiting = false; 46 | 47 | /// 48 | /// store the current color matrix. 49 | /// 50 | private float[,] currentMatrix = null; 51 | 52 | // /!\ The full screen magnifier seems not to be thread-safe on Windows 8 at least, 53 | // so every call after initialization must be done on the same thread. 54 | #region Inter-thread color effect calls 55 | 56 | /// 57 | /// allow to execute magnifer api calls on the proper thread. 58 | /// 59 | private ScreenColorEffect invokeColorEffect; 60 | private bool shouldInvokeColorEffect; 61 | private object invokeColorEffectLock = new object(); 62 | 63 | /// 64 | /// Ask for a color effect change to be executed on the proper thread. 65 | /// 66 | /// 67 | private void InvokeColorEffect(ScreenColorEffect colorEffect) 68 | { 69 | lock (invokeColorEffectLock) 70 | { 71 | invokeColorEffect = colorEffect; 72 | SynchronizeMenuItemCheckboxesWithEffect(colorEffect); 73 | shouldInvokeColorEffect = true; 74 | } 75 | } 76 | 77 | /// 78 | /// Execute the specified color effect change, on the proper thread. 79 | /// 80 | private void DoMagnifierApiInvoke() 81 | { 82 | lock (invokeColorEffectLock) 83 | { 84 | if (shouldInvokeColorEffect) 85 | { 86 | SafeChangeColorEffect(invokeColorEffect.Matrix); 87 | } 88 | shouldInvokeColorEffect = false; 89 | } 90 | } 91 | 92 | #endregion 93 | 94 | private static OverlayManager _Instance; 95 | public static OverlayManager Instance 96 | { 97 | get 98 | { 99 | Initialize(); 100 | return _Instance; 101 | } 102 | } 103 | 104 | public static void Initialize() 105 | { 106 | if (_Instance == null) 107 | { 108 | _Instance = new OverlayManager(); 109 | } 110 | } 111 | 112 | private OverlayManager() 113 | { 114 | InitializeComponent(); 115 | this.Icon = Properties.Resources.Icon; 116 | trayIcon.Icon = Properties.Resources.Icon; 117 | 118 | TryRegisterHotKeys(); 119 | 120 | toggleInversionToolStripMenuItem.ShortcutKeyDisplayString = Configuration.Current.ToggleKey.ToString(); 121 | exitToolStripMenuItem.ShortcutKeyDisplayString = Configuration.Current.ExitKey.ToString(); 122 | InitializeContextMenu(); 123 | 124 | currentMatrix = Configuration.Current.InitialColorEffect.Matrix; 125 | SynchronizeMenuItemCheckboxesWithEffect(Configuration.Current.InitialColorEffect); // requires the context menu to be initialized 126 | 127 | InitializeControlLoop(); 128 | } 129 | 130 | public void ShowBalloonTip(int timeout, string title, string message, ToolTipIcon icon) 131 | { 132 | trayIcon.ShowBalloonTip(timeout, title, message, icon); 133 | } 134 | 135 | private void TryRegisterHotKeys() 136 | { 137 | 138 | StringBuilder sb = new StringBuilder("Unable to register one or more hot keys:\n"); 139 | bool success = true; 140 | success &= TryRegisterHotKeyAppendError(Configuration.Current.ToggleKey, sb); 141 | success &= TryRegisterHotKeyAppendError(Configuration.Current.ExitKey, sb); 142 | foreach (var item in Configuration.Current.ColorEffects) 143 | { 144 | if (item.Key != HotKey.Empty) 145 | { 146 | success &= TryRegisterHotKeyAppendError(item.Key, sb); 147 | } 148 | } 149 | if (!success) 150 | { 151 | ShowBalloonTip(4000, "Warning", sb.ToString(), ToolTipIcon.Warning); 152 | } 153 | } 154 | 155 | private bool TryRegisterHotKeyAppendError(HotKey hotkey, StringBuilder appendErrorTo) 156 | { 157 | if (!TryRegisterHotKey(hotkey, out AlreadyRegisteredHotKeyException ex)) 158 | { 159 | appendErrorTo.AppendFormat(" - \"{0}\" : {1}", ex.HotKey, (ex.InnerException == null ? "" : ex.InnerException.Message)); 160 | return false; 161 | } 162 | return true; 163 | } 164 | 165 | private void InitializeContextMenu() 166 | { 167 | foreach (var item in Configuration.Current.ColorEffects) 168 | { 169 | var menuItem = new ToolStripMenuItem(item.Value.Description) 170 | { 171 | Tag = item.Value, 172 | ShortcutKeyDisplayString = item.Key.ToString() 173 | }; 174 | menuItem.Click += (s, e) => 175 | { 176 | var effect = (ScreenColorEffect)((ToolStripMenuItem)s).Tag; 177 | InvokeColorEffect(effect); 178 | }; 179 | this.changeModeToolStripMenuItem.DropDownItems.Add(menuItem); 180 | } 181 | } 182 | 183 | private void InitializeControlLoop() 184 | { 185 | System.Threading.Thread t = new System.Threading.Thread(ControlLoop); 186 | t.SetApartmentState((System.Threading.ApartmentState.STA)); 187 | t.Start(); 188 | } 189 | 190 | /// 191 | /// Main loop, in charge of controlling the magnification api. 192 | /// 193 | private void ControlLoop() 194 | { 195 | if (!Configuration.Current.ActiveOnStartup) 196 | { 197 | mainLoopPaused = true; 198 | PauseLoop(); 199 | } 200 | while (!exiting) 201 | { 202 | if (!NativeMethods.MagInitialize()) 203 | { 204 | throw new Exception("MagInitialize()", Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error())); 205 | } 206 | try 207 | { 208 | ToggleColorEffect(fromNormal: true); 209 | } 210 | catch (CannotChangeColorEffectException) 211 | { 212 | // Unable to set the color effect, most likely because the Windows Magnifier color inversion was enabled. 213 | mainLoopPaused = true; 214 | } 215 | while (!exiting) 216 | { 217 | System.Threading.Thread.Sleep(Configuration.Current.MainLoopRefreshTime); 218 | DoMagnifierApiInvoke(); 219 | if (mainLoopPaused) 220 | { 221 | try 222 | { 223 | ToggleColorEffect(fromNormal: false); 224 | } 225 | catch (CannotChangeColorEffectException) 226 | { 227 | // Ignore the error and enter the pause loop. 228 | } 229 | if (!NativeMethods.MagUninitialize()) 230 | { 231 | throw new Exception("MagUninitialize()", Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error())); 232 | } 233 | PauseLoop(); 234 | // we need to reinitialize 235 | break; 236 | } 237 | } 238 | } 239 | this.Invoke((Action)(() => 240 | { 241 | this.Dispose(); 242 | Application.Exit(); 243 | })); 244 | } 245 | 246 | private void PauseLoop() 247 | { 248 | while (mainLoopPaused && !exiting) 249 | { 250 | System.Threading.Thread.Sleep(Configuration.Current.MainLoopRefreshTime); 251 | DoMagnifierApiInvoke(); 252 | } 253 | } 254 | 255 | public bool TryRegisterHotKey(HotKey hotkey, out AlreadyRegisteredHotKeyException exception) 256 | { 257 | bool ok = NativeMethods.RegisterHotKey(this.Handle, hotkey.Id, hotkey.Modifiers, hotkey.Key); 258 | if (!ok) 259 | { 260 | exception = new AlreadyRegisteredHotKeyException(hotkey, Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error())); 261 | return false; 262 | } 263 | else 264 | { 265 | exception = null; 266 | return true; 267 | } 268 | } 269 | 270 | private void UnregisterHotKeys() 271 | { 272 | try 273 | { 274 | NativeMethods.UnregisterHotKey(this.Handle, Configuration.Current.ToggleKey.Id); 275 | NativeMethods.UnregisterHotKey(this.Handle, Configuration.Current.ExitKey.Id); 276 | 277 | } 278 | catch (Exception) { } 279 | } 280 | 281 | protected override void WndProc(ref Message m) 282 | { 283 | // Listen for operating system messages. 284 | switch (m.Msg) 285 | { 286 | case (int)WindowMessage.WM_HOTKEY: 287 | int HotKeyId = (int)m.WParam; 288 | switch (HotKeyId) 289 | { 290 | case HotKey.ExitKeyId: 291 | Exit(); 292 | break; 293 | case HotKey.ToggleKeyId: 294 | Toggle(); 295 | break; 296 | default: 297 | foreach (var item in Configuration.Current.ColorEffects) 298 | { 299 | if (item.Key.Id == HotKeyId) 300 | { 301 | InvokeColorEffect(item.Value); 302 | } 303 | } 304 | break; 305 | } 306 | break; 307 | } 308 | base.WndProc(ref m); 309 | } 310 | 311 | /// 312 | /// Can be called from any thread. 313 | /// 314 | public void Exit() 315 | { 316 | if (!mainLoopPaused) 317 | { 318 | mainLoopPaused = true; 319 | } 320 | this.exiting = true; 321 | } 322 | 323 | /// 324 | /// Can be called from any thread. 325 | /// 326 | public void Toggle() 327 | { 328 | this.mainLoopPaused = !mainLoopPaused; 329 | } 330 | 331 | /// 332 | /// Can be called from any thread. 333 | /// 334 | public void Enable() 335 | { 336 | this.mainLoopPaused = false; 337 | } 338 | 339 | /// 340 | /// Can be called from any thread. 341 | /// 342 | public void Disable() 343 | { 344 | this.mainLoopPaused = true; 345 | } 346 | 347 | /// 348 | /// Can be called from any thread. 349 | /// 350 | /// Returns true if the effect was found and set, false otherwise. 351 | public bool TrySetColorEffectByName(string colorEffectName) 352 | { 353 | var effect = Configuration.Current.ColorEffects.Where(x => x.Value.Description == colorEffectName); 354 | if (effect.Any()) 355 | { 356 | InvokeColorEffect(effect.First().Value); 357 | return true; 358 | } 359 | else 360 | { 361 | return false; 362 | } 363 | } 364 | 365 | private void ToggleColorEffect(bool fromNormal) 366 | { 367 | if (fromNormal) 368 | { 369 | if (Configuration.Current.SmoothToggles) 370 | { 371 | BuiltinMatrices.InterpolateColorEffect(BuiltinMatrices.Identity, currentMatrix); 372 | } 373 | else 374 | { 375 | BuiltinMatrices.ChangeColorEffect(currentMatrix); 376 | } 377 | } 378 | else 379 | { 380 | if (Configuration.Current.SmoothToggles) 381 | { 382 | BuiltinMatrices.InterpolateColorEffect(currentMatrix, BuiltinMatrices.Identity); 383 | } 384 | else 385 | { 386 | BuiltinMatrices.ChangeColorEffect(BuiltinMatrices.Identity); 387 | } 388 | } 389 | } 390 | 391 | /// 392 | /// Check if the magnification api is in a state where a color effect can be applied, then proceed. 393 | /// 394 | /// 395 | private void SafeChangeColorEffect(float[,] matrix) 396 | { 397 | if (!mainLoopPaused && !exiting) 398 | { 399 | try 400 | { 401 | if (Configuration.Current.SmoothTransitions) 402 | { 403 | BuiltinMatrices.InterpolateColorEffect(currentMatrix, matrix); 404 | } 405 | else 406 | { 407 | BuiltinMatrices.ChangeColorEffect(matrix); 408 | } 409 | } 410 | // Ignore ColorEffectChangeException, probably thrown because the Windows Magnifier has its color inversion enabled. 411 | catch (CannotChangeColorEffectException) 412 | { 413 | // But we don't change the current matrix. 414 | return; 415 | } 416 | } 417 | currentMatrix = matrix; 418 | } 419 | 420 | protected override void Dispose(bool disposing) 421 | { 422 | if (disposing && (components != null)) 423 | { 424 | components.Dispose(); 425 | UnregisterHotKeys(); 426 | NativeMethods.MagUninitialize(); 427 | } 428 | base.Dispose(disposing); 429 | } 430 | 431 | private void SynchronizeMenuItemCheckboxesWithEffect(ScreenColorEffect effect) 432 | { 433 | ToolStripMenuItem currentItem = null; 434 | foreach (ToolStripMenuItem effectItem in this.changeModeToolStripMenuItem.DropDownItems) 435 | { 436 | effectItem.Checked = false; // reset all the check boxes 437 | var castItem = (ScreenColorEffect)effectItem.Tag; 438 | if (castItem.Matrix == effect.Matrix) currentItem = effectItem; // TODO: should implement equality comparison... 439 | } 440 | if (currentItem != null) 441 | { 442 | currentItem.Checked = true; 443 | } 444 | } 445 | 446 | #region Event Handlers 447 | 448 | private void OverlayManager_FormClosed(object sender, FormClosedEventArgs e) 449 | { 450 | Exit(); 451 | } 452 | 453 | private void toggleInversionToolStripMenuItem_Click(object sender, EventArgs e) 454 | { 455 | Toggle(); 456 | } 457 | 458 | private void exitToolStripMenuItem_Click(object sender, EventArgs e) 459 | { 460 | Exit(); 461 | } 462 | 463 | private void editConfigurationToolStripMenuItem_Click(object sender, EventArgs e) 464 | { 465 | Configuration.UserEditCurrentConfiguration(); 466 | } 467 | 468 | private void trayIcon_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) 469 | { 470 | if (e.Button == System.Windows.Forms.MouseButtons.Left) 471 | { 472 | Toggle(); 473 | } 474 | } 475 | 476 | #endregion 477 | 478 | private void aboutToolStripMenuItem_Click(object sender, EventArgs e) 479 | { 480 | if (!aboutForm.Visible) 481 | { 482 | aboutForm.ShowDialog(); 483 | } 484 | } 485 | } 486 | } 487 | -------------------------------------------------------------------------------- /NegativeScreen/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2011-2017 Melvyn Laïly 2 | // https://zerowidthjoiner.net 3 | 4 | // This file is part of NegativeScreen. 5 | 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | using System; 20 | using System.Diagnostics; 21 | using System.IO; 22 | using System.Linq; 23 | using System.Windows.Forms; 24 | 25 | namespace NegativeScreen 26 | { 27 | internal class Program 28 | { 29 | [STAThread] 30 | private static void Main(string[] args) 31 | { 32 | AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); 33 | 34 | // check whether the current process is running under WoW64 mode 35 | if (NativeMethods.IsX86InWow64Mode()) 36 | { 37 | // see http://social.msdn.microsoft.com/Forums/en-US/windowsaccessibilityandautomation/thread/6cc761ea-8a54-4403-9cca-2fa8680f4409/ 38 | MessageBox.Show( 39 | @"You are trying to run this program on a 64 bits processor whereas it was compiled for a 32 bits processor. 40 | To avoid known bugs relative to the used APIs, please instead run the 64 bits compiled version.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); 41 | return; 42 | } 43 | 44 | // check Windows version 45 | // TODO: check whether the undocumented functions exist under Windows server 2008 (probably not) and R2 (probably yes) 46 | if (Environment.OSVersion.Version < new Version(6, 1)) 47 | { 48 | System.Windows.Forms.MessageBox.Show( 49 | @"Sorry, this version only works on Windows 7 and above. :/ 50 | There is a Vista version though. You can download it on 51 | http://x2a.yt?negativescreen", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); 52 | return; 53 | } 54 | 55 | // forces the working directory to be the one of the executable 56 | Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory; 57 | Configuration.Initialize(); 58 | 59 | // check whether aero is enabled 60 | if (Configuration.Current.ShowAeroWarning && !NativeMethods.DwmIsCompositionEnabled()) 61 | { 62 | var result = MessageBox.Show("Windows Aero must be enabled for this program to work properly!", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); 63 | if (result != DialogResult.OK) 64 | { 65 | return; 66 | } 67 | } 68 | // check whether the current application is already running 69 | if (IsAnotherInstanceAlreadyRunning(out Process aleadyRunningInstance)) 70 | { 71 | // There is no way to know which thread is the main thread (where the message loop is) 72 | // so we don't take any chance... 73 | foreach (ProcessThread thread in aleadyRunningInstance.Threads) 74 | { 75 | // The goal is to enable the already running instance color effect: 76 | NativeMethods.PostThreadMessage((uint)thread.Id, UserMessageFilter.WM_ENABLE_COLOR_EFFECT, UserMessageFilter.ExpectedParams, UserMessageFilter.ExpectedParams); 77 | } 78 | return; 79 | } 80 | // without this call, and with custom DPI settings, 81 | // the magnified window is either partially out of the screen, 82 | // or blurry, if the transformation scale is forced to 1. 83 | NativeMethods.SetProcessDPIAware(); 84 | 85 | Application.EnableVisualStyles(); 86 | Application.AddMessageFilter(new UserMessageFilter()); 87 | 88 | OverlayManager.Initialize(); 89 | 90 | if (Configuration.Current.EnableApi) 91 | { 92 | Api api = new Api(OverlayManager.Instance); 93 | Application.ApplicationExit += (s, e) => api.Exit(); 94 | } 95 | 96 | Application.Run(); 97 | } 98 | 99 | private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) 100 | { 101 | MessageBox.Show(e.ExceptionObject.ToString(), "Sorry, I'm bailing out!", MessageBoxButtons.OK, MessageBoxIcon.Error); 102 | } 103 | 104 | private static bool IsAnotherInstanceAlreadyRunning(out Process alreadyRunningInstance) 105 | { 106 | Process me = Process.GetCurrentProcess(); 107 | // Warning: the following call may return false positives 108 | // when a debugger is attached and IntelliTrace is enabled. 109 | Process[] processesWithSameName = Process.GetProcessesByName(me.ProcessName); 110 | foreach (Process process in processesWithSameName) 111 | { 112 | // same process name, was started from the same file name and location. 113 | if (process.Id != me.Id && process.MainModule.FileName == me.MainModule.FileName) 114 | { 115 | alreadyRunningInstance = process; 116 | return true; 117 | } 118 | } 119 | alreadyRunningInstance = null; 120 | return false; 121 | } 122 | } 123 | 124 | /// 125 | /// This class is required to intercept Windows messages sent via PostThreadMessage() 126 | /// as for unknown reasons, the overridden WndProc() of a never receives them... 127 | /// 128 | public class UserMessageFilter : IMessageFilter 129 | { 130 | public const int WM_ENABLE_COLOR_EFFECT = (int)WindowMessage.WM_APP + 42; 131 | public static readonly IntPtr ExpectedParams = new IntPtr(1337); 132 | 133 | public bool PreFilterMessage(ref Message m) 134 | { 135 | if (m.Msg == WM_ENABLE_COLOR_EFFECT && m.LParam == ExpectedParams && m.WParam == ExpectedParams && Configuration.Current.ActiveOnStartup) 136 | { 137 | // Handle a custom WM_ENABLE_COLOR_EFFECT message 138 | // so that NegativeScreen can be enabled from another process/instance. 139 | OverlayManager.Instance.Enable(); 140 | } 141 | return false; 142 | } 143 | } 144 | } -------------------------------------------------------------------------------- /NegativeScreen/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("NegativeScreen")] 9 | [assembly: AssemblyDescription( 10 | @"The original purpose of NegativeScreen was to simply invert your screen's colors. 11 | This can be useful, for example when using a computer in a dark room and the screen is dazzling you. 12 | 13 | The name stuck, but you can now use NegativeScreen to apply any color effect that can be modeled as a color transformation matrix. 14 | 15 | Home page and documentation: https://zerowidthjoiner.net/negativescreen 16 | Source code (GPL): https://github.com/mlaily/NegativeScreen/ 17 | ")] 18 | [assembly: AssemblyConfiguration("")] 19 | [assembly: AssemblyProduct("NegativeScreen")] 20 | [assembly: AssemblyCopyright("Copyright © Melvyn Laïly 2011-2018")] 21 | [assembly: AssemblyTrademark("")] 22 | [assembly: AssemblyCulture("")] 23 | 24 | // Setting ComVisible to false makes the types in this assembly not visible 25 | // to COM components. If you need to access a type in this assembly from 26 | // COM, set the ComVisible attribute to true on that type. 27 | [assembly: ComVisible(false)] 28 | 29 | // The following GUID is for the ID of the typelib if this project is exposed to COM 30 | [assembly: Guid("a25e2081-ba27-4751-959b-45dfa968c506")] 31 | 32 | // Version information for an assembly consists of the following four values: 33 | // 34 | // Major Version 35 | // Minor Version 36 | // Build Number 37 | // Revision 38 | // 39 | // You can specify all the values or you can default the Build and Revision Numbers 40 | // by using the '*' as shown below: 41 | // [assembly: AssemblyVersion("1.0.*")] 42 | [assembly: AssemblyVersion("2.6.*")] 43 | -------------------------------------------------------------------------------- /NegativeScreen/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace NegativeScreen.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("NegativeScreen.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). 65 | /// 66 | internal static System.Drawing.Icon Icon { 67 | get { 68 | object obj = ResourceManager.GetObject("Icon", resourceCulture); 69 | return ((System.Drawing.Icon)(obj)); 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /NegativeScreen/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 122 | ..\Icon.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 123 | 124 | -------------------------------------------------------------------------------- /NegativeScreen/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NegativeScreen # 2 | 3 | https://zerowidthjoiner.net/negativescreen 4 | 5 | *** 6 | 7 | ## Description 8 | 9 | NegativeScreen's main goal is to support your poor tearful eyes when enjoying the bright white interweb in a dark room. 10 | This task is joyfully achieved by inverting the colors of your screen. 11 | 12 | Unlike the Windows Magnifier, which is also capable of such color inversion, 13 | NegativeScreen was specifically designed to be easy and convenient to use. 14 | 15 | It comes with a minimal graphic interface in the form of a system tray icon with a context menu, 16 | but don't worry, this only makes it easier to use! 17 | 18 | 19 | ## Features 20 | 21 | Invert screen's colors. 22 | 23 | Additionally, many color effects can be applied. 24 | For example, different inversion modes, including "smart" modes, 25 | swapping blacks and whites while keeping colors (about) the sames. 26 | 27 | You can now configure the color effects manually via a configuration file. 28 | You can also configure the hot keys for every actions, using the same configuration file. 29 | 30 | A basic web api is part of NegativeScreen >= 2.5. 31 | It is disabled by default. When enabled, it listens by default on port 8990, localhost only. 32 | See the configuration file to enable the api or change the listening uri... 33 | 34 | All commands must be sent with the POST http method. 35 | The following commands are implemented: 36 | - TOGGLE 37 | - ENABLE 38 | - DISABLE 39 | - SET "Color effect name" (without the quotes) 40 | 41 | Any request sent with a method other than POST will not be interpreted, 42 | and a response containing the application version will be sent. 43 | 44 | 45 | ## Requirements 46 | 47 | NegativeScreen < 2.0 needs at least Windows Vista to run. 48 | 49 | Versions 2.0+ need at least Windows 7. 50 | 51 | Both run on Windows 8 or superior. 52 | 53 | Graphic acceleration (Aero) must be enabled. 54 | 55 | .NET 4.5 is required. (Should be available out of the box on up-to-date Windows installations) 56 | 57 | 58 | ## Default controls 59 | 60 | - Press Win+Alt+H to Halt the program immediately 61 | - Press Win+Alt+N to toggle color inversion (mnemonic: Night vision :)) 62 | - Press Win+Alt+F1-to-F11 to switch between inversion modes: 63 | * F1: standard inversion 64 | * F2: smart inversion1 - theoretical optimal transformation (but ugly desaturated pure colors) 65 | * F3: smart inversion2 - high saturation, good pure colors 66 | * F4: smart inversion3 - overall desaturated, yellows and blues plain bad. actually relaxing and very usable 67 | * F5: smart inversion4 - high saturation. yellows and blues plain bad. actually quite readable 68 | * F6: smart inversion5 - not so readable. good colors. (CMY colors a bit desaturated, still more saturated than normal) 69 | * F7: negative sepia 70 | * F8: negative gray scale 71 | * F9: negative red 72 | * F10: red 73 | * F11: grayscale 74 | 75 | 76 | ## Configuration file 77 | 78 | A customizable configuration file is created the first time you use "Edit Configuration" from the context menu. 79 | 80 | The default location for this file is next to NegativeScreen.exe, and is called "negativescreen.conf" 81 | 82 | If the default location is inaccessible, 83 | NegativeScreen will try to create the configuration file in %AppData%/NegativeScreen/negativescreen.conf 84 | 85 | This feature allows to deploy NegativeScreen.exe in a read-only location for unprivileged users. 86 | Each user can then have its own configuration file. 87 | 88 | The order of priority for trying to read a configuration file when starting NegativeScreen is as follows: 89 | - %AppData%/NegativeScreen/negativescreen.conf 90 | - negativescreen.conf in the directory where NegativeScreen.exe is located 91 | - If the above fails, the embedded default configuration is used 92 | 93 | Should something go wrong (syntax error, bad hot key...), you can simply delete the configuration file, 94 | the internal default configuration will be used. 95 | 96 | If the configuration file is missing, you can use the "Edit Configuration" menu to regenerate the default one. 97 | 98 | Syntax: see in the configuration file... 99 | 100 | 101 | *** 102 | 103 | Many thanks to Tom MacLeod who gave me the idea for the "smart" inversion mode :) 104 | 105 | 106 | Enjoy! 107 | -------------------------------------------------------------------------------- /TODO.txt: -------------------------------------------------------------------------------- 1 | To Do in next releases: 2 | 3 | auto-switch on light/dark | when browser on/off 4 | -------------------------------------------------------------------------------- /create-release.sh: -------------------------------------------------------------------------------- 1 | 2 | read -p "Please remove any previous 'release' folder before continuing..." 3 | 4 | mkdir release 5 | 6 | cp NegativeScreen/bin/Release/NegativeScreen.exe release/NegativeScreenX86.exe 7 | cp NegativeScreen/bin/x64/Release/NegativeScreen.exe release/NegativeScreen.exe 8 | cp CHANGELOG.txt release/ 9 | cp LICENSE.txt release/ 10 | cp README.md release/ 11 | 12 | zip -j Binary.zip release/* 13 | 14 | read -p "Now generating the chocolatey package. Press enter to proceed..." 15 | choco.exe pack Chocolatey/negativescreen.nuspec --out=Chocolatey/ 16 | --------------------------------------------------------------------------------