├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── README.md ├── appveyor.yml ├── dependencies ├── pfm │ ├── COPYING │ ├── config.hpp │ ├── include │ │ └── pfm │ │ │ ├── byte_order.hpp │ │ │ ├── color_pixel.hpp │ │ │ ├── pfm.hpp │ │ │ ├── pfm_input_file.hpp │ │ │ └── pfm_output_file.hpp │ ├── pfm_input_file.cpp │ └── pfm_output_file.cpp ├── pic │ ├── COPYING │ ├── config.hpp │ ├── include │ │ └── pic │ │ │ ├── pic.hpp │ │ │ ├── pic_input_file.hpp │ │ │ ├── pic_output_file.hpp │ │ │ └── pixel.hpp │ ├── pic_input_file.cpp │ └── pic_output_file.cpp └── tinyexr │ └── tinyexr.h ├── media ├── Close.png ├── CloseActive.png ├── Compare.png ├── CompareActive.png ├── Comparison.png ├── Default.png ├── FormatByte.png ├── FormatEXR.png ├── FormatHDR.png ├── FormatPFM.png ├── Icon.ico ├── Icons.svg ├── Open.png ├── Properties.png ├── Save.png ├── Screenshots.png ├── Settings.png ├── SingleInstance.png └── hdrv.rc ├── thumbnails ├── ClassFactory.cpp ├── ClassFactory.hpp ├── Registry.cpp ├── Registry.hpp ├── ThumbnailProvider.cpp ├── ThumbnailProvider.hpp ├── Thumbnails.cpp └── Thumbnails.hpp └── viewer ├── Main.cpp ├── image ├── Image.cpp └── Image.hpp ├── model ├── ImageCollection.cpp ├── ImageCollection.hpp ├── ImageDocument.cpp ├── ImageDocument.hpp ├── Settings.cpp └── Settings.hpp ├── qtquickcontrols2.conf ├── shader ├── RenderImage.frag └── RenderImage.vert ├── view ├── AppSettings.qml ├── ExportButton.qml ├── IPCClient.cpp ├── IPCClient.hpp ├── IPCServer.cpp ├── IPCServer.hpp ├── ImageArea.cpp ├── ImageArea.hpp ├── ImageProperties.qml ├── ImageRenderer.cpp ├── ImageRenderer.hpp ├── Main.qml └── TabNav.qml └── viewer.qrc /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | build-*/ 3 | *.pro.user* 4 | .vs 5 | .vscode 6 | CMakeSettings.json 7 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Acly/hdrv/0d68b52b8b25f8f67731f1ef41cce240c31e4031/.gitmodules -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | project(hdrv LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 17) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 COMPONENTS Core Quick Concurrent REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Quick Concurrent REQUIRED) 16 | 17 | add_library(pfm STATIC 18 | dependencies/pfm/pfm_input_file.cpp 19 | dependencies/pfm/pfm_output_file.cpp 20 | ) 21 | target_include_directories(pfm PUBLIC dependencies/pfm/include) 22 | 23 | add_library(pic STATIC 24 | dependencies/pic/pic_input_file.cpp 25 | dependencies/pic/pic_output_file.cpp 26 | ) 27 | target_include_directories(pic PUBLIC dependencies/pic/include) 28 | 29 | add_library(tinyexr INTERFACE) 30 | target_include_directories(tinyexr INTERFACE dependencies/tinyexr) 31 | 32 | add_executable(hdrv WIN32 33 | viewer/Main.cpp 34 | viewer/viewer.qrc 35 | viewer/image/Image.cpp 36 | viewer/image/Image.hpp 37 | viewer/model/ImageCollection.cpp 38 | viewer/model/ImageCollection.hpp 39 | viewer/model/ImageDocument.cpp 40 | viewer/model/ImageDocument.hpp 41 | viewer/model/Settings.cpp 42 | viewer/model/Settings.hpp 43 | viewer/view/ImageArea.cpp 44 | viewer/view/ImageArea.hpp 45 | viewer/view/ImageRenderer.cpp 46 | viewer/view/ImageRenderer.hpp 47 | viewer/view/IPCClient.cpp 48 | viewer/view/IPCClient.hpp 49 | viewer/view/IPCServer.cpp 50 | viewer/view/IPCServer.hpp 51 | $<$:media/hdrv.rc> 52 | ) 53 | target_include_directories(hdrv PRIVATE viewer) 54 | target_compile_definitions(hdrv PRIVATE NOMINMAX $<$:QT_QML_DEBUG>) 55 | target_link_libraries(hdrv PRIVATE pfm pic tinyexr Qt6::Core Qt6::Quick Qt6::Concurrent) 56 | 57 | if (WIN32) 58 | 59 | add_library(thumbnails SHARED 60 | thumbnails/ClassFactory.cpp 61 | thumbnails/ClassFactory.hpp 62 | thumbnails/Registry.cpp 63 | thumbnails/Registry.hpp 64 | thumbnails/ThumbnailProvider.cpp 65 | thumbnails/ThumbnailProvider.hpp 66 | thumbnails/Thumbnails.cpp 67 | thumbnails/Thumbnails.hpp 68 | viewer/image/Image.cpp 69 | viewer/image/Image.hpp 70 | ) 71 | target_include_directories(thumbnails PRIVATE viewer thumbnails) 72 | target_compile_definitions(thumbnails PRIVATE NOMINMAX) 73 | target_link_libraries(thumbnails PRIVATE pfm pic tinyexr Qt6::Core Qt6::Gui) 74 | 75 | endif(WIN32) 76 | 77 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HDR Viewer 2 | 3 | GUI which displays HDR images, no bullshit. 4 | 5 | ![Screenshots](/media/Screenshots.png?raw=true) 6 | 7 | ## Features 8 | 9 | * Opens popular HDR image formats: Radiance PIC (_*.pic, *.hdr_), PFM (_*.pfm, *.ppm_), OpenEXR (_*.exr_) 10 | * Exports images in Radiance PIC, PFM or OpenEXR format 11 | * Fast zoom, pan and brightness control 12 | * Manage multiple image documents in tabs 13 | * Compare opened images (absolute difference or side-by-side) 14 | * Thumbnails in Windows shell 15 | 16 | ## Build 17 | 18 | ![AppVeyorBuildStatus](https://ci.appveyor.com/api/projects/status/github/Acly/hdrv?branch=master&svg=true) 19 | 20 | ### Prerequisites 21 | * C++ 17 compiler 22 | * CMake 23 | * Qt 6 24 | 25 | ### Checkout 26 | 27 | ``` 28 | git clone https://github.com/Acly/hdrv.git hdrv 29 | ``` 30 | 31 | ### Configure and Build with CMake 32 | Build from the command line using the typical CMake workflow. 33 | ``` 34 | mkdir build 35 | cd build 36 | cmake .. 37 | cmake --build . 38 | ``` 39 | 40 | ### Windows - Visual Studio 2019 41 | Open the folder in Visual Studio to configure and build using its CMake/Ninja integration. 42 | 43 | If Qt6 is not found automatically you can add its location to the CMake command line with eg. `-DCMAKE_PREFIX_PATH=C:\Qt\6.0.0\msvc2019_64`. 44 | 45 | After building, runtime libraries can be copied with `windeployqt --qmldir viewer/view build/release/hdrv.exe`. 46 | 47 | ### Linux 48 | 49 | If Qt6 is not found automatically you can add its location to the CMake command line with eg. `-DCMAKE_PREFIX_PATH=$HOME/Qt/6.0.0/gcc_64`. 50 | 51 | ## Use 52 | 53 | Load images by supplying them as arguments to the hdrv executable, drag-and-drop them into the viewer or 54 | use the _Open image_ button in the tab bar. 55 | 56 | ### Mouse controls 57 | 58 | * \[ **Pan** \] Hold the left mouse button to view different regions of the image if it does not fit on the screen. 59 | * \[ **Zoom** \] Use the mouse wheel to scale the image. 60 | * \[ **Compare** \] Hold the right mouse button in comparison mode to move the image comparison separator. 61 | 62 | ### Keyboard shortcuts 63 | 64 | * \[ **+**/**-** \] Increase / decrease the image brightness. 65 | * \[ **Left**/**Right** \] Iterate through images in the current folder. 66 | * \[ **1**/**2**/**3**/... \] Switch to image tab 1, 2, 3, ... 67 | * \[ **S** \] Toggle between the last two image tabs. 68 | * \[ **C** \] Open comparison mode for the last two images. 69 | * \[ **R** \] Reset positioning and scaling of the image. 70 | 71 | ### Thumbnails 72 | 73 | A thumbnail shell integration is present for Windows in the subproject _thumbnails_. 74 | On x86 Windows installations the project must be compiled as x86 target and vice versa for x64 Windows installations to be compatible. 75 | 76 | You can use the buttons in the UI to (un)install the thumbnail handler. 77 | Note that you should not move/delete the `thumbnails.dll` without uninstalling it beforehand. 78 | 79 | To register the extension manually use an **elevated shell** and type: 80 | ``` 81 | regsvr32 thumbnails.dll 82 | ``` 83 | Removing the extension works by adding `/u` to the command: 84 | ``` 85 | regsvr32 /u thumbnails.dll 86 | ``` 87 | 88 | ## TODO 89 | 90 | * Show more stats (average / maximum / minimum color) 91 | * More options for tone mapping 92 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 0.7.{build} 2 | skip_tags: true 3 | image: 4 | - Visual Studio 2019 5 | - Ubuntu2004 6 | configuration: Release 7 | platform: x64 8 | environment: 9 | CC: /usr/bin/gcc-9 10 | CXX: /usr/bin/g++-9 11 | install: 12 | - sh: sudo apt update 13 | - sh: sudo apt-get -y install libgl1-mesa-dev 14 | before_build: 15 | - mkdir build 16 | - cd build 17 | - cmd: cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_PREFIX_PATH=C:\Qt\6.0.0\msvc2019_64 .. 18 | - sh: cmake -DCMAKE_PREFIX_PATH=$HOME/Qt/6.0.0/gcc_64 .. 19 | build_script: 20 | - cmake --build . --config Release 21 | -------------------------------------------------------------------------------- /dependencies/pfm/COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Library General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License 307 | along with this program; if not, write to the Free Software 308 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 309 | 310 | 311 | Also add information on how to contact you by electronic and paper mail. 312 | 313 | If the program is interactive, make it output a short notice like this 314 | when it starts in an interactive mode: 315 | 316 | Gnomovision version 69, Copyright (C) year name of author 317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 318 | This is free software, and you are welcome to redistribute it 319 | under certain conditions; type `show c' for details. 320 | 321 | The hypothetical commands `show w' and `show c' should show the appropriate 322 | parts of the General Public License. Of course, the commands you use may 323 | be called something other than `show w' and `show c'; they could even be 324 | mouse-clicks or menu items--whatever suits your program. 325 | 326 | You should also get your employer (if you work as a programmer) or your 327 | school, if any, to sign a "copyright disclaimer" for the program, if 328 | necessary. Here is a sample; alter the names: 329 | 330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 332 | 333 | , 1 April 1989 334 | Ty Coon, President of Vice 335 | 336 | This General Public License does not permit incorporating your program into 337 | proprietary programs. If your program is a subroutine library, you may 338 | consider it more useful to permit linking proprietary applications with the 339 | library. If this is what you want to do, use the GNU Library General 340 | Public License instead of this License. 341 | -------------------------------------------------------------------------------- /dependencies/pfm/config.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _PFM_CONFIG_HPP 2 | #define _PFM_CONFIG_HPP 1 3 | 4 | /* pfm/config.hpp. Generated automatically at end of configure. */ 5 | /* config.h. Generated from config.h.in by configure. */ 6 | /* config.h.in. Generated from configure.ac by autoheader. */ 7 | 8 | /* Define to 1 if you have the header file. */ 9 | #ifndef PFM_HAVE_DLFCN_H 10 | #define PFM_HAVE_DLFCN_H 1 11 | #endif 12 | 13 | /* Define to 1 if you have the header file. */ 14 | #ifndef PFM_HAVE_INTTYPES_H 15 | #define PFM_HAVE_INTTYPES_H 1 16 | #endif 17 | 18 | /* Define to 1 if you have the header file. */ 19 | #ifndef PFM_HAVE_MEMORY_H 20 | #define PFM_HAVE_MEMORY_H 1 21 | #endif 22 | 23 | /* Define to 1 if stdbool.h conforms to C99. */ 24 | #ifndef PFM_HAVE_STDBOOL_H 25 | #define PFM_HAVE_STDBOOL_H 1 26 | #endif 27 | 28 | /* Define to 1 if you have the header file. */ 29 | #ifndef PFM_HAVE_STDINT_H 30 | #define PFM_HAVE_STDINT_H 1 31 | #endif 32 | 33 | /* Define to 1 if you have the header file. */ 34 | #ifndef PFM_HAVE_STDLIB_H 35 | #define PFM_HAVE_STDLIB_H 1 36 | #endif 37 | 38 | /* Define to 1 if you have the header file. */ 39 | #ifndef PFM_HAVE_STRINGS_H 40 | #define PFM_HAVE_STRINGS_H 1 41 | #endif 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #ifndef PFM_HAVE_STRING_H 45 | #define PFM_HAVE_STRING_H 1 46 | #endif 47 | 48 | /* Define to 1 if you have the header file. */ 49 | #ifndef PFM_HAVE_SYS_STAT_H 50 | #define PFM_HAVE_SYS_STAT_H 1 51 | #endif 52 | 53 | /* Define to 1 if you have the header file. */ 54 | #ifndef PFM_HAVE_SYS_TYPES_H 55 | #define PFM_HAVE_SYS_TYPES_H 1 56 | #endif 57 | 58 | /* Define to 1 if you have the header file. */ 59 | #ifndef PFM_HAVE_UNISTD_H 60 | #define PFM_HAVE_UNISTD_H 1 61 | #endif 62 | 63 | /* Define to 1 if the system has the type `_Bool'. */ 64 | /* #undef HAVE__BOOL */ 65 | 66 | /* Name of package */ 67 | #ifndef PFM_PACKAGE 68 | #define PFM_PACKAGE "pfm" 69 | #endif 70 | 71 | /* Author of package */ 72 | #ifndef PFM_PACKAGE_AUTHOR 73 | #define PFM_PACKAGE_AUTHOR "Ares Lagae" 74 | #endif 75 | 76 | /* Define to the address where bug reports for this package should be sent. */ 77 | #ifndef PFM_PACKAGE_BUGREPORT 78 | #define PFM_PACKAGE_BUGREPORT "ares.lagae@cs.kuleuven.be" 79 | #endif 80 | 81 | /* Define to the full name of this package. */ 82 | #ifndef PFM_PACKAGE_NAME 83 | #define PFM_PACKAGE_NAME "pfm" 84 | #endif 85 | 86 | /* Define to the full name and version of this package. */ 87 | #ifndef PFM_PACKAGE_STRING 88 | #define PFM_PACKAGE_STRING "pfm 0.1" 89 | #endif 90 | 91 | /* Define to the one symbol short name of this package. */ 92 | #ifndef PFM_PACKAGE_TARNAME 93 | #define PFM_PACKAGE_TARNAME "pfm" 94 | #endif 95 | 96 | /* Define to the version of this package. */ 97 | #ifndef PFM_PACKAGE_VERSION 98 | #define PFM_PACKAGE_VERSION "0.1" 99 | #endif 100 | 101 | /* Define to 1 if you have the ANSI C header files. */ 102 | /* #undef STDC_HEADERS */ 103 | 104 | /* Version number of package */ 105 | #ifndef PFM_VERSION 106 | #define PFM_VERSION "0.1" 107 | #endif 108 | 109 | /* Define to empty if `const' does not conform to ANSI C. */ 110 | /* #undef const */ 111 | 112 | /* Define to `unsigned int' if does not define. */ 113 | /* #undef size_t */ 114 | 115 | /* once: _PFM_CONFIG_HPP */ 116 | #endif 117 | -------------------------------------------------------------------------------- /dependencies/pfm/include/pfm/byte_order.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PFM_BYTE_ORDER_HPP_INCLUDED 2 | #define PFM_BYTE_ORDER_HPP_INCLUDED 3 | 4 | #include 5 | 6 | namespace pfm { 7 | 8 | #if defined(PFM_BIG_ENDIAN) || defined(PFM_LITTLE_ENDIAN) 9 | # error 10 | #endif 11 | 12 | #if (defined(__powerpc) || defined(__powerpc__) || defined(__POWERPC__) || defined(__ppc__) || defined(_M_PPC) || defined(__ARCH_PPC)) 13 | # define PFM_BIG_ENDIAN 14 | #elif (defined(i386) || defined(__i386__) || defined(__i386) || defined(_M_IX86) || defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__) || defined(__INTEL__)) \ 15 | || (defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64)) 16 | # define PFM_LITTLE_ENDIAN 17 | #else 18 | # error 19 | #endif 20 | 21 | typedef int byte_order_type; 22 | enum byte_order_enum 23 | { 24 | little_endian_byte_order, 25 | big_endian_byte_order, 26 | #if defined(PFM_BIG_ENDIAN) 27 | host_byte_order = big_endian_byte_order 28 | #elif defined(PFM_LITTLE_ENDIAN) 29 | host_byte_order = little_endian_byte_order 30 | #else 31 | # error 32 | #endif 33 | }; 34 | 35 | #undef PFM_BIG_ENDIAN 36 | #undef PFM_LITTLE_ENDIAN 37 | 38 | void swap_byte_order(float_type& value); 39 | 40 | } // namespace pfm 41 | 42 | inline void pfm::swap_byte_order(float_type& value) 43 | { 44 | typedef unsigned char uint8_t; 45 | uint8_t* bytes = reinterpret_cast(&value); 46 | std::swap(bytes[0], bytes[3]); 47 | std::swap(bytes[1], bytes[2]); 48 | } 49 | 50 | #endif // PFM_BYTE_ORDER_HPP_INCLUDED 51 | -------------------------------------------------------------------------------- /dependencies/pfm/include/pfm/color_pixel.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PFM_COLOR_PIXEL_HPP_INCLUDED 2 | #define PFM_COLOR_PIXEL_HPP_INCLUDED 3 | 4 | #include 5 | 6 | namespace pfm { 7 | 8 | class color_pixel 9 | { 10 | public: 11 | typedef float_type value_type; 12 | typedef std::size_t size_type; 13 | color_pixel(); 14 | color_pixel(value_type, value_type, value_type); 15 | explicit color_pixel(value_type); 16 | const value_type& operator[](size_type) const; 17 | value_type& operator[](size_type); 18 | private: 19 | value_type rgb_[3]; 20 | }; 21 | 22 | bool operator==(const color_pixel&, const color_pixel&); 23 | bool operator!=(const color_pixel&, const color_pixel&); 24 | template std::basic_ostream& operator<<(std::basic_ostream&, const color_pixel&); 25 | template std::basic_istream& operator>>(std::basic_istream&, color_pixel&); 26 | 27 | } // namespace pfm 28 | 29 | #include 30 | 31 | inline pfm::color_pixel::color_pixel() 32 | { 33 | } 34 | 35 | inline pfm::color_pixel::color_pixel(value_type r, value_type g, value_type b) 36 | { 37 | rgb_[0] = r; 38 | rgb_[1] = g; 39 | rgb_[2] = b; 40 | } 41 | 42 | inline pfm::color_pixel::color_pixel(value_type rgb) 43 | { 44 | rgb_[0] = rgb; 45 | rgb_[1] = rgb; 46 | rgb_[2] = rgb; 47 | } 48 | 49 | inline const pfm::color_pixel::value_type& pfm::color_pixel::operator[](size_type index) const 50 | { 51 | assert(index < 3); 52 | return rgb_[index]; 53 | } 54 | 55 | inline pfm::color_pixel::value_type& pfm::color_pixel::operator[](size_type index) 56 | { 57 | assert(index < 3); 58 | return rgb_[index]; 59 | } 60 | 61 | inline bool pfm::operator==(const color_pixel& lhs, const color_pixel& rhs) 62 | { 63 | return (lhs[0] == rhs[0]) && (lhs[1] == rhs[1]) && (lhs[2] == rhs[2]); 64 | } 65 | 66 | inline bool pfm::operator!=(const color_pixel& lhs, const color_pixel& rhs) 67 | { 68 | return !(lhs == rhs); 69 | } 70 | 71 | template 72 | inline std::basic_ostream& pfm::operator<<(std::basic_ostream& ostream, const color_pixel& p) 73 | { 74 | return ostream << p[0] << ' ' << p[1] << ' ' << p[2]; 75 | } 76 | 77 | template 78 | inline std::basic_istream& pfm::operator>>(std::basic_istream& istream, color_pixel& p) 79 | { 80 | return istream >> p[0] >> p[1] >> p[2]; 81 | } 82 | 83 | #endif // PFM_COLOR_PIXEL_HPP_INCLUDED 84 | -------------------------------------------------------------------------------- /dependencies/pfm/include/pfm/pfm.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PFM_PFM_HPP_INCLUDED 2 | #define PFM_PFM_HPP_INCLUDED 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace pfm { 9 | 10 | typedef int format_type; 11 | enum format_enum { color_format, grayscale_format }; 12 | 13 | typedef float float_type; 14 | 15 | typedef float_type grayscale_pixel; 16 | 17 | class runtime_error : public std::runtime_error { 18 | public: 19 | explicit runtime_error(const std::string& what); 20 | }; 21 | 22 | } // namespace pfm 23 | 24 | inline pfm::runtime_error::runtime_error(const std::string& what) 25 | : std::runtime_error(what) 26 | { 27 | } 28 | 29 | #endif // PFM_PFM_HPP_INCLUDED 30 | -------------------------------------------------------------------------------- /dependencies/pfm/include/pfm/pfm_input_file.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PFM_PFM_INPUT_FILE_HPP_INCLUDED 2 | #define PFM_PFM_INPUT_FILE_HPP_INCLUDED 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace pfm { 11 | 12 | class pfm_input_file 13 | { 14 | public: 15 | pfm_input_file(std::istream& istream); 16 | void read_header(format_type& format, std::size_t& width, std::size_t& height, byte_order_type& byte_order, double& scale); 17 | void read_color_scanline(color_pixel* scanline, std::size_t length); 18 | void read_grayscale_scanline(grayscale_pixel* scanline, std::size_t length); 19 | private: 20 | std::istream& istream_; 21 | format_type format_; 22 | std::size_t width_; 23 | std::size_t height_; 24 | byte_order_type byte_order_; 25 | double scale_; 26 | }; 27 | 28 | } // namespace pfm 29 | 30 | inline pfm::pfm_input_file::pfm_input_file(std::istream& istream) 31 | : istream_(istream) 32 | { 33 | } 34 | 35 | #endif // PFM_PFM_INPUT_FILE_HPP_INCLUDED 36 | -------------------------------------------------------------------------------- /dependencies/pfm/include/pfm/pfm_output_file.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PFM_PFM_OUTPUT_FILE_HPP_INCLUDED 2 | #define PFM_PFM_OUTPUT_FILE_HPP_INCLUDED 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace pfm { 11 | 12 | class pfm_output_file 13 | { 14 | public: 15 | pfm_output_file(std::ostream& ostream); 16 | void write_header(format_type format, std::size_t width, std::size_t height, byte_order_type byte_order, double scale); 17 | void write_color_scanline(const color_pixel* scanline, std::size_t length); 18 | void write_grayscale_scanline(const grayscale_pixel* scanline, std::size_t length); 19 | private: 20 | std::ostream& ostream_; 21 | format_type format_; 22 | std::size_t width_; 23 | std::size_t height_; 24 | byte_order_type byte_order_; 25 | double scale_; 26 | }; 27 | 28 | } // namespace pfm 29 | 30 | inline pfm::pfm_output_file::pfm_output_file(std::ostream& ostream) 31 | : ostream_(ostream) 32 | { 33 | } 34 | 35 | #endif // PFM_PFM_OUTPUT_FILE_HPP_INCLUDED 36 | -------------------------------------------------------------------------------- /dependencies/pfm/pfm_input_file.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #ifdef PFM_DEBUG 8 | # include 9 | #endif 10 | 11 | void pfm::pfm_input_file::read_header(format_type& format, std::size_t& width, std::size_t& height, byte_order_type& byte_order, double& scale) 12 | { 13 | std::size_t line_number = 1; 14 | char whitespace; 15 | 16 | // identifier 17 | const std::size_t identifier_size = 2; 18 | char identifier[identifier_size]; 19 | istream_.read(identifier, identifier_size); 20 | if (!istream_) { 21 | throw pfm::runtime_error(std::string("pfm: error: ") + __FUNCTION__); 22 | } 23 | if (!istream_ || (identifier[0] != 'P') || ((identifier[1] != 'F') && (identifier[1] != 'f'))) { 24 | #ifdef PFM_DEBUG 25 | std::cerr << "pfm: " << line_number << ": " << "error" << std::endl; 26 | #endif 27 | throw pfm::runtime_error(std::string("pfm: error: ") + __FUNCTION__); 28 | } 29 | #ifdef PFM_DEBUG 30 | std::cerr << "pfm: " << line_number << ": " << "info: " << std::string(identifier, 2) << std::endl; 31 | #endif 32 | format_ = identifier[1] == 'F' ? color_format : grayscale_format; 33 | 34 | // whitespace 35 | istream_.get(whitespace); 36 | if (!istream_ || !std::isspace(whitespace)) { 37 | #ifdef PFM_DEBUG 38 | std::cerr << "pfm: " << line_number << ": " << "error" << std::endl; 39 | #endif 40 | throw pfm::runtime_error(std::string("pfm: error: ") + __FUNCTION__); 41 | } 42 | if (whitespace == '\n') { 43 | ++line_number; 44 | } 45 | 46 | // width 47 | istream_ >> width_; 48 | if (!istream_ || (width_ == 0)) { 49 | #ifdef PFM_DEBUG 50 | std::cerr << "pfm: " << line_number << ": " << "error" << std::endl; 51 | #endif 52 | throw pfm::runtime_error(std::string("pfm: error: ") + __FUNCTION__); 53 | } 54 | #ifdef PFM_DEBUG 55 | std::cerr << "pfm: " << line_number << ": " << "info: " << width_ << std::endl; 56 | #endif 57 | 58 | // blank 59 | char blank; 60 | istream_.get(blank); 61 | if (!istream_ || (blank != ' ')) { 62 | #ifdef PFM_DEBUG 63 | std::cerr << "pfm: " << line_number << ": " << "error" << std::endl; 64 | #endif 65 | throw pfm::runtime_error(std::string("pfm: error: ") + __FUNCTION__); 66 | } 67 | 68 | // height 69 | istream_ >> height_; 70 | if (!istream_ || (height_ == 0)) { 71 | #ifdef PFM_DEBUG 72 | std::cerr << "pfm: " << line_number << ": " << "error" << std::endl; 73 | #endif 74 | throw pfm::runtime_error(std::string("pfm: error: ") + __FUNCTION__); 75 | } 76 | #ifdef PFM_DEBUG 77 | std::cerr << "pfm: " << line_number << ": " << "info: " << height_ << std::endl; 78 | #endif 79 | 80 | // whitespace 81 | istream_.get(whitespace); 82 | if (!istream_ || !std::isspace(whitespace)) { 83 | #ifdef PFM_DEBUG 84 | std::cerr << "pfm: " << line_number << ": " << "error" << std::endl; 85 | #endif 86 | throw pfm::runtime_error(std::string("pfm: error: ") + __FUNCTION__); 87 | } 88 | if (whitespace == '\n') { 89 | ++line_number; 90 | } 91 | 92 | // byte_order and scale 93 | double byte_order_and_scale; 94 | istream_ >> byte_order_and_scale; 95 | if (!istream_ || (byte_order_and_scale == 0.0)) { 96 | #ifdef PFM_DEBUG 97 | std::cerr << "pfm: " << line_number << ": " << "error" << std::endl; 98 | #endif 99 | throw pfm::runtime_error(std::string("pfm: error: ") + __FUNCTION__); 100 | } 101 | #ifdef PFM_DEBUG 102 | std::cerr << "pfm: " << line_number << ": " << "info: " << byte_order_and_scale << std::endl; 103 | #endif 104 | if (byte_order_and_scale < 0.0) { 105 | byte_order_ = little_endian_byte_order; 106 | scale_ = -byte_order_and_scale; 107 | } 108 | else { 109 | byte_order_ = big_endian_byte_order; 110 | scale_ = byte_order_and_scale; 111 | } 112 | 113 | // whitespace 114 | istream_.get(whitespace); 115 | if (!istream_ || !std::isspace(whitespace)) { 116 | #ifdef PFM_DEBUG 117 | std::cerr << "pfm: " << line_number << ": " << "error" << std::endl; 118 | #endif 119 | throw pfm::runtime_error(std::string("pfm: error: ") + __FUNCTION__); 120 | } 121 | if (whitespace == '\n') { 122 | ++line_number; 123 | } 124 | 125 | format = format_; 126 | width = width_; 127 | height = height_; 128 | byte_order = byte_order_; 129 | scale = scale_; 130 | } 131 | 132 | void pfm::pfm_input_file::read_color_scanline(color_pixel* scanline, std::size_t length) 133 | { 134 | assert(format_ == color_format); 135 | assert(scanline != 0); 136 | assert(length == width_); 137 | 138 | color_pixel* scanline_begin = scanline; 139 | color_pixel* scanline_end = scanline_begin + length; 140 | for (color_pixel* scanline_iterator = scanline_begin; scanline_iterator != scanline_end; ++scanline_iterator) { 141 | color_pixel& pixel = *scanline_iterator; 142 | istream_.read(reinterpret_cast(&pixel[0]), 4); 143 | if (!istream_) { 144 | #ifdef PFM_DEBUG 145 | std::cerr << istream_.tellg() << ": " << "error: " << std::endl; 146 | #endif 147 | throw pfm::runtime_error(std::string("pfm: error: ") + __FUNCTION__); 148 | } 149 | if (byte_order_ != host_byte_order) { 150 | swap_byte_order(pixel[0]); 151 | } 152 | istream_.read(reinterpret_cast(&pixel[1]), 4); 153 | if (!istream_) { 154 | #ifdef PFM_DEBUG 155 | std::cerr << istream_.tellg() << ": " << "error: " << std::endl; 156 | #endif 157 | throw pfm::runtime_error(std::string("pfm: error: ") + __FUNCTION__); 158 | } 159 | if (byte_order_ != host_byte_order) { 160 | swap_byte_order(pixel[1]); 161 | } 162 | istream_.read(reinterpret_cast(&pixel[2]), 4); 163 | if (!istream_) { 164 | #ifdef PFM_DEBUG 165 | std::cerr << istream_.tellg() << ": " << "error: " << std::endl; 166 | #endif 167 | throw pfm::runtime_error(std::string("pfm: error: ") + __FUNCTION__); 168 | } 169 | if (byte_order_ != host_byte_order) { 170 | swap_byte_order(pixel[2]); 171 | } 172 | } 173 | } 174 | 175 | void pfm::pfm_input_file::read_grayscale_scanline(grayscale_pixel* scanline, std::size_t length) 176 | { 177 | assert(format_ == grayscale_format); 178 | assert(scanline != 0); 179 | assert(length == width_); 180 | 181 | grayscale_pixel* scanline_begin = scanline; 182 | grayscale_pixel* scanline_end = scanline_begin + length; 183 | for (grayscale_pixel* scanline_iterator = scanline_begin; scanline_iterator != scanline_end; ++scanline_iterator) { 184 | grayscale_pixel& pixel = *scanline_iterator; 185 | istream_.read(reinterpret_cast(&pixel), 4); 186 | if (!istream_) { 187 | #ifdef PFM_DEBUG 188 | std::cerr << istream_.tellg() << ": " << "error: " << std::endl; 189 | #endif 190 | throw pfm::runtime_error(std::string("pfm: error: ") + __FUNCTION__); 191 | } 192 | if (byte_order_ != host_byte_order) { 193 | swap_byte_order(pixel); 194 | } 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /dependencies/pfm/pfm_output_file.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #ifdef PFM_DEBUG 6 | # include 7 | #endif 8 | 9 | void pfm::pfm_output_file::write_header(format_type format, std::size_t width, std::size_t height, byte_order_type byte_order, double scale) 10 | { 11 | assert((format == color_format) || (format == grayscale_format)); 12 | assert(width > 0); 13 | assert(height > 0); 14 | assert((byte_order == little_endian_byte_order) || (byte_order == big_endian_byte_order)); 15 | assert(scale > 0.0); 16 | 17 | ostream_ << (format == color_format ? "PF" : "Pf") << "\n"; 18 | ostream_ << width << " " << height << "\n"; 19 | ostream_ << (byte_order == big_endian_byte_order ? scale : -scale) << "\n"; 20 | 21 | if (!ostream_) { 22 | #ifdef PFM_DEBUG 23 | std::cerr << ostream_.tellp() << ": " << "error: " << std::endl; 24 | #endif 25 | throw pfm::runtime_error(std::string("pfm: error: ") + __FUNCTION__); 26 | } 27 | 28 | format_ = format; 29 | width_ = width; 30 | height_ = height; 31 | byte_order_ = byte_order; 32 | scale_ = scale; 33 | } 34 | 35 | void pfm::pfm_output_file::write_color_scanline(const color_pixel* scanline, std::size_t length) 36 | { 37 | assert(format_ == color_format); 38 | assert(scanline != 0); 39 | assert(length == width_); 40 | 41 | const color_pixel* scanline_begin = scanline; 42 | const color_pixel* scanline_end = scanline_begin + length; 43 | for (const color_pixel* scanline_iterator = scanline_begin; scanline_iterator != scanline_end; ++scanline_iterator) { 44 | color_pixel pixel = *scanline_iterator; 45 | if (byte_order_ != host_byte_order) { 46 | swap_byte_order(pixel[0]); 47 | } 48 | ostream_.write(reinterpret_cast(&pixel[0]), 4); 49 | if (!ostream_) { 50 | #ifdef PFM_DEBUG 51 | std::cerr << istream_.tellp() << ": " << "error: " << std::endl; 52 | #endif 53 | throw pfm::runtime_error(std::string("pfm: error: ") + __FUNCTION__); 54 | } 55 | if (byte_order_ != host_byte_order) { 56 | swap_byte_order(pixel[1]); 57 | } 58 | ostream_.write(reinterpret_cast(&pixel[1]), 4); 59 | if (!ostream_) { 60 | #ifdef PFM_DEBUG 61 | std::cerr << istream_.tellp() << ": " << "error: " << std::endl; 62 | #endif 63 | throw pfm::runtime_error(std::string("pfm: error: ") + __FUNCTION__); 64 | } 65 | if (byte_order_ != host_byte_order) { 66 | swap_byte_order(pixel[2]); 67 | } 68 | ostream_.write(reinterpret_cast(&pixel[2]), 4); 69 | if (!ostream_) { 70 | #ifdef PFM_DEBUG 71 | std::cerr << istream_.tellp() << ": " << "error: " << std::endl; 72 | #endif 73 | throw pfm::runtime_error(std::string("pfm: error: ") + __FUNCTION__); 74 | } 75 | } 76 | } 77 | 78 | void pfm::pfm_output_file::write_grayscale_scanline(const grayscale_pixel* scanline, std::size_t length) 79 | { 80 | assert(format_ == grayscale_format); 81 | assert(scanline != 0); 82 | assert(length == width_); 83 | 84 | const grayscale_pixel* scanline_begin = scanline; 85 | const grayscale_pixel* scanline_end = scanline_begin + length; 86 | for (const grayscale_pixel* scanline_iterator = scanline_begin; scanline_iterator != scanline_end; ++scanline_iterator) { 87 | grayscale_pixel pixel = *scanline_iterator; 88 | if (byte_order_ != host_byte_order) { 89 | swap_byte_order(pixel); 90 | } 91 | ostream_.write(reinterpret_cast(&pixel), 4); 92 | if (!ostream_) { 93 | #ifdef PFM_DEBUG 94 | std::cerr << istream_.tellp() << ": " << "error: " << std::endl; 95 | #endif 96 | throw pfm::runtime_error(std::string("pfm: error: ") + __FUNCTION__); 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /dependencies/pic/COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Library General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License 307 | along with this program; if not, write to the Free Software 308 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 309 | 310 | 311 | Also add information on how to contact you by electronic and paper mail. 312 | 313 | If the program is interactive, make it output a short notice like this 314 | when it starts in an interactive mode: 315 | 316 | Gnomovision version 69, Copyright (C) year name of author 317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 318 | This is free software, and you are welcome to redistribute it 319 | under certain conditions; type `show c' for details. 320 | 321 | The hypothetical commands `show w' and `show c' should show the appropriate 322 | parts of the General Public License. Of course, the commands you use may 323 | be called something other than `show w' and `show c'; they could even be 324 | mouse-clicks or menu items--whatever suits your program. 325 | 326 | You should also get your employer (if you work as a programmer) or your 327 | school, if any, to sign a "copyright disclaimer" for the program, if 328 | necessary. Here is a sample; alter the names: 329 | 330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 332 | 333 | , 1 April 1989 334 | Ty Coon, President of Vice 335 | 336 | This General Public License does not permit incorporating your program into 337 | proprietary programs. If your program is a subroutine library, you may 338 | consider it more useful to permit linking proprietary applications with the 339 | library. If this is what you want to do, use the GNU Library General 340 | Public License instead of this License. 341 | -------------------------------------------------------------------------------- /dependencies/pic/config.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _PIC_CONFIG_HPP 2 | #define _PIC_CONFIG_HPP 1 3 | 4 | /* pic/config.hpp. Generated automatically at end of configure. */ 5 | /* config.h. Generated from config.h.in by configure. */ 6 | /* config.h.in. Generated from configure.ac by autoheader. */ 7 | 8 | /* Define to 1 if you have the header file. */ 9 | #ifndef PIC_HAVE_DLFCN_H 10 | #define PIC_HAVE_DLFCN_H 1 11 | #endif 12 | 13 | /* Define to 1 if you have the header file. */ 14 | #ifndef PIC_HAVE_INTTYPES_H 15 | #define PIC_HAVE_INTTYPES_H 1 16 | #endif 17 | 18 | /* Define to 1 if you have the header file. */ 19 | #ifndef PIC_HAVE_MEMORY_H 20 | #define PIC_HAVE_MEMORY_H 1 21 | #endif 22 | 23 | /* Define to 1 if stdbool.h conforms to C99. */ 24 | #ifndef PIC_HAVE_STDBOOL_H 25 | #define PIC_HAVE_STDBOOL_H 1 26 | #endif 27 | 28 | /* Define to 1 if you have the header file. */ 29 | #ifndef PIC_HAVE_STDINT_H 30 | #define PIC_HAVE_STDINT_H 1 31 | #endif 32 | 33 | /* Define to 1 if you have the header file. */ 34 | #ifndef PIC_HAVE_STDLIB_H 35 | #define PIC_HAVE_STDLIB_H 1 36 | #endif 37 | 38 | /* Define to 1 if you have the header file. */ 39 | #ifndef PIC_HAVE_STRINGS_H 40 | #define PIC_HAVE_STRINGS_H 1 41 | #endif 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #ifndef PIC_HAVE_STRING_H 45 | #define PIC_HAVE_STRING_H 1 46 | #endif 47 | 48 | /* Define to 1 if you have the header file. */ 49 | #ifndef PIC_HAVE_SYS_STAT_H 50 | #define PIC_HAVE_SYS_STAT_H 1 51 | #endif 52 | 53 | /* Define to 1 if you have the header file. */ 54 | #ifndef PIC_HAVE_SYS_TYPES_H 55 | #define PIC_HAVE_SYS_TYPES_H 1 56 | #endif 57 | 58 | /* Define to 1 if you have the header file. */ 59 | #ifndef PIC_HAVE_UNISTD_H 60 | #define PIC_HAVE_UNISTD_H 1 61 | #endif 62 | 63 | /* Define to 1 if the system has the type `_Bool'. */ 64 | /* #undef HAVE__BOOL */ 65 | 66 | /* Name of package */ 67 | #ifndef PIC_PACKAGE 68 | #define PIC_PACKAGE "pic" 69 | #endif 70 | 71 | /* Author of package */ 72 | #ifndef PIC_PACKAGE_AUTHOR 73 | #define PIC_PACKAGE_AUTHOR "Ares Lagae" 74 | #endif 75 | 76 | /* Define to the address where bug reports for this package should be sent. */ 77 | #ifndef PIC_PACKAGE_BUGREPORT 78 | #define PIC_PACKAGE_BUGREPORT "ares.lagae@cs.kuleuven.be" 79 | #endif 80 | 81 | /* Define to the full name of this package. */ 82 | #ifndef PIC_PACKAGE_NAME 83 | #define PIC_PACKAGE_NAME "pic" 84 | #endif 85 | 86 | /* Define to the full name and version of this package. */ 87 | #ifndef PIC_PACKAGE_STRING 88 | #define PIC_PACKAGE_STRING "pic 0.1" 89 | #endif 90 | 91 | /* Define to the one symbol short name of this package. */ 92 | #ifndef PIC_PACKAGE_TARNAME 93 | #define PIC_PACKAGE_TARNAME "pic" 94 | #endif 95 | 96 | /* Define to the version of this package. */ 97 | #ifndef PIC_PACKAGE_VERSION 98 | #define PIC_PACKAGE_VERSION "0.1" 99 | #endif 100 | 101 | /* Define to 1 if you have the ANSI C header files. */ 102 | /* #undef STDC_HEADERS */ 103 | 104 | /* Version number of package */ 105 | #ifndef PIC_VERSION 106 | #define PIC_VERSION "0.1" 107 | #endif 108 | 109 | /* Define to empty if `const' does not conform to ANSI C. */ 110 | /* #undef const */ 111 | 112 | /* Define to `unsigned int' if does not define. */ 113 | /* #undef size_t */ 114 | 115 | /* once: _PIC_CONFIG_HPP */ 116 | #endif 117 | -------------------------------------------------------------------------------- /dependencies/pic/include/pic/pic.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PIC_PIC_HPP_INCLUDED 2 | #define PIC_PIC_HPP_INCLUDED 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace pic { 9 | 10 | typedef int format_type; 11 | enum format { _32_bit_rle_rgbe, _32_bit_rle_xyze }; 12 | 13 | typedef int resolution_string_type; 14 | enum resolution_string { neg_y_pos_x, neg_y_neg_x, pos_y_neg_x, pos_y_pos_x, pos_x_pos_y, neg_x_pos_y, neg_x_neg_y, pos_x_neg_y }; 15 | 16 | typedef unsigned char uint8_t; 17 | 18 | class runtime_error : public std::runtime_error { 19 | public: 20 | explicit runtime_error(const std::string& what); 21 | }; 22 | 23 | template void rgbe_or_xyze_to_rgb_or_xyz(uint8_t rgbe_r_or_xyze_x, uint8_t rgbe_g_or_xyze_y, uint8_t rgbe_b_or_xyze_z, uint8_t rgbe_e_or_xyze_e, FloatType& rgb_r_or_xyz_x, FloatType& rgb_g_or_xyz_y, FloatType& rgb_b_or_xyz_z); 24 | template void rgbe_to_rgb(uint8_t rgbe_r, uint8_t rgbe_g, uint8_t rgbe_b, uint8_t rgbe_e, FloatType& rgb_r, FloatType& rgb_g, FloatType& rgb_b); 25 | template void xyze_to_xyz(uint8_t xyze_x, uint8_t xyze_y, uint8_t xyze_z, uint8_t xyze_e, FloatType& xyz_x, FloatType& xyz_y, FloatType& xyz_z); 26 | template void rgb_or_xyz_to_rgbe_or_xyze(FloatType rgb_r_or_xyz_x, FloatType rgb_g_or_xyz_y, FloatType rgb_b_or_xyz_z, uint8_t& rgbe_r_or_xyze_x, uint8_t& rgbe_g_or_xyze_y, uint8_t& rgbe_b_or_xyze_z, uint8_t& rgbe_e_or_xyze_e); 27 | template void rgb_to_rgbe(FloatType rgb_r, FloatType rgb_g, FloatType rgb_b, uint8_t& rgbe_r, uint8_t& rgbe_g, uint8_t& rgbe_b, uint8_t& rgbe_e); 28 | template void xyz_to_xyze(FloatType xyz_x, FloatType xyz_y, FloatType xyz_z, uint8_t& xyze_x, uint8_t& xyze_y, uint8_t& xyze_z, uint8_t& xyze_e); 29 | 30 | } // namespace pic 31 | 32 | inline pic::runtime_error::runtime_error(const std::string& what) 33 | : std::runtime_error(what) 34 | { 35 | } 36 | 37 | #include 38 | 39 | template 40 | inline void pic::rgbe_or_xyze_to_rgb_or_xyz(uint8_t rgbe_r_or_xyze_x, uint8_t rgbe_g_or_xyze_y, uint8_t rgbe_b_or_xyze_z, uint8_t rgbe_e_or_xyze_e, FloatType& rgb_r_or_xyz_x, FloatType& rgb_g_or_xyz_y, FloatType& rgb_b_or_xyz_z) 41 | { 42 | if (rgbe_e_or_xyze_e != 0) { 43 | FloatType f = std::ldexp(FloatType(1.0), int(rgbe_e_or_xyze_e) - (128 + 8)); 44 | rgb_r_or_xyz_x = (rgbe_r_or_xyze_x + FloatType(0.5)) * f; 45 | rgb_g_or_xyz_y = (rgbe_g_or_xyze_y + FloatType(0.5)) * f; 46 | rgb_b_or_xyz_z = (rgbe_b_or_xyze_z + FloatType(0.5)) * f; 47 | } 48 | else { 49 | rgb_r_or_xyz_x = rgb_g_or_xyz_y = rgb_b_or_xyz_z = FloatType(0.0); 50 | } 51 | } 52 | 53 | template 54 | inline void pic::rgb_or_xyz_to_rgbe_or_xyze(FloatType rgb_r_or_xyz_x, FloatType rgb_g_or_xyz_y, FloatType rgb_b_or_xyz_z, uint8_t& rgbe_r_or_xyze_x, uint8_t& rgbe_g_or_xyze_y, uint8_t& rgbe_b_or_xyze_z, uint8_t& rgbe_e_or_xyze_e) 55 | { 56 | FloatType d = std::max(rgb_r_or_xyz_x, std::max(rgb_g_or_xyz_y, rgb_b_or_xyz_z)); 57 | if (d <= FloatType(1e-32)) { 58 | rgbe_r_or_xyze_x = rgbe_g_or_xyze_y = rgbe_b_or_xyze_z = 0; 59 | rgbe_e_or_xyze_e = 0; 60 | } 61 | else { 62 | int e; 63 | d = frexp(d, &e) * FloatType(255.9999) / d; 64 | rgbe_r_or_xyze_x = rgb_r_or_xyz_x > FloatType(0.0) ? (uint8_t)(rgb_r_or_xyz_x * d) : 0; 65 | rgbe_g_or_xyze_y = rgb_g_or_xyz_y > FloatType(0.0) ? (uint8_t)(rgb_g_or_xyz_y * d) : 0; 66 | rgbe_b_or_xyze_z = rgb_b_or_xyz_z > FloatType(0.0) ? (uint8_t)(rgb_b_or_xyz_z * d) : 0; 67 | rgbe_e_or_xyze_e = e + 128; 68 | } 69 | } 70 | 71 | template 72 | inline void pic::rgbe_to_rgb(uint8_t rgbe_r, uint8_t rgbe_g, uint8_t rgbe_b, uint8_t rgbe_e, FloatType& rgb_r, FloatType& rgb_g, FloatType& rgb_b) 73 | { 74 | return rgbe_or_xyze_to_rgb_or_xyz(rgbe_r, rgbe_g, rgbe_b, rgbe_e, rgb_r, rgb_g, rgb_b); 75 | } 76 | 77 | template 78 | inline void pic::rgb_to_rgbe(FloatType rgb_r, FloatType rgb_g, FloatType rgb_b, uint8_t& rgbe_r, uint8_t& rgbe_g, uint8_t& rgbe_b, uint8_t& rgbe_e) 79 | { 80 | return rgb_or_xyz_to_rgbe_or_xyze(rgb_r, rgb_g, rgb_b, rgbe_r, rgbe_g, rgbe_b, rgbe_e); 81 | } 82 | 83 | template 84 | inline void pic::xyze_to_xyz(uint8_t xyze_x, uint8_t xyze_y, uint8_t xyze_z, uint8_t xyze_e, FloatType& xyz_x, FloatType& xyz_y, FloatType& xyz_z) 85 | { 86 | return rgbe_or_xyze_to_rgb_or_xyz(xyze_x, xyze_y, xyze_z, xyze_e, xyz_x, xyz_y, xyz_z); 87 | } 88 | 89 | template 90 | inline void pic::xyz_to_xyze(FloatType xyz_x, FloatType xyz_y, FloatType xyz_z, uint8_t& xyze_x, uint8_t& xyze_y, uint8_t& xyze_z, uint8_t& xyze_e) 91 | { 92 | return rgb_or_xyz_to_rgbe_or_xyze(xyz_x, xyz_y, xyz_z, xyze_x, xyze_y, xyze_z, xyze_e); 93 | } 94 | 95 | #endif // PIC_PIC_HPP_INCLUDED 96 | -------------------------------------------------------------------------------- /dependencies/pic/include/pic/pic_input_file.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PIC_PIC_INPUT_FILE_HPP_INCLUDED 2 | #define PIC_PIC_INPUT_FILE_HPP_INCLUDED 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace pic { 10 | 11 | class pic_input_file 12 | { 13 | public: 14 | pic_input_file(std::istream& istream); 15 | void read_information_header(format_type& format, double& exposure); 16 | void read_resolution_string(resolution_string_type& resolution_string_type, std::size_t& x_resolution, std::size_t& y_resolution); 17 | void read_scanline(pixel* scanline, std::size_t length); 18 | private: 19 | std::istream& istream_; 20 | std::size_t line_number_; 21 | }; 22 | 23 | } // namespace pic 24 | 25 | inline pic::pic_input_file::pic_input_file(std::istream& istream) 26 | : istream_(istream) 27 | { 28 | } 29 | 30 | #endif // PIC_PIC_INPUT_FILE_HPP_INCLUDED 31 | -------------------------------------------------------------------------------- /dependencies/pic/include/pic/pic_output_file.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PIC_PIC_OUTPUT_FILE_HPP_INCLUDED 2 | #define PIC_PIC_OUTPUT_FILE_HPP_INCLUDED 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace pic { 10 | 11 | class pic_output_file 12 | { 13 | public: 14 | pic_output_file(std::ostream& ostream); 15 | void write_information_header(format_type format, double exposure); 16 | void write_resolution_string(resolution_string_type resolution_string_type, std::size_t x_resolution, std::size_t y_resolution); 17 | void write_scanline(const pixel* scanline, std::size_t length); 18 | private: 19 | std::ostream& ostream_; 20 | }; 21 | 22 | } // namespace pic 23 | 24 | inline pic::pic_output_file::pic_output_file(std::ostream& ostream) 25 | : ostream_(ostream) 26 | { 27 | } 28 | 29 | #endif // PIC_PIC_OUTPUT_FILE_HPP_INCLUDED 30 | -------------------------------------------------------------------------------- /dependencies/pic/include/pic/pixel.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PIC_PIXEL_HPP_INCLUDED 2 | #define PIC_PIXEL_HPP_INCLUDED 3 | 4 | #include 5 | 6 | namespace pic { 7 | 8 | class pixel 9 | { 10 | public: 11 | typedef uint8_t value_type; 12 | typedef std::size_t size_type; 13 | pixel(); 14 | pixel(value_type, value_type, value_type, value_type); 15 | explicit pixel(value_type); 16 | const value_type& operator[](size_type) const; 17 | value_type& operator[](size_type); 18 | private: 19 | value_type rgbe_or_xyze_[4]; 20 | }; 21 | 22 | bool operator==(const pixel&, const pixel&); 23 | bool operator!=(const pixel&, const pixel&); 24 | template std::basic_ostream& operator<<(std::basic_ostream&, const pixel&); 25 | template std::basic_istream& operator>>(std::basic_istream&, pixel&); 26 | 27 | } // namespace pic 28 | 29 | #include 30 | 31 | inline pic::pixel::pixel() 32 | { 33 | } 34 | 35 | inline pic::pixel::pixel(value_type r_or_x, value_type g_or_y, value_type b_or_z, value_type e) 36 | { 37 | rgbe_or_xyze_[0] = r_or_x; 38 | rgbe_or_xyze_[1] = g_or_y; 39 | rgbe_or_xyze_[2] = b_or_z; 40 | rgbe_or_xyze_[3] = e; 41 | } 42 | 43 | inline pic::pixel::pixel(value_type rgbe_or_xyze) 44 | { 45 | rgbe_or_xyze_[0] = rgbe_or_xyze; 46 | rgbe_or_xyze_[1] = rgbe_or_xyze; 47 | rgbe_or_xyze_[2] = rgbe_or_xyze; 48 | rgbe_or_xyze_[3] = rgbe_or_xyze; 49 | } 50 | 51 | inline const pic::pixel::value_type& pic::pixel::operator[](size_type index) const 52 | { 53 | assert(index < 4); 54 | return rgbe_or_xyze_[index]; 55 | } 56 | 57 | inline pic::pixel::value_type& pic::pixel::operator[](size_type index) 58 | { 59 | assert(index < 4); 60 | return rgbe_or_xyze_[index]; 61 | } 62 | 63 | inline bool pic::operator==(const pixel& lhs, const pixel& rhs) 64 | { 65 | return (lhs[0] == rhs[0]) && (lhs[1] == rhs[1]) && (lhs[2] == rhs[2]) && (lhs[3] == rhs[3]); 66 | } 67 | 68 | inline bool pic::operator!=(const pixel& lhs, const pixel& rhs) 69 | { 70 | return !(lhs == rhs); 71 | } 72 | 73 | template 74 | inline std::basic_ostream& pic::operator<<(std::basic_ostream& ostream, const pixel& p) 75 | { 76 | return ostream << p[0] << ' ' << p[1] << ' ' << p[2] << ' ' << p[3]; 77 | } 78 | 79 | template 80 | inline std::basic_istream& pic::operator>>(std::basic_istream& istream, pixel& p) 81 | { 82 | return istream >> p[0] >> p[1] >> p[2] >> p[3]; 83 | } 84 | 85 | #endif // PIC_PIXEL_HPP_INCLUDED 86 | -------------------------------------------------------------------------------- /dependencies/pic/pic_input_file.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #ifdef PIC_DEBUG 10 | # include 11 | #endif 12 | 13 | void pic::pic_input_file::read_information_header(format_type& format, double& exposure) 14 | { 15 | std::string line; 16 | line_number_ = 0; 17 | 18 | // magic 19 | std::string header; 20 | std::getline(istream_, header); 21 | if (!istream_) { 22 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 23 | } 24 | ++line_number_; 25 | if (!(header == "#?RADIANCE" || header == "#?RGBE")) { 26 | throw pic::runtime_error(std::string("pic: invalid header token: ") + header); 27 | } 28 | 29 | std::size_t number_of_format_lines = 0; 30 | double cumulative_exposure = 1.0; 31 | double cumulative_colorcorr[3] = {1.0, 1.0, 1.0}; 32 | double cumulative_pixaspect = 1.0; 33 | std::size_t number_of_primaries_lines = 0; 34 | 35 | while (std::getline(istream_, line)) { 36 | ++line_number_; 37 | 38 | if (!line.empty()) { 39 | std::string::size_type pos = line.find('='); 40 | if (pos != std::string::npos) { 41 | std::string key = line.substr(0, pos); 42 | std::string value = line.substr(pos + 1, line.size()); 43 | 44 | // format 45 | if (key == "FORMAT") { 46 | std::string format_string; 47 | std::istringstream istringstream(value); 48 | istringstream.unsetf(std::ios_base::skipws); 49 | istringstream >> std::ws >> format_string;// >> std::ws; 50 | if ((format_string != "32-bit_rle_rgbe") && (format_string != "32-bit_rle_xyze")) { 51 | #ifdef PIC_DEBUG 52 | std::cerr << "pic: " << line_number_ << ": " << "error" << std::endl; 53 | #endif 54 | throw pic::runtime_error(std::string("Unsupported format: ") + format_string); 55 | } 56 | if (number_of_format_lines > 0) { 57 | #ifdef PIC_DEBUG 58 | std::cerr << "pic: " << line_number_ << ": " << "error" << std::endl; 59 | #endif 60 | throw pic::runtime_error(std::string("Encountered multiple format lines.")); 61 | } 62 | #ifdef PIC_DEBUG 63 | std::cerr << "pic: " << line_number_ << ": " << "info: " << "FORMAT=" << format_string << std::endl; 64 | #endif 65 | if (format_string == "32-bit_rle_rgbe") { 66 | format = _32_bit_rle_rgbe; 67 | } 68 | else { 69 | format = _32_bit_rle_xyze; 70 | } 71 | ++number_of_format_lines; 72 | } 73 | 74 | // exposure 75 | else if (key == "EXPOSURE") { 76 | double exposure; 77 | std::istringstream istringstream(value); 78 | istringstream.unsetf(std::ios_base::skipws); 79 | istringstream >> std::ws >> exposure; 80 | if (exposure < 0.0) { 81 | #ifdef PIC_DEBUG 82 | std::cerr << "pic: " << line_number_ << ": " << "error" << std::endl; 83 | #endif 84 | throw pic::runtime_error(std::string("Invalid exposure value: ") + std::to_string(exposure)); 85 | } 86 | #ifdef PIC_DEBUG 87 | std::cerr << "pic: " << line_number_ << ": " << "info: " << "EXPOSURE=" << exposure << std::endl; 88 | #endif 89 | cumulative_exposure *= exposure; 90 | } 91 | 92 | // color correction 93 | else if (key == "COLORCORR") { 94 | double colorcorr[3]; 95 | char space_colorcorr_0_colorcorr_1, space_colorcorr_1_colorcorr_2; 96 | std::istringstream istringstream(value); 97 | istringstream.unsetf(std::ios_base::skipws); 98 | istringstream >> std::ws >> colorcorr[0] >> space_colorcorr_0_colorcorr_1 >> std::ws >> colorcorr[1] >> space_colorcorr_1_colorcorr_2 >> std::ws >> colorcorr[2] >> std::ws; 99 | if (!std::isspace(space_colorcorr_0_colorcorr_1) || !std::isspace(space_colorcorr_1_colorcorr_2)) { 100 | #ifdef PIC_DEBUG 101 | std::cerr << "pic: " << line_number_ << ": " << "error" << std::endl; 102 | #endif 103 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 104 | } 105 | #ifdef PIC_DEBUG 106 | std::cerr << "pic: " << line_number_ << ": " << "info: " << "COLORCORR=" << colorcorr[0] << " " << colorcorr[1] << " " << colorcorr[2] << std::endl; 107 | #endif 108 | cumulative_colorcorr[0] *= colorcorr[0]; 109 | cumulative_colorcorr[1] *= colorcorr[1]; 110 | cumulative_colorcorr[2] *= colorcorr[2]; 111 | #ifdef PIC_DEBUG 112 | std::cerr << "pic: " << line_number_ << ": " << "warning: " << "ignoring line ‘" << line << "’" << std::endl; 113 | #endif 114 | } 115 | 116 | // software 117 | else if (key == "SOFTWARE") { 118 | std::string software = value; 119 | #ifdef PIC_DEBUG 120 | std::cerr << "pic: " << line_number_ << ": " << "info: " << "SOFTWARE=" << software << std::endl; 121 | #endif 122 | #ifdef PIC_DEBUG 123 | std::cerr << "pic: " << line_number_ << ": " << "warning: " << "ignoring line ‘" << line << "’" << std::endl; 124 | #endif 125 | } 126 | 127 | // pixel aspect ratio 128 | else if (key == "PIXASPECT") { 129 | double pixaspect; 130 | std::istringstream istringstream(value); 131 | istringstream.unsetf(std::ios_base::skipws); 132 | istringstream >> std::ws >> pixaspect; 133 | #ifdef PIC_DEBUG 134 | std::cerr << "pic: " << line_number_ << ": " << "info: " << "PIXASPECT=" << pixaspect << std::endl; 135 | #endif 136 | cumulative_pixaspect *= pixaspect; 137 | #ifdef PIC_DEBUG 138 | std::cerr << "pic: " << line_number_ << ": " << "warning: " << "ignoring line ‘" << line << "’" << std::endl; 139 | #endif 140 | } 141 | 142 | // view 143 | else if (key == "VIEW") { 144 | std::string view_parameters = value; 145 | #ifdef PIC_DEBUG 146 | std::cerr << "pic: " << line_number_ << ": " << "info: " << "VIEW=" << view_parameters << std::endl; 147 | #endif 148 | #ifdef PIC_DEBUG 149 | std::cerr << "pic: " << line_number_ << ": " << "warning: " << "ignoring line ‘" << line << "’" << std::endl; 150 | #endif 151 | } 152 | 153 | // primaries 154 | else if (key == "PRIMARIES") { 155 | double primaries[4][2]; 156 | char space_primaries_0_0_primaries_0_1, space_primaries_0_1_primaries_1_0, space_primaries_1_0_primaries_1_1, space_primaries_1_1_primaries_2_0, space_primaries_2_0_primaries_2_1, space_primaries_2_1_primaries_3_0, space_primaries_3_0_primaries_3_1; 157 | std::istringstream istringstream(value); 158 | istringstream.unsetf(std::ios_base::skipws); 159 | istringstream >> std::ws >> primaries[0][0] >> space_primaries_0_0_primaries_0_1 >> std::ws >> primaries[0][1] >> space_primaries_0_1_primaries_1_0 >> std::ws >> primaries[1][0] >> space_primaries_1_0_primaries_1_1 >> std::ws >> primaries[1][1] >> space_primaries_1_1_primaries_2_0 >> std::ws >> primaries[2][0] >> space_primaries_2_0_primaries_2_1 >> std::ws >> primaries[2][1] >> space_primaries_2_1_primaries_3_0 >> std::ws >> primaries[3][0] >> space_primaries_3_0_primaries_3_1 >> std::ws >> primaries[3][1]; 160 | if ((!std::isspace(space_primaries_0_0_primaries_0_1)) || (!std::isspace(space_primaries_0_1_primaries_1_0)) || (!std::isspace(space_primaries_1_0_primaries_1_1)) || (!std::isspace(space_primaries_1_1_primaries_2_0)) || (!std::isspace(space_primaries_2_0_primaries_2_1)) || (!std::isspace(space_primaries_2_1_primaries_3_0)) || (!std::isspace(space_primaries_3_0_primaries_3_1))) { 161 | #ifdef PIC_DEBUG 162 | std::cerr << "pic: " << line_number_ << ": " << "error" << std::endl; 163 | #endif 164 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 165 | } 166 | if (number_of_primaries_lines > 0) { 167 | #ifdef PIC_DEBUG 168 | std::cerr << "pic: " << line_number_ << ": " << "error" << std::endl; 169 | #endif 170 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 171 | } 172 | #ifdef PIC_DEBUG 173 | std::cerr << "pic: " << line_number_ << ": " << "info: " << "PRIMARIES=" << primaries[0][0] << " " << primaries[0][1] << " " << primaries[1][0] << " " << primaries[1][1] << " " << primaries[2][0] << " " << primaries[2][1] << " " << primaries[3][0] << " " << primaries[3][1] << std::endl; 174 | #endif 175 | ++number_of_primaries_lines; 176 | #ifdef PIC_DEBUG 177 | std::cerr << "pic: " << line_number_ << ": " << "warning: " << "ignoring line ‘" << line << "’" << std::endl; 178 | #endif 179 | } 180 | 181 | // unknown 182 | else { 183 | #ifdef PIC_DEBUG 184 | std::cerr << "pic: " << line_number_ << ": " << "warning: " << "ignoring line ‘" << line << "’" << std::endl; 185 | #endif 186 | } 187 | } 188 | 189 | // comment 190 | else if (line[0] == '#') { 191 | std::string comment = line; 192 | #ifdef PIC_DEBUG 193 | std::cerr << "pic: " << line_number_ << ": " << "info: " << comment << std::endl; 194 | #endif 195 | } 196 | 197 | // unknown 198 | else { 199 | #ifdef PIC_DEBUG 200 | std::cerr << "pic: " << line_number_ << ": " << "warning: " << "ignoring line ‘" << line << "’" << std::endl; 201 | #endif 202 | } 203 | 204 | } 205 | else { 206 | // empty line 207 | break; 208 | } 209 | } 210 | 211 | // format 212 | if (number_of_format_lines != 1) { 213 | #ifdef PIC_DEBUG 214 | std::cerr << "pic: " << line_number_ << ": " << "error" << std::endl; 215 | #endif 216 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 217 | } 218 | 219 | if (!istream_) { 220 | #ifdef PIC_DEBUG 221 | std::cerr << "pic: " << line_number_ << ": " << "error" << std::endl; 222 | #endif 223 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 224 | } 225 | 226 | exposure = cumulative_exposure; 227 | } 228 | 229 | void pic::pic_input_file::read_resolution_string(resolution_string_type& resolution_string_type, std::size_t& x_resolution, std::size_t& y_resolution) 230 | { 231 | std::string line; 232 | 233 | // resolution string 234 | std::getline(istream_, line); 235 | if (!istream_) { 236 | #ifdef PIC_DEBUG 237 | std::cerr << "pic: " << line_number_ << ": " << "error" << std::endl; 238 | #endif 239 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 240 | } 241 | char sign[2]; 242 | char dim[2]; 243 | std::size_t resolution[2]; 244 | char space_dim_0_resolution_0, space_resolution_0_sign_1, space_dim_1_resolution_1; 245 | std::istringstream istringstream(line); 246 | istringstream.unsetf(std::ios_base::skipws); 247 | istringstream >> std::ws >> sign[0] >> dim[0] >> space_dim_0_resolution_0 >> std::ws >> resolution[0] >> space_resolution_0_sign_1 >> std::ws >> sign[1] >> dim[1] >> space_dim_1_resolution_1 >> std::ws >> resolution[1] >> std::ws; 248 | if ( ((sign[0] != '+') && (sign[0] != '-')) 249 | || ((dim[0] != 'X') && (dim[0] != 'Y')) 250 | || (!std::isspace(space_dim_0_resolution_0)) 251 | || (resolution[0] == 0) 252 | || (!std::isspace(space_resolution_0_sign_1)) 253 | || ((sign[1] != '+') && (sign[1] != '-')) 254 | || ((dim[1] != 'X') && (dim[1] != 'Y')) 255 | || (!std::isspace(space_dim_1_resolution_1)) 256 | || (resolution[1] == 0) 257 | || (dim[0] == dim[1])) 258 | { 259 | #ifdef PIC_DEBUG 260 | std::cerr << "pic: " << line_number_ << ": " << "error" << std::endl; 261 | #endif 262 | throw pic::runtime_error(std::string("Invalid resolution: ") + line); 263 | } 264 | #ifdef PIC_DEBUG 265 | std::cerr << "pic: " << line_number_ << ": " << "info: " << sign[0] << dim[0] << " " << resolution[0] << " " << sign[1] << dim[1] << " " << resolution[1] << "\n"; 266 | #endif 267 | resolution_string_type = dim[0] == 'Y' ? (sign[0] == '-' ? (sign[1] == '+' ? neg_y_pos_x : neg_y_neg_x) 268 | : (sign[1] == '+' ? pos_y_pos_x : pos_y_neg_x)) 269 | : (sign[0] == '-' ? (sign[1] == '+' ? neg_x_pos_y : neg_x_neg_y) 270 | : (sign[1] == '+' ? pos_x_pos_y : pos_x_neg_y)); 271 | if (dim[0] == 'Y') { 272 | x_resolution = resolution[1]; 273 | y_resolution = resolution[0]; 274 | } 275 | else { 276 | x_resolution = resolution[0]; 277 | y_resolution = resolution[1]; 278 | } 279 | } 280 | 281 | void pic::pic_input_file::read_scanline(pixel* scanline, std::size_t length) 282 | { 283 | assert(scanline != 0); 284 | assert(length > 0); 285 | 286 | if ((length < 8) || (length > 0x7fff)) { 287 | #ifdef PIC_DEBUG 288 | std::cerr << istream_.tellg() << ": " << "error: " << std::endl; 289 | #endif 290 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 291 | } 292 | else { 293 | uint8_t header[4]; 294 | istream_.read(reinterpret_cast(&header), 4); 295 | if (!istream_) { 296 | #ifdef PIC_DEBUG 297 | std::cerr << istream_.tellg() << ": " << "error: " << std::endl; 298 | #endif 299 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 300 | } 301 | if ((header[0] != 2) || (header[1] != 2)) { 302 | // Uncompressed format (not run-length encoded) 303 | memcpy(scanline, header, sizeof(pixel)); 304 | istream_.read(reinterpret_cast(&scanline[1]), (length - 1) * sizeof(pixel)); 305 | return; 306 | } 307 | std::size_t scanline_length = (header[2] << 8) | header[3]; 308 | if (scanline_length != length) { 309 | #ifdef PIC_DEBUG 310 | std::cerr << istream_.tellg() << ": " << "error: " << std::endl; 311 | #endif 312 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 313 | } 314 | for (std::size_t component_index = 0; component_index < 4; ++component_index) { 315 | pixel* scanline_iterator = scanline; 316 | std::size_t bytes_left = scanline_length; 317 | while (bytes_left > 0) { 318 | // read byte 319 | uint8_t byte; 320 | istream_.read(reinterpret_cast(&byte), 1); 321 | if (!istream_) { 322 | #ifdef PIC_DEBUG 323 | std::cerr << istream_.tellg() << ": " << "error: " << std::endl; 324 | #endif 325 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 326 | } 327 | // run 328 | if ((byte > 128)) { 329 | std::size_t run_length = byte - 128; 330 | if (run_length > bytes_left) { 331 | #ifdef PIC_DEBUG 332 | std::cerr << istream_.tellg() << ": " << "error: " << std::endl; 333 | #endif 334 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 335 | } 336 | istream_.read(reinterpret_cast(&byte), 1); 337 | if (!istream_) { 338 | #ifdef PIC_DEBUG 339 | std::cerr << istream_.tellg() << ": " << "error: " << std::endl; 340 | #endif 341 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 342 | } 343 | for (std::size_t i = 0; i < run_length; ++i) { 344 | (*scanline_iterator)[component_index] = byte; 345 | ++scanline_iterator; 346 | } 347 | bytes_left -= run_length; 348 | } 349 | // dump 350 | else { 351 | std::size_t dump_length = byte; 352 | if (dump_length > bytes_left) { 353 | #ifdef PIC_DEBUG 354 | std::cerr << istream_.tellg() << ": " << "error: " << std::endl; 355 | #endif 356 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 357 | } 358 | for (std::size_t i = 0; i < dump_length; ++i) { 359 | istream_.read(reinterpret_cast(&byte), 1); 360 | if (!istream_) { 361 | #ifdef PIC_DEBUG 362 | std::cerr << istream_.tellg() << ": " << "error: " << std::endl; 363 | #endif 364 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 365 | } 366 | (*scanline_iterator)[component_index] = byte; 367 | ++scanline_iterator; 368 | } 369 | bytes_left -= dump_length; 370 | } 371 | 372 | } 373 | } 374 | } 375 | } 376 | -------------------------------------------------------------------------------- /dependencies/pic/pic_output_file.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #ifdef PIC_DEBUG 6 | # include 7 | #endif 8 | 9 | void pic::pic_output_file::write_information_header(format_type format, double exposure) 10 | { 11 | assert((format == pic::_32_bit_rle_rgbe) || (format == pic::_32_bit_rle_xyze)); 12 | assert(exposure >= 0.0); 13 | 14 | ostream_ << "#?RADIANCE" << "\n"; 15 | switch (format) { 16 | case pic::_32_bit_rle_rgbe: 17 | ostream_ << "FORMAT=32-bit_rle_rgbe\n"; 18 | break; 19 | case pic::_32_bit_rle_xyze: 20 | ostream_ << "FORMAT=32-bit_rle_xyze\n"; 21 | break; 22 | } 23 | ostream_ << "EXPOSURE=" << exposure << "\n"; 24 | ostream_ << "\n"; 25 | 26 | if (!ostream_) { 27 | #ifdef PIC_DEBUG 28 | std::cerr << ostream_.tellp() << ": " << "error: " << std::endl; 29 | #endif 30 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 31 | } 32 | } 33 | 34 | void pic::pic_output_file::write_resolution_string(resolution_string_type resolution_string_type, std::size_t x_resolution, std::size_t y_resolution) 35 | { 36 | assert((resolution_string_type == pic::pos_x_pos_y) 37 | || (resolution_string_type == pic::pos_x_neg_y) 38 | || (resolution_string_type == pic::neg_x_pos_y) 39 | || (resolution_string_type == pic::neg_x_neg_y) 40 | || (resolution_string_type == pic::pos_y_pos_x) 41 | || (resolution_string_type == pic::pos_y_neg_x) 42 | || (resolution_string_type == pic::neg_y_pos_x) 43 | || (resolution_string_type == pic::neg_y_neg_x) 44 | ); 45 | assert(x_resolution > 0); 46 | assert(y_resolution > 0); 47 | 48 | switch (resolution_string_type) { 49 | case pic::pos_x_pos_y: 50 | ostream_ << "+X " << x_resolution << " +Y " << y_resolution << "\n"; 51 | break; 52 | case pic::pos_x_neg_y: 53 | ostream_ << "+X " << x_resolution << " -Y " << y_resolution << "\n"; 54 | break; 55 | case pic::neg_x_pos_y: 56 | ostream_ << "-X " << x_resolution << " +Y " << y_resolution << "\n"; 57 | break; 58 | case pic::neg_x_neg_y: 59 | ostream_ << "-X " << x_resolution << " -Y " << y_resolution << "\n"; 60 | break; 61 | case pic::pos_y_pos_x: 62 | ostream_ << "+Y " << y_resolution << " +X " << x_resolution << "\n"; 63 | break; 64 | case pic::pos_y_neg_x: 65 | ostream_ << "+Y " << y_resolution << " -X " << x_resolution << "\n"; 66 | break; 67 | case pic::neg_y_pos_x: 68 | ostream_ << "-Y " << y_resolution << " +X " << x_resolution << "\n"; 69 | break; 70 | case pic::neg_y_neg_x: 71 | ostream_ << "-Y " << y_resolution << " -X " << x_resolution << "\n"; 72 | break; 73 | default: 74 | assert(false); 75 | } 76 | 77 | if (!ostream_) { 78 | #ifdef PIC_DEBUG 79 | std::cerr << ostream_.tellp() << ": " << "error: " << std::endl; 80 | #endif 81 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 82 | } 83 | } 84 | 85 | void pic::pic_output_file::write_scanline(const pixel* scanline, std::size_t length) 86 | { 87 | assert(scanline != 0); 88 | assert(length > 0); 89 | 90 | if (length < 8) { 91 | throw pic::runtime_error(std::string("Image width must be 8 or larger")); 92 | } 93 | if (length > 0x7fff) { 94 | throw pic::runtime_error(std::string("Maximum image width exceeded")); 95 | } 96 | uint8_t header[4]; 97 | header[0] = header[1] = 2; 98 | header[2] = length >> 8; 99 | header[3] = length & 0xFF; 100 | ostream_.write(reinterpret_cast(&header), 4); 101 | if (!ostream_) { 102 | #ifdef PIC_DEBUG 103 | std::cerr << ostream_.tellp() << ": " << "error: " << std::endl; 104 | #endif 105 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 106 | } 107 | for (std::size_t component_index = 0; component_index < 4; ++component_index) { 108 | const pixel* scanline_begin = scanline; 109 | const pixel* scanline_end = scanline + length; 110 | const pixel* scanline_iterator = scanline_begin; 111 | while (scanline_iterator != scanline_end) { 112 | // try to find a run [run_begin, run_end) with length run_length, at least 2 and at most 127 113 | const pixel* run_begin = scanline_iterator; 114 | const pixel* run_end; 115 | std::size_t run_length; 116 | do { 117 | run_end = run_begin + 1; 118 | run_length = 1; 119 | while ((run_end != scanline_end) && ((*run_end)[component_index] == (*run_begin)[component_index]) && (run_length < 127)) { 120 | ++run_end; 121 | ++run_length; 122 | } 123 | if ((run_length < 2) && (run_end != scanline_end)) { 124 | run_begin = run_end; 125 | } 126 | } while ((run_length < 2) && (run_end != scanline_end)); 127 | // dump 128 | const pixel* dump_begin = scanline_iterator; 129 | const pixel* dump_end = run_begin; 130 | if (run_length < 2) { 131 | dump_end = run_end; 132 | } 133 | std::size_t dump_length = dump_end - dump_begin; 134 | if (dump_length > 0) { 135 | while (dump_length > 128) { 136 | uint8_t byte = 128; 137 | ostream_.write(reinterpret_cast(&byte), 1); 138 | if (!ostream_) { 139 | #ifdef PIC_DEBUG 140 | std::cerr << ostream_.tellp() << ": " << "error: " << std::endl; 141 | #endif 142 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 143 | } 144 | for (std::size_t i = 0; i < 128; ++i) { 145 | ostream_.write(reinterpret_cast(&((*(dump_begin + i))[component_index])), 1); 146 | if (!ostream_) { 147 | #ifdef PIC_DEBUG 148 | std::cerr << ostream_.tellp() << ": " << "error: " << std::endl; 149 | #endif 150 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 151 | } 152 | } 153 | dump_length -= 128; 154 | dump_begin += 128; 155 | scanline_iterator += 128; 156 | } 157 | if (dump_length > 0) { 158 | uint8_t byte = dump_length; 159 | ostream_.write(reinterpret_cast(&byte), 1); 160 | if (!ostream_) { 161 | #ifdef PIC_DEBUG 162 | std::cerr << ostream_.tellp() << ": " << "error: " << std::endl; 163 | #endif 164 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 165 | } 166 | for (std::size_t i = 0; i < dump_length; ++i) { 167 | ostream_.write(reinterpret_cast(&((*(dump_begin + i))[component_index])), 1); 168 | if (!ostream_) { 169 | #ifdef PIC_DEBUG 170 | std::cerr << ostream_.tellp() << ": " << "error: " << std::endl; 171 | #endif 172 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 173 | } 174 | } 175 | scanline_iterator += dump_length; 176 | } 177 | } 178 | // run 179 | if (run_length >= 2) { 180 | uint8_t byte = 128 + run_length; 181 | ostream_.write(reinterpret_cast(&byte), 1); 182 | if (!ostream_) { 183 | #ifdef PIC_DEBUG 184 | std::cerr << ostream_.tellp() << ": " << "error: " << std::endl; 185 | #endif 186 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 187 | } 188 | ostream_.write(reinterpret_cast(&((*run_begin)[component_index])), 1); 189 | if (!ostream_) { 190 | #ifdef PIC_DEBUG 191 | std::cerr << ostream_.tellp() << ": " << "error: " << std::endl; 192 | #endif 193 | throw pic::runtime_error(std::string("pic: error: ") + __FUNCTION__); 194 | } 195 | scanline_iterator += run_length; 196 | } 197 | } 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /media/Close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Acly/hdrv/0d68b52b8b25f8f67731f1ef41cce240c31e4031/media/Close.png -------------------------------------------------------------------------------- /media/CloseActive.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Acly/hdrv/0d68b52b8b25f8f67731f1ef41cce240c31e4031/media/CloseActive.png -------------------------------------------------------------------------------- /media/Compare.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Acly/hdrv/0d68b52b8b25f8f67731f1ef41cce240c31e4031/media/Compare.png -------------------------------------------------------------------------------- /media/CompareActive.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Acly/hdrv/0d68b52b8b25f8f67731f1ef41cce240c31e4031/media/CompareActive.png -------------------------------------------------------------------------------- /media/Comparison.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Acly/hdrv/0d68b52b8b25f8f67731f1ef41cce240c31e4031/media/Comparison.png -------------------------------------------------------------------------------- /media/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Acly/hdrv/0d68b52b8b25f8f67731f1ef41cce240c31e4031/media/Default.png -------------------------------------------------------------------------------- /media/FormatByte.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Acly/hdrv/0d68b52b8b25f8f67731f1ef41cce240c31e4031/media/FormatByte.png -------------------------------------------------------------------------------- /media/FormatEXR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Acly/hdrv/0d68b52b8b25f8f67731f1ef41cce240c31e4031/media/FormatEXR.png -------------------------------------------------------------------------------- /media/FormatHDR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Acly/hdrv/0d68b52b8b25f8f67731f1ef41cce240c31e4031/media/FormatHDR.png -------------------------------------------------------------------------------- /media/FormatPFM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Acly/hdrv/0d68b52b8b25f8f67731f1ef41cce240c31e4031/media/FormatPFM.png -------------------------------------------------------------------------------- /media/Icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Acly/hdrv/0d68b52b8b25f8f67731f1ef41cce240c31e4031/media/Icon.ico -------------------------------------------------------------------------------- /media/Open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Acly/hdrv/0d68b52b8b25f8f67731f1ef41cce240c31e4031/media/Open.png -------------------------------------------------------------------------------- /media/Properties.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Acly/hdrv/0d68b52b8b25f8f67731f1ef41cce240c31e4031/media/Properties.png -------------------------------------------------------------------------------- /media/Save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Acly/hdrv/0d68b52b8b25f8f67731f1ef41cce240c31e4031/media/Save.png -------------------------------------------------------------------------------- /media/Screenshots.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Acly/hdrv/0d68b52b8b25f8f67731f1ef41cce240c31e4031/media/Screenshots.png -------------------------------------------------------------------------------- /media/Settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Acly/hdrv/0d68b52b8b25f8f67731f1ef41cce240c31e4031/media/Settings.png -------------------------------------------------------------------------------- /media/SingleInstance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Acly/hdrv/0d68b52b8b25f8f67731f1ef41cce240c31e4031/media/SingleInstance.png -------------------------------------------------------------------------------- /media/hdrv.rc: -------------------------------------------------------------------------------- 1 | IDI_ICON1 ICON DISCARDABLE "Icon.ico" 2 | -------------------------------------------------------------------------------- /thumbnails/ClassFactory.cpp: -------------------------------------------------------------------------------- 1 | #include "ClassFactory.hpp" 2 | #include "Thumbnails.hpp" 3 | #include "ThumbnailProvider.hpp" 4 | #include 5 | 6 | #include 7 | #pragma comment(lib, "shlwapi.lib") 8 | 9 | ClassFactory::ClassFactory(ThumbnailProvider::ImageExtension ext) 10 | : referenceCounter_(1), imageExtension_(ext) 11 | { 12 | ++ThumbnailsDll::dllReferenceCounter; 13 | } 14 | 15 | ClassFactory::~ClassFactory() 16 | { 17 | --ThumbnailsDll::dllReferenceCounter; 18 | } 19 | 20 | // IUnknown 21 | 22 | #pragma warning(push) 23 | #pragma warning(disable: 4838) // conversion from 'DWORD' to 'int' requires a narrowing conversion 24 | 25 | IFACEMETHODIMP ClassFactory::QueryInterface(REFIID riid, void **ppv) 26 | { 27 | static const QITAB qit[] = 28 | { 29 | QITABENT(ClassFactory, IClassFactory), 30 | { 0 }, 31 | }; 32 | return QISearch(this, qit, riid, ppv); 33 | } 34 | 35 | #pragma warning(pop) 36 | 37 | IFACEMETHODIMP_(ULONG) ClassFactory::AddRef() 38 | { 39 | return ++referenceCounter_; 40 | } 41 | 42 | IFACEMETHODIMP_(ULONG) ClassFactory::Release() 43 | { 44 | ULONG cRef = --referenceCounter_; 45 | if (0 == cRef) 46 | { 47 | delete this; 48 | } 49 | return cRef; 50 | } 51 | 52 | // IClassFactory 53 | 54 | IFACEMETHODIMP ClassFactory::CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppv) 55 | { 56 | HRESULT hr = CLASS_E_NOAGGREGATION; 57 | 58 | // pUnkOuter is used for aggregation. We do not support it. 59 | if (pUnkOuter == NULL) 60 | { 61 | hr = E_OUTOFMEMORY; 62 | 63 | // Create the COM component. 64 | ThumbnailProvider *pExt = new (std::nothrow) ThumbnailProvider(imageExtension_); 65 | if (pExt) 66 | { 67 | // Query the specified interface. 68 | hr = pExt->QueryInterface(riid, ppv); 69 | pExt->Release(); 70 | } 71 | } 72 | 73 | return hr; 74 | } 75 | 76 | IFACEMETHODIMP ClassFactory::LockServer(BOOL fLock) 77 | { 78 | if (fLock) 79 | { 80 | ++ThumbnailsDll::dllReferenceCounter; 81 | } 82 | else 83 | { 84 | --ThumbnailsDll::dllReferenceCounter; 85 | } 86 | return S_OK; 87 | } 88 | -------------------------------------------------------------------------------- /thumbnails/ClassFactory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ThumbnailProvider.hpp" 4 | 5 | #include // IClassFactory 6 | #include 7 | #include 8 | 9 | class ClassFactory : public IClassFactory 10 | { 11 | public: 12 | // IUnknown 13 | IFACEMETHODIMP QueryInterface(REFIID riid, void **ppv); 14 | IFACEMETHODIMP_(ULONG) AddRef(); 15 | IFACEMETHODIMP_(ULONG) Release(); 16 | 17 | // IClassFactory 18 | IFACEMETHODIMP CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppv); 19 | IFACEMETHODIMP LockServer(BOOL fLock); 20 | 21 | ClassFactory(ThumbnailProvider::ImageExtension ext); 22 | 23 | protected: 24 | ~ClassFactory(); 25 | 26 | private: 27 | std::atomic referenceCounter_; 28 | ThumbnailProvider::ImageExtension imageExtension_; 29 | }; 30 | -------------------------------------------------------------------------------- /thumbnails/Registry.cpp: -------------------------------------------------------------------------------- 1 | #include "Registry.hpp" 2 | 3 | const std::string ThumbnailProviderRegistration::thumbnailProviderCLSID_ = "{e357fccd-a995-4576-b01f-234630154e96}"; 4 | 5 | Registry::Registry(std::string const & subKey, OpenMode openMode, HKEY root) 6 | { 7 | if (openMode == OpenMode::Create) 8 | { 9 | check( 10 | RegCreateKeyExA( 11 | root, subKey.size() ? subKey.c_str() : nullptr, 0, nullptr, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE | DELETE, 12 | nullptr, &hKey_, nullptr), 13 | "Error creating key: " + subKey); 14 | } 15 | else 16 | { 17 | REGSAM mode; 18 | 19 | switch (openMode) 20 | { 21 | case OpenMode::Read: mode = KEY_READ; break; 22 | case OpenMode::ReadWrite: mode = KEY_READ | KEY_WRITE | DELETE; break; 23 | default: throw std::runtime_error("Unknown OpenMode."); 24 | } 25 | 26 | check( 27 | RegOpenKeyExA(root, subKey.size() ? subKey.c_str() : nullptr, 0, mode, &hKey_), 28 | "Error opening key: " + subKey); 29 | } 30 | } 31 | 32 | Registry::~Registry() 33 | { 34 | check(RegCloseKey(hKey_), "Error closing key"); 35 | } 36 | 37 | bool Registry::keyExists(std::string const &subKey, HKEY root) 38 | { 39 | try { 40 | Registry(subKey, Registry::OpenMode::Read, root); 41 | } catch(std::runtime_error const&) { 42 | return false; 43 | } 44 | return true; 45 | } 46 | 47 | std::string Registry::readString(std::string const & valueName) 48 | { 49 | DWORD buflen = MAX_PATH-1; 50 | DWORD type; 51 | uint8_t buf[MAX_PATH] = {}; 52 | LSTATUS result = RegQueryValueExA(hKey_, valueName.c_str(), nullptr, 53 | &type, buf, &buflen); 54 | 55 | if (valueName.size() == 0 && (result == ERROR_FILE_NOT_FOUND)) { 56 | return ""; 57 | } 58 | 59 | check(result, 60 | "Error reading value"); 61 | if (type != REG_SZ && type != REG_MULTI_SZ && type != REG_EXPAND_SZ) { 62 | throw std::runtime_error("Value has unexpected type."); 63 | } 64 | 65 | return std::string(reinterpret_cast(buf)); 66 | } 67 | 68 | void Registry::writeString(std::string const & valueName, std::string const & value) 69 | { 70 | check( 71 | RegSetValueExA(hKey_, valueName.c_str(), 0, 72 | REG_SZ, reinterpret_cast(value.c_str()), static_cast(value.size() + 1)), 73 | "Error writing value"); 74 | } 75 | 76 | void Registry::deleteKeyRecursive(std::string const & subKey) 77 | { 78 | check( 79 | RegDeleteTreeA(hKey_, subKey.c_str()), 80 | "Error deleting key tree"); 81 | } 82 | 83 | void Registry::check(LSTATUS ls, std::string const & failureMsg) { 84 | HRESULT hr = HRESULT_FROM_WIN32(ls); 85 | if (FAILED(hr)) 86 | { 87 | std::ostringstream ss; 88 | ss << "hdrv.thumbnail registry failue: " << failureMsg << "; HRESULT(0x" << std::hex << hr << ")"; 89 | throw std::runtime_error(ss.str()); 90 | } 91 | } 92 | 93 | 94 | void ThumbnailProviderRegistration::registerInprocServer(std::string const & inprocSvrClsid, std::string const & friendlyName, std::string const & absoluteSvrPath) 95 | { 96 | const std::string keyBase = "CLSID\\" + inprocSvrClsid; 97 | Registry(keyBase, Registry::OpenMode::Create).writeString("", friendlyName); 98 | Registry inprocSvr(keyBase + "\\InprocServer32", Registry::OpenMode::Create); 99 | inprocSvr.writeString("", absoluteSvrPath); 100 | inprocSvr.writeString("ThreadingModel", "Apartment"); 101 | } 102 | 103 | void ThumbnailProviderRegistration::unregisterInprocServer(std::string const & inprocSvrClsid) 104 | { 105 | Registry("CLSID").deleteKeyRecursive(inprocSvrClsid); 106 | } 107 | 108 | void ThumbnailProviderRegistration::registerThumbnailHandler(std::string const & fileExtension, std::string const & inprocSvrClsid) 109 | { 110 | std::string fileType = Registry(fileExtension, Registry::OpenMode::Create).readString(); 111 | std::string keyBase = fileExtension; 112 | if (fileType.size() > 0) { 113 | keyBase = fileType; 114 | } 115 | Registry(keyBase + "\\shellex\\" + thumbnailProviderCLSID_, Registry::OpenMode::Create) 116 | .writeString("", inprocSvrClsid); 117 | } 118 | 119 | void ThumbnailProviderRegistration::unregisterThumbnailHandler(std::string const & fileExtension) 120 | { 121 | std::string fileType = Registry(fileExtension).readString(); 122 | if (fileType.size() > 0) { 123 | removeKeyIfExists(fileExtension + "\\shellex\\" + thumbnailProviderCLSID_); 124 | } 125 | removeKeyIfExists(fileType + "\\shellex\\" + thumbnailProviderCLSID_); 126 | } 127 | 128 | void ThumbnailProviderRegistration::removeKeyIfExists(std::string const & key) { 129 | if (Registry::keyExists(key)) { 130 | Registry().deleteKeyRecursive(key); 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /thumbnails/Registry.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | class Registry 10 | { 11 | public: 12 | enum class OpenMode { Create, ReadWrite, Read }; 13 | 14 | Registry(std::string const &subKey = "", OpenMode openMode = OpenMode::ReadWrite, HKEY root = HKEY_CLASSES_ROOT); 15 | ~Registry(); 16 | 17 | static bool keyExists(std::string const &subKey, HKEY root = HKEY_CLASSES_ROOT); 18 | 19 | std::string readString(std::string const &valueName = ""); 20 | void writeString(std::string const &valueName, std::string const &value); 21 | void deleteKeyRecursive(std::string const &subKey); 22 | 23 | protected: 24 | void check(LSTATUS ls, std::string const &failureMsg); 25 | 26 | HKEY hKey_ = 0; 27 | }; 28 | 29 | class ThumbnailProviderRegistration 30 | { 31 | public: 32 | static void registerInprocServer(std::string const &inprocSvrClsid, std::string const &friendlyName, std::string const &absoluteSvrPath); 33 | static void unregisterInprocServer(std::string const &inprocSvrClsid); 34 | 35 | static void registerThumbnailHandler(std::string const &fileExtension, std::string const &inprocSvrClsid); 36 | static void unregisterThumbnailHandler(std::string const &fileExtension); 37 | 38 | protected: 39 | static void removeKeyIfExists(std::string const &key); 40 | 41 | static const std::string thumbnailProviderCLSID_; 42 | }; 43 | -------------------------------------------------------------------------------- /thumbnails/ThumbnailProvider.cpp: -------------------------------------------------------------------------------- 1 | #include "ThumbnailProvider.hpp" 2 | #include "Thumbnails.hpp" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | // Why Microsoft, why? 13 | #ifdef min 14 | # undef min 15 | #endif 16 | 17 | #pragma comment(lib, "Shlwapi.lib") 18 | 19 | struct Buffer : std::streambuf 20 | { 21 | std::unique_ptr data; 22 | size_t size = 0; 23 | 24 | Buffer() = default; 25 | explicit Buffer(size_t size) 26 | : data(new std::byte[size]) 27 | , size(size) 28 | { 29 | char* begin = reinterpret_cast(data.get()); 30 | this->setg(begin, begin, begin + size); 31 | } 32 | }; 33 | 34 | 35 | ThumbnailProvider::ThumbnailProvider(ImageExtension ext) 36 | : referenceCounter_(1), stream_(nullptr), imageExtension_(ext) 37 | { 38 | ++ThumbnailsDll::dllReferenceCounter; 39 | } 40 | 41 | ThumbnailProvider::~ThumbnailProvider() 42 | { 43 | --ThumbnailsDll::dllReferenceCounter; 44 | } 45 | 46 | // IUnknown 47 | 48 | #pragma warning(push) 49 | #pragma warning(disable: 4838) // conversion from 'DWORD' to 'int' requires a narrowing conversion 50 | 51 | IFACEMETHODIMP ThumbnailProvider::QueryInterface(REFIID riid, void **ppv) 52 | { 53 | static const QITAB qit[] = 54 | { 55 | QITABENT(ThumbnailProvider, IThumbnailProvider), 56 | QITABENT(ThumbnailProvider, IInitializeWithStream), 57 | { 0 }, 58 | }; 59 | return QISearch(this, qit, riid, ppv); 60 | } 61 | 62 | #pragma warning(pop) 63 | 64 | IFACEMETHODIMP_(ULONG) ThumbnailProvider::AddRef() 65 | { 66 | return ++referenceCounter_; 67 | } 68 | 69 | IFACEMETHODIMP_(ULONG) ThumbnailProvider::Release() 70 | { 71 | ULONG cRef = --referenceCounter_; 72 | if (0 == cRef) 73 | { 74 | delete this; 75 | } 76 | 77 | return cRef; 78 | } 79 | 80 | // IInitializeWithStream 81 | 82 | IFACEMETHODIMP ThumbnailProvider::Initialize(IStream *stream, DWORD /*grfMode*/) 83 | { 84 | // A handler instance should be initialized only once in its lifetime. 85 | HRESULT hr = HRESULT_FROM_WIN32(ERROR_ALREADY_INITIALIZED); 86 | if (stream_ == nullptr) 87 | { 88 | // Take a reference to the stream if it has not been initialized yet. 89 | hr = stream->QueryInterface(&stream_); 90 | } 91 | return hr; 92 | } 93 | 94 | // IThumbnailProvider 95 | 96 | // Gets a thumbnail image and alpha type. The GetThumbnail is called with the 97 | // largest desired size of the image, in pixels. Although the parameter is 98 | // called cx, this is used as the maximum size of both the x and y dimensions. 99 | // If the retrieved thumbnail is not square, then the longer axis is limited 100 | // by cx and the aspect ratio of the original image respected. On exit, 101 | // GetThumbnail provides a handle to the retrieved image. It also provides a 102 | // value that indicates the color format of the image and whether it has 103 | // valid alpha information. 104 | IFACEMETHODIMP ThumbnailProvider::GetThumbnail(UINT cx, HBITMAP* phbmp, 105 | WTS_ALPHATYPE* pdwAlpha) 106 | { 107 | HRESULT hr = E_OUTOFMEMORY; 108 | 109 | // Read data from stream 110 | STATSTG streamStat{}; 111 | if (HRESULT r = stream_->Stat(&streamStat, STATFLAG_NONAME); r != S_OK) { 112 | OutputDebugStringA("hdrv.thumbnail error: IStream::Stat failed"); 113 | return r; 114 | } 115 | 116 | if (streamStat.cbSize.QuadPart > 132710400ull) { 117 | // Avoid spending too many system resources on thumbnails 118 | OutputDebugStringA("hdrv.thumbnail warning: File too large"); 119 | return E_ABORT; 120 | } 121 | 122 | Buffer streamBuffer(streamStat.cbSize.QuadPart); 123 | ULONG bytesRead = 0; 124 | if (HRESULT r = stream_->Read(streamBuffer.data.get(), ULONG(streamBuffer.size), &bytesRead); r != S_OK) { 125 | OutputDebugStringA("hdrv.thumbnail error: IStream::Read failed"); 126 | return r; 127 | } 128 | 129 | // Load the image from the stream 130 | auto img = hdrv::Result("Unsupported image format"); 131 | std::istream stdStream(&streamBuffer); 132 | switch (imageExtension_) { 133 | case ImageExtension::EXR: { img = hdrv::Image::loadEXR(streamBuffer.data.get(), streamBuffer.size); break; } 134 | case ImageExtension::PFM: { img = hdrv::Image::loadPFM(stdStream); break; } 135 | case ImageExtension::PIC: { img = hdrv::Image::loadPIC(stdStream); break; } 136 | } 137 | if (!img) { 138 | std::string err = "hdrv.thumbnail error: " + img.error(); 139 | OutputDebugStringA(err.c_str()); 140 | return E_FAIL; 141 | } 142 | auto pic = std::move(img).value(); 143 | streamBuffer = {}; 144 | 145 | // Downscale image to desired maximum resolution cx 146 | int maxIterations = 16; 147 | while ((uint32_t)pic.width() > cx || (uint32_t)pic.height() > cx) { 148 | if (--maxIterations == 0) { 149 | OutputDebugStringA("hdrv.thumbnail error: too many iterations"); 150 | return E_FAIL; 151 | } 152 | 153 | pic = pic.scaleByHalf().value(); 154 | } 155 | 156 | // Put everything into a bitmap 157 | uint32_t nWidth = pic.width(), nHeight = pic.height(); 158 | 159 | BITMAPINFO bmi = {sizeof(bmi.bmiHeader)}; 160 | bmi.bmiHeader.biWidth = nWidth; 161 | bmi.bmiHeader.biHeight = -static_cast(nHeight); 162 | bmi.bmiHeader.biPlanes = 1; 163 | bmi.bmiHeader.biBitCount = 32; 164 | bmi.bmiHeader.biCompression = BI_RGB; 165 | 166 | uint8_t* pBits; 167 | HBITMAP hbmp = CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, reinterpret_cast(&pBits), NULL, 0); 168 | if (hbmp) { 169 | hr = S_OK; 170 | *phbmp = hbmp; 171 | *pdwAlpha = (pic.channels() > 3) ? WTSAT_ARGB : WTSAT_RGB; 172 | 173 | // Simple gamma correction, clamping and 8 bit conversion 174 | // (will break on negative input, e.g. normal maps) 175 | auto gamma = [](float in)->uint8_t { 176 | return (uint8_t)std::min(powf(in, 1.f / 2.2f) * 255.f, 255.f); 177 | }; 178 | 179 | for (uint32_t x = 0; x < nWidth; ++x) { 180 | for (uint32_t y = 0; y < nHeight; ++y) 181 | { 182 | const int pixelstride = 4; 183 | const int linestride = pixelstride * nWidth; 184 | 185 | uint8_t r = 0, g = 0, b = 0, a = 255; 186 | 187 | r = g = b = gamma(pic.value(x, y, 0)); 188 | if (pic.channels() > 1) g = gamma(pic.value(x, y, 1)); 189 | if (pic.channels() > 2) b = gamma(pic.value(x, y, 2)); 190 | if (pic.channels() > 3) a = gamma(pic.value(x, y, 3)); 191 | 192 | pBits[linestride * y + pixelstride * x + 0] = b; 193 | pBits[linestride * y + pixelstride * x + 1] = g; 194 | pBits[linestride * y + pixelstride * x + 2] = r; 195 | pBits[linestride * y + pixelstride * x + 3] = a; 196 | } 197 | } 198 | } 199 | return hr; 200 | } 201 | -------------------------------------------------------------------------------- /thumbnails/ThumbnailProvider.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include // IThumbnailProvider 5 | 6 | #include 7 | 8 | class ThumbnailProvider : 9 | public IInitializeWithStream, 10 | public IThumbnailProvider 11 | { 12 | public: 13 | 14 | enum class ImageExtension { PFM, PIC, EXR }; 15 | 16 | // IUnknown 17 | IFACEMETHODIMP QueryInterface(REFIID riid, void **ppv); 18 | IFACEMETHODIMP_(ULONG) AddRef(); 19 | IFACEMETHODIMP_(ULONG) Release(); 20 | 21 | // IInitializeWithStream 22 | IFACEMETHODIMP Initialize(IStream *stream, DWORD grfMode); 23 | 24 | // IThumbnailProvider 25 | IFACEMETHODIMP GetThumbnail(UINT cx, HBITMAP *phbmp, WTS_ALPHATYPE *pdwAlpha); 26 | 27 | ThumbnailProvider(ImageExtension ext); 28 | 29 | protected: 30 | ~ThumbnailProvider(); 31 | 32 | private: 33 | std::atomic referenceCounter_; 34 | IStream *stream_; 35 | ImageExtension imageExtension_; 36 | }; 37 | -------------------------------------------------------------------------------- /thumbnails/Thumbnails.cpp: -------------------------------------------------------------------------------- 1 | #include "Thumbnails.hpp" 2 | 3 | #include 4 | #include 5 | 6 | #include "Registry.hpp" 7 | #include "ClassFactory.hpp" 8 | #include "ThumbnailProvider.hpp" 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #pragma comment( linker, "/export:DllGetClassObject,PRIVATE" ) 16 | #pragma comment( linker, "/export:DllCanUnloadNow,PRIVATE" ) 17 | #pragma comment( linker, "/export:DllRegisterServer,PRIVATE" ) 18 | #pragma comment( linker, "/export:DllUnregisterServer,PRIVATE" ) 19 | 20 | HINSTANCE ThumbnailsDll::hInstance = NULL; 21 | std::atomic ThumbnailsDll::dllReferenceCounter = 0; 22 | 23 | struct ExtensionProvider 24 | { 25 | CLSID clsid; 26 | ThumbnailProvider::ImageExtension extensionType; 27 | std::vector extensionList; 28 | }; 29 | 30 | const std::vector supportedExtensions{ 31 | // {20EEDC07-F4E2-428C-9D35-F48EBF5B4D00} 32 | { { 0x20eedc07, 0xf4e2, 0x428c, { 0x9d, 0x35, 0xf4, 0x8e, 0xbf, 0x5b, 0x4d, 0x00 } }, ThumbnailProvider::ImageExtension::PIC, { ".hdr", ".pic" } }, 33 | // {20EEDC07-F4E2-428C-9D35-F48EBF5B4D01} 34 | { { 0x20eedc07, 0xf4e2, 0x428c, { 0x9d, 0x35, 0xf4, 0x8e, 0xbf, 0x5b, 0x4d, 0x01 } }, ThumbnailProvider::ImageExtension::PFM, { ".pfm", ".ppm" } }, 35 | // {20EEDC07-F4E2-428C-9D35-F48EBF5B4D02} 36 | { { 0x20eedc07, 0xf4e2, 0x428c, { 0x9d, 0x35, 0xf4, 0x8e, 0xbf, 0x5b, 0x4d, 0x02 } }, ThumbnailProvider::ImageExtension::EXR, { ".exr" } } 37 | }; 38 | 39 | std::string clsidToString(CLSID const& clsid) 40 | { 41 | wchar_t wclsid[MAX_PATH]; 42 | int wideSize = StringFromGUID2(clsid, wclsid, ARRAYSIZE(wclsid)); 43 | int mbSize = WideCharToMultiByte(CP_UTF8, 0, wclsid, wideSize, nullptr, 0, nullptr, nullptr); 44 | std::string result(mbSize - 1, 0); 45 | WideCharToMultiByte(CP_UTF8, 0, wclsid, wideSize, result.data(), mbSize, nullptr, nullptr); 46 | return result; 47 | } 48 | 49 | std::string getModuleFilePath() 50 | { 51 | char moduleName[MAX_PATH]; 52 | if (GetModuleFileNameA(ThumbnailsDll::hInstance, moduleName, MAX_PATH) == 0) 53 | { 54 | std::ostringstream ss; 55 | ss << "hdrv.thumbnail failure: could not retrieve module file name; HRESULT(0x" << std::hex << HRESULT_FROM_WIN32(GetLastError()) << ")"; 56 | throw std::runtime_error(ss.str()); 57 | } 58 | return moduleName; 59 | } 60 | 61 | BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID /*lpReserved*/) 62 | { 63 | if(dwReason == DLL_PROCESS_ATTACH) { 64 | ThumbnailsDll::hInstance = hModule; 65 | DisableThreadLibraryCalls(hModule); 66 | } 67 | return TRUE; 68 | } 69 | 70 | STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv) 71 | { 72 | HRESULT hr = CLASS_E_CLASSNOTAVAILABLE; 73 | 74 | auto extProviderIt = std::find_if(supportedExtensions.cbegin(), supportedExtensions.cend(), [&rclsid](ExtensionProvider const &provider)->bool { 75 | return IsEqualCLSID(provider.clsid, rclsid) == TRUE; 76 | }); 77 | 78 | if (extProviderIt != supportedExtensions.cend()) 79 | { 80 | hr = E_OUTOFMEMORY; 81 | 82 | ClassFactory *pClassFactory = new (std::nothrow) ClassFactory(extProviderIt->extensionType); 83 | if (pClassFactory) 84 | { 85 | hr = pClassFactory->QueryInterface(riid, ppv); 86 | pClassFactory->Release(); 87 | } 88 | } 89 | 90 | return hr; 91 | } 92 | 93 | STDAPI DllCanUnloadNow(void) 94 | { 95 | return ThumbnailsDll::dllReferenceCounter > 0 ? S_FALSE : S_OK; 96 | } 97 | 98 | STDAPI DllRegisterServer(void) 99 | { 100 | HRESULT hr = S_OK; 101 | 102 | try 103 | { 104 | std::string moduleName = getModuleFilePath(); 105 | 106 | for (auto const & ext : supportedExtensions) 107 | { 108 | std::string clsid = clsidToString(ext.clsid); 109 | 110 | // Register the component. 111 | ThumbnailProviderRegistration::registerInprocServer(clsid, "hdrv.ThumbnailProvider Class", moduleName); 112 | 113 | // Register the thumbnail handler. 114 | for (auto const &extension : ext.extensionList) { 115 | ThumbnailProviderRegistration::registerThumbnailHandler(extension, clsid); 116 | } 117 | 118 | // This tells the shell to invalidate the thumbnail cache. It is 119 | // important because any of our files viewed before registering 120 | // this handler would otherwise show cached blank thumbnails. 121 | SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); 122 | } 123 | } 124 | catch (std::exception const &e) 125 | { 126 | std::ostringstream ss; 127 | ss << "hdrv.thumbnail - Failed to register thumbnail handler:" << std::endl << std::endl << e.what(); 128 | std::string err = ss.str(); 129 | MessageBoxA(0, err.c_str(), "hdrv.thumbnail - Failed to register thumbnail handler", MB_ICONERROR | MB_OK); 130 | hr = E_FAIL; 131 | } 132 | 133 | return hr; 134 | } 135 | 136 | STDAPI DllUnregisterServer(void) 137 | { 138 | HRESULT hr = S_OK; 139 | 140 | for (auto const & ext : supportedExtensions) 141 | { 142 | try 143 | { 144 | // Unregister the component. 145 | ThumbnailProviderRegistration::unregisterInprocServer(clsidToString(ext.clsid)); 146 | 147 | // Unregister the thumbnail handler. 148 | for (auto const &extension : ext.extensionList) { 149 | ThumbnailProviderRegistration::unregisterThumbnailHandler(extension); 150 | } 151 | } 152 | catch (std::exception const &e) 153 | { 154 | // only show one error message 155 | if (SUCCEEDED(hr)) 156 | { 157 | std::ostringstream ss; 158 | ss << "hdrv.thumbnail - Failed to unregister thumbnail handler - was it already unregistered?" << std::endl << std::endl << e.what(); 159 | std::string err = ss.str(); 160 | MessageBoxA(0, err.c_str(), "hdrv.thumbnail - Failed to register thumbnail handler", MB_ICONERROR | MB_OK); 161 | hr = E_FAIL; 162 | } 163 | } 164 | } 165 | 166 | return hr; 167 | } 168 | -------------------------------------------------------------------------------- /thumbnails/Thumbnails.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | struct ThumbnailsDll 7 | { 8 | static HINSTANCE hInstance; 9 | static std::atomic dllReferenceCounter; 10 | }; 11 | -------------------------------------------------------------------------------- /viewer/Main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace hdrv; 15 | 16 | void moveToForeground() 17 | { 18 | QWindowList l = QGuiApplication::allWindows(); 19 | if (l.size() > 0 && l.at(0) != nullptr) { 20 | QWindow* w = l.at(0); 21 | w->requestActivate(); 22 | if (w->windowState() & Qt::WindowMinimized) { 23 | w->showNormal(); 24 | } 25 | } 26 | } 27 | 28 | int main(int argc, char * argv[]) 29 | { 30 | QGuiApplication app(argc, argv); 31 | qmlRegisterType("Hdrv", 1, 0, "ImageDocument"); 32 | qmlRegisterType("Hdrv", 1, 0, "ImageCollection"); 33 | qmlRegisterType("Hdrv", 1, 0, "ImageArea"); 34 | qmlRegisterType("Hdrv", 1, 0, "Settings"); 35 | qmlRegisterType("Hdrv", 1, 0, "Server"); 36 | qmlRegisterType("Hdrv", 1, 0, "Client"); 37 | 38 | QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL); 39 | 40 | Settings settings; 41 | IPCServer server; 42 | IPCClient client; 43 | ImageCollection images; 44 | QQmlApplicationEngine engine; 45 | engine.rootContext()->setContextProperty("settings", &settings); 46 | engine.rootContext()->setContextProperty("images", &images); 47 | engine.rootContext()->setContextProperty("server", &server); 48 | engine.rootContext()->setContextProperty("client", &client); 49 | 50 | QObject::connect(&server, SIGNAL(openFile(QUrl const &)), &images, SLOT(load(QUrl const &))); 51 | QObject::connect(&server, &IPCServer::openFile, &moveToForeground); 52 | 53 | bool fileOpened = false; 54 | for (int i = 1; i < app.arguments().count(); ++i) { 55 | auto url = QUrl::fromLocalFile(app.arguments()[i]); 56 | if (!client.remoteOpenFile(url)) { 57 | images.load(url); 58 | fileOpened = true; 59 | } 60 | } 61 | 62 | if (app.arguments().count() > 1 && !fileOpened) { 63 | return 0; 64 | } 65 | 66 | if (settings.singleInstance() && !client.isServerAvailable()) { 67 | server.start(); 68 | } 69 | 70 | engine.load(QUrl("qrc:/hdrv/view/Main.qml")); 71 | 72 | return app.exec(); 73 | } 74 | -------------------------------------------------------------------------------- /viewer/image/Image.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace hdrv { 10 | 11 | template 12 | class Result 13 | { 14 | public: 15 | operator bool() const { return (bool)value_; } 16 | T const& value() const& { return value_.value(); } 17 | T && value() && { return std::move(value_.value()); } 18 | std::string const& error() const { return error_; } 19 | 20 | Result(T && v) : value_(std::move(v)) {} 21 | Result(std::string const& error) : error_(error) {} 22 | 23 | private: 24 | std::string error_; 25 | std::optional value_; 26 | }; 27 | 28 | class Image 29 | { 30 | public: 31 | enum Format { Byte, Float }; 32 | enum Display { Color, Luminance, Depth, Normal, Integer }; 33 | 34 | struct Layer { 35 | std::string name; 36 | int channels; 37 | Display display; 38 | size_t offset; 39 | }; 40 | 41 | static Image makeEmpty(); 42 | 43 | static Result loadPFM(std::string const& path); 44 | static Result loadPIC(std::string const& path); 45 | static Result loadEXR(std::string const& path); 46 | static Result loadImage(std::string const& path); 47 | 48 | static Result loadPFM(std::istream& stream); 49 | static Result loadPIC(std::istream& stream); 50 | static Result loadEXR(std::byte const*, size_t); 51 | 52 | int width() const { return width_; } 53 | int height() const { return height_; } 54 | int channels(int layer = 0) const { return layer == 0 ? channels_ : layers_[layer].channels; } 55 | int pixelSizeInBytes() const { return format_ == Byte ? sizeof(uint8_t) : sizeof(float); } 56 | int sizeInBytes() const { return width_ * height_ * channels_ * pixelSizeInBytes(); } 57 | Format format() const { return format_; } 58 | uint8_t const* data() const { return data_.data(); } 59 | float value(int x, int y, int channel, int layer = 0) const; 60 | 61 | std::vector const& layers() const { return layers_; } 62 | 63 | Result storePFM(std::string const& path) const; 64 | Result storePIC(std::string const& path) const; 65 | Result storeEXR(std::string const& path) const; 66 | Result storeImage(std::string const& path, float brightness, float gamma) const; 67 | 68 | Result scaleByHalf() const; 69 | 70 | Image(int w, int h, int c, Format f, std::vector&& data); 71 | Image(int w, int h, Format f, std::vector&& data, std::vector&& layers); 72 | 73 | private: 74 | 75 | int width_; 76 | int height_; 77 | int channels_; 78 | Format format_; 79 | std::vector data_; 80 | std::vector layers_; 81 | }; 82 | 83 | } -------------------------------------------------------------------------------- /viewer/model/ImageCollection.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | namespace hdrv { 7 | 8 | ImageCollection::ImageCollection(QObject * parent) 9 | : QObject(parent) 10 | , currentIndex_(-1) 11 | { 12 | connect(this, SIGNAL(currentIndexChanged()), this, SLOT(updateRecentItems())); 13 | 14 | add(new ImageDocument); 15 | setCurrentIndex(0); 16 | } 17 | 18 | void ImageCollection::add(ImageDocument * image) 19 | { 20 | if (items_.size() == 1 && items_[0]->isDefault()) { 21 | items_.clear(); 22 | } 23 | items_.emplace_back(image); 24 | currentIndex_ = (int)items_.size() - 1; 25 | emit itemsChanged(); 26 | emit currentIndexChanged(); 27 | emit currentChanged(); 28 | } 29 | 30 | void ImageCollection::load(QUrl const& url) 31 | { 32 | add(new ImageDocument(url, this)); 33 | } 34 | 35 | void ImageCollection::replace(int index, QUrl const& url) 36 | { 37 | auto item = items_[index]; 38 | item->deleteLater(); 39 | items_[index] = new ImageDocument(url, this); 40 | items_[index]->setPosition(item->position()); 41 | items_[index]->setScale(item->scale()); 42 | emit itemsChanged(); 43 | emit currentIndexChanged(); 44 | emit currentChanged(); 45 | } 46 | 47 | void ImageCollection::remove(int index) 48 | { 49 | auto item = items_[index]; 50 | recentItems_.removeOne(index); 51 | currentIndex_ = std::min(currentIndex(), (int)items_.size() - 2); 52 | items_.erase(items_.begin() + index); 53 | emit itemsChanged(); 54 | emit currentIndexChanged(); 55 | emit currentChanged(); 56 | item->deleteLater(); 57 | } 58 | 59 | QUrl ImageCollection::nextFile(bool prev) 60 | { 61 | if (items_.size() == 1 && items_[0]->isDefault()) { 62 | return QUrl(); 63 | } 64 | 65 | QFileInfo currentFile(items_[currentIndex()]->url().toLocalFile()); 66 | QDir dir(currentFile.absolutePath()); 67 | 68 | auto list = dir.entryList(supportedFormats(), QDir::Files, QDir::Name | QDir::IgnoreCase); 69 | int index = list.indexOf(currentFile.fileName()); 70 | if (index == -1) { 71 | return QUrl(); 72 | } 73 | 74 | index += (prev ? -1 : 1); 75 | index = index < 0 ? list.size() - 1 : index; 76 | index = index >= list.size() ? 0 : index; 77 | 78 | QFileInfo nextFile(dir, list[index]); 79 | return QUrl::fromLocalFile(nextFile.absoluteFilePath()); 80 | } 81 | 82 | void ImageCollection::compare(int index) 83 | { 84 | add(new ImageDocument(current()->url(), items_[index]->url(), this)); 85 | } 86 | 87 | void ImageCollection::setCurrentIndex(int i) 88 | { 89 | if (currentIndex_ != i) { 90 | currentIndex_ = i; 91 | emit currentIndexChanged(); 92 | emit currentChanged(); 93 | } 94 | } 95 | 96 | void ImageCollection::updateRecentItems() 97 | { 98 | int index = currentIndex(); 99 | recentItems_.removeOne(index); 100 | recentItems_.push_back(index); 101 | } 102 | 103 | QStringList ImageCollection::supportedFormats() 104 | { 105 | return QStringList() 106 | << "*.png" 107 | << "*.jpg" 108 | << "*.bmp" 109 | << "*.gif" 110 | << "*.hdr" 111 | << "*.pic" 112 | << "*.pfm" 113 | << "*.ppm" 114 | << "*.exr"; 115 | } 116 | 117 | } -------------------------------------------------------------------------------- /viewer/model/ImageCollection.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | namespace hdrv { 12 | 13 | class ImageCollection : public QObject 14 | { 15 | Q_OBJECT 16 | Q_PROPERTY(QQmlListProperty items READ items NOTIFY itemsChanged) 17 | Q_PROPERTY(QList recentItems READ recentItems) 18 | Q_PROPERTY(ImageDocument* current READ current NOTIFY currentChanged) 19 | Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) 20 | 21 | using Collection = std::vector; 22 | 23 | public: 24 | ImageCollection(QObject * parent = nullptr); 25 | 26 | static qsizetype itemCount(QQmlListProperty * list) 27 | { 28 | return reinterpret_cast(list->data)->size(); 29 | } 30 | 31 | static ImageDocument * itemAt(QQmlListProperty * list, qsizetype index) 32 | { 33 | return reinterpret_cast(list->data)->at(index); 34 | } 35 | 36 | QQmlListProperty items() 37 | { 38 | return QQmlListProperty(this, &items_, &itemCount, &itemAt); 39 | } 40 | 41 | void add(ImageDocument * image); 42 | Q_INVOKABLE void load(QUrl const& url); 43 | Q_INVOKABLE void remove(int index); 44 | Q_INVOKABLE void replace(int index, QUrl const& url); 45 | Q_INVOKABLE void compare(int index); 46 | 47 | Q_INVOKABLE QUrl nextFile(bool prev); 48 | Q_INVOKABLE QStringList supportedFormats(); 49 | 50 | ImageDocument * current() const { return items_.at(currentIndex_); } 51 | int currentIndex() const { return currentIndex_; } 52 | QList const& recentItems() const { return recentItems_; }; 53 | 54 | void setCurrentIndex(int i); 55 | 56 | Collection const& vector() const { return items_; } 57 | 58 | signals: 59 | void itemsChanged(); 60 | void currentChanged(); 61 | void currentIndexChanged(); 62 | 63 | private slots: 64 | void updateRecentItems(); 65 | 66 | private: 67 | Collection items_; 68 | QList recentItems_; 69 | int currentIndex_; 70 | }; 71 | 72 | } 73 | 74 | Q_DECLARE_METATYPE(QQmlListProperty) 75 | Q_DECLARE_METATYPE(hdrv::ImageCollection*) 76 | -------------------------------------------------------------------------------- /viewer/model/ImageDocument.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | namespace hdrv { 16 | 17 | std::shared_ptr createDefaultImage() 18 | { 19 | return std::make_shared(Image::makeEmpty()); 20 | } 21 | 22 | QUrl defaultUrl() { return QUrl("file:////HDRV"); } 23 | QString nameFromUrl(QUrl const& url) { return QFileInfo(url.fileName()).completeBaseName(); } 24 | 25 | ImageDocument::ImageDocument(QUrl const& url, QObject * parent) 26 | : QObject(parent) 27 | , name_(nameFromUrl(url)) 28 | , url_(url) 29 | , image_(createDefaultImage()) 30 | { 31 | init(); 32 | 33 | watcher_ = setupWatcher(url_, false); 34 | load(url_.toLocalFile(), watcher_); 35 | } 36 | 37 | ImageDocument::ImageDocument(QUrl const& base, QUrl const& comparison, QObject * parent) 38 | : QObject(parent) 39 | , name_(nameFromUrl(base) + " | " + nameFromUrl(comparison)) 40 | , url_(base) 41 | , comparisonUrl_(comparison) 42 | , image_(createDefaultImage()) 43 | { 44 | init(); 45 | 46 | watcher_ = setupWatcher(url_, false); 47 | comparisonWatcher_ = setupWatcher(comparisonUrl_, true); 48 | 49 | load(url_.toLocalFile(), watcher_); 50 | load(comparisonUrl_.toLocalFile(), comparisonWatcher_); 51 | } 52 | 53 | ImageDocument::ImageDocument(QObject * parent) 54 | : QObject(parent) 55 | , url_(defaultUrl()) 56 | , image_(createDefaultImage()) 57 | { 58 | init(); 59 | } 60 | 61 | void ImageDocument::init() 62 | { 63 | QSettings settings; 64 | displayMode_ = (DisplayMode)settings.value("Rendering/DisplayMode").toInt(); 65 | } 66 | 67 | QFutureWatcher* ImageDocument::setupWatcher(QUrl const& url, bool comparison) 68 | { 69 | QFutureWatcher* watcher = new QFutureWatcher(this); 70 | connect(watcher, SIGNAL(started()), this, SIGNAL(busyChanged())); 71 | connect(watcher, SIGNAL(finished()), this, SIGNAL(busyChanged())); 72 | 73 | connect( 74 | watcher, &QFutureWatcher::finished, 75 | std::bind(&ImageDocument::loadFinished, this, watcher, url, comparison)); 76 | 77 | auto* fsWatcher = new QFileSystemWatcher(QStringList(url.toLocalFile()), this); 78 | auto* delay = new QTimer(this); 79 | delay->setSingleShot(true); 80 | 81 | connect( 82 | fsWatcher, &QFileSystemWatcher::fileChanged, 83 | [delay]() { delay->start(500); }); 84 | connect( 85 | delay, &QTimer::timeout, 86 | std::bind(&ImageDocument::load, this, url.toLocalFile(), watcher)); 87 | 88 | return watcher; 89 | } 90 | 91 | QUrl ImageDocument::directory() const 92 | { 93 | return QUrl::fromLocalFile(QFileInfo(url().toLocalFile()).absolutePath()); 94 | } 95 | 96 | QString ImageDocument::fileType() const 97 | { 98 | if (isDefault()) { 99 | return "Default"; 100 | } else if (isComparison()) { 101 | return "Comparison"; 102 | } else if (isFloat()) { 103 | auto ext = QFileInfo(url().fileName()).suffix(); 104 | if (ext == "exr") { 105 | return "FormatEXR"; 106 | } else if (ext == "pfm" || ext == "ppm") { 107 | return "FormatPFM"; 108 | } else { 109 | return "FormatHDR"; 110 | } 111 | } else { // not float 112 | return "FormatByte"; 113 | } 114 | } 115 | 116 | int ImageDocument::channels() const 117 | { // clamp layer_ since QML combo sets it to -1 if it is not populated 118 | return image_->channels(std::clamp(layer_, 0, int(image_->layers().size()))); 119 | } 120 | 121 | QList ImageDocument::layers() const 122 | { 123 | QList list; 124 | for (auto&& layer : image_->layers()) { 125 | if (layer.name.empty()) { 126 | list.push_back(QString("Default")); 127 | } else { 128 | list.push_back(QString::fromStdString(layer.name)); 129 | } 130 | } 131 | if (image_->layers().empty()) { 132 | list.push_back(QString("Default")); 133 | } 134 | return list; 135 | } 136 | 137 | bool ImageDocument::isDefault() const { return url() == defaultUrl(); } 138 | 139 | void ImageDocument::resetError() 140 | { 141 | for (int i = 0; i < errorText_.size(); ++i) { 142 | errorText_[i] = ""; 143 | } 144 | emit errorTextChanged(); 145 | } 146 | 147 | void ImageDocument::setError(QString const& errorText, ErrorCategory category) 148 | { 149 | errorText_[static_cast(category)] = errorText; 150 | emit errorTextChanged(); 151 | } 152 | 153 | void ImageDocument::setPosition(QPointF pos) 154 | { 155 | position_ = pos; 156 | emit positionChanged(); 157 | emit propertyChanged(); 158 | } 159 | 160 | void ImageDocument::move(QPointF offset) 161 | { 162 | setPosition(position() + offset); 163 | } 164 | 165 | void ImageDocument::setScale(qreal scale) 166 | { 167 | if (!qFuzzyCompare(scale_, scale)) { 168 | scale_ = scale; 169 | emit scaleChanged(); 170 | emit propertyChanged(); 171 | } 172 | } 173 | 174 | void ImageDocument::setBrightness(qreal brightness) 175 | { 176 | if (!qFuzzyCompare(brightness_, brightness) && brightness >= minBrightness() && brightness <= maxBrightness()) { 177 | brightness_ = brightness; 178 | emit brightnessChanged(); 179 | emit propertyChanged(); 180 | } 181 | } 182 | 183 | void ImageDocument::setGamma(qreal gamma) 184 | { 185 | if (!qFuzzyCompare(gamma_, gamma) && gamma >= minGamma() && gamma <= maxGamma()) { 186 | gamma_ = gamma; 187 | emit gammaChanged(); 188 | emit propertyChanged(); 189 | } 190 | } 191 | 192 | void ImageDocument::setDisplayMode(DisplayMode displayMode) 193 | { 194 | if (displayMode_ != displayMode) { 195 | displayMode_ = displayMode; 196 | 197 | QSettings settings; 198 | settings.setValue("Rendering/DisplayMode", QVariant((int)displayMode)); 199 | 200 | emit displayModeChanged(); 201 | emit propertyChanged(); 202 | } 203 | } 204 | 205 | void ImageDocument::setCurrentPixel(QPoint index) 206 | { 207 | if (index != pixelPosition_ && index.x() < width() && index.y() < height()) { 208 | pixelPosition_ = index; 209 | emit pixelPositionChanged(); 210 | emit pixelValueChanged(); 211 | } 212 | } 213 | 214 | void ImageDocument::setComparisonMode(ComparisonMode mode) 215 | { 216 | if (comparison_ && comparison_->mode != mode) { 217 | comparison_->mode = mode; 218 | emit comparisonModeChanged(); 219 | emit propertyChanged(); 220 | } 221 | } 222 | 223 | void ImageDocument::setComparisonSeparator(float value) 224 | { 225 | if (comparison_ && !qFuzzyCompare(comparison_->separator, value)) { 226 | comparison_->separator = value; 227 | emit comparisonSeparatorChanged(); 228 | emit propertyChanged(); 229 | } 230 | } 231 | 232 | void ImageDocument::setLayer(int layer) 233 | { 234 | if (layer_ != layer) { 235 | layer_ = layer; 236 | emit layerChanged(); 237 | emit propertyChanged(); 238 | } 239 | } 240 | 241 | void ImageDocument::store(QUrl const& url) 242 | { 243 | QFileInfo file(url.toLocalFile()); 244 | if (file.suffix() == "hdr" || file.suffix() == "pic") { 245 | check(image()->storePIC(file.absoluteFilePath().toStdString()), ErrorCategory::Generic); 246 | } else if (file.suffix() == "pfm" || file.suffix() == "ppm") { 247 | check(image()->storePFM(file.absoluteFilePath().toStdString()), ErrorCategory::Generic); 248 | } else if (file.suffix() == "exr") { 249 | check(image()->storeEXR(file.absoluteFilePath().toStdString()), ErrorCategory::Generic); 250 | } else if (file.suffix() == "png") { 251 | check(image()->storeImage(file.absoluteFilePath().toStdString(), pow(2.0f, brightness()), 1.0f / gamma()), ErrorCategory::Generic); 252 | } else { 253 | setError("Unsupported file extension: " + file.suffix(), ErrorCategory::Generic); 254 | } 255 | } 256 | 257 | QVector4D ImageDocument::pixelValue() const 258 | { 259 | QVector4D texel; 260 | int l = std::clamp(layer_, 0, int(image_->layers().size())); 261 | texel.setX(image_->value(pixelPosition_.x(), pixelPosition_.y(), 0, l)); 262 | if (channels() > 1) { 263 | texel.setY(image_->value(pixelPosition_.x(), pixelPosition_.y(), 1, l)); 264 | if (channels() > 2) { 265 | texel.setZ(image_->value(pixelPosition_.x(), pixelPosition_.y(), 2, l)); 266 | if (channels() > 3) { 267 | texel.setW(image_->value(pixelPosition_.x(), pixelPosition_.y(), 3, l)); 268 | } 269 | } 270 | } 271 | if (image_->layers().size() > l && image_->layers()[l].display == Image::Integer) { 272 | for (int i = 0; i < channels(); ++i) { 273 | uint32_t integer; 274 | std::memcpy(&integer, &texel[i], sizeof(float)); 275 | texel[i] = float(integer); 276 | } 277 | } 278 | return texel; 279 | } 280 | 281 | void ImageDocument::load(QString const& path, QFutureWatcher* watcher) 282 | { 283 | QFuture future = QtConcurrent::run([path]() { 284 | QFileInfo file(path); 285 | std::string path = file.absoluteFilePath().toStdString(); 286 | if (!file.exists()) { 287 | return std::make_shared>("File " + path + " does not exist."); 288 | } 289 | if (file.suffix() == "hdr" || file.suffix() == "pic") { 290 | return std::make_shared>(Image::loadPIC(path)); 291 | } else if (file.suffix() == "pfm" || file.suffix() == "ppm") { 292 | return std::make_shared>(Image::loadPFM(path)); 293 | } else if (file.suffix() == "exr") { 294 | return std::make_shared>(Image::loadEXR(path)); 295 | } else { 296 | return std::make_shared>(Image::loadImage(path)); 297 | } 298 | }); 299 | watcher->setFuture(future); 300 | } 301 | 302 | void ImageDocument::loadFinished(QFutureWatcher* watcher, QUrl const& url, bool comparison) 303 | { 304 | auto result = watcher->result(); 305 | if (check(*result, comparison ? ErrorCategory::Comparison : ErrorCategory::Image, "Failed to load " + url.toLocalFile() + ": ")) { 306 | if (!comparison) { 307 | image_ = std::make_shared(std::move(*result).value()); 308 | } else { 309 | comparison_ = Comparison(std::make_shared(std::move(*result).value())); 310 | emit isComparisonChanged(); 311 | } 312 | setError("", comparison ? ErrorCategory::Comparison : ErrorCategory::Image); 313 | emit errorTextChanged(); 314 | emit fileTypeChanged(); 315 | emit propertyChanged(); 316 | } 317 | } 318 | 319 | } 320 | -------------------------------------------------------------------------------- /viewer/model/ImageDocument.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace hdrv { 17 | 18 | class ImageDocument : public QObject 19 | { 20 | Q_OBJECT 21 | Q_PROPERTY(QString name READ name CONSTANT FINAL) 22 | Q_PROPERTY(QUrl url READ url CONSTANT FINAL) 23 | Q_PROPERTY(bool busy READ busy NOTIFY busyChanged) 24 | Q_PROPERTY(QStringList errorText READ errorText NOTIFY errorTextChanged) 25 | Q_PROPERTY(QUrl directory READ directory CONSTANT FINAL) 26 | Q_PROPERTY(QString fileType READ fileType NOTIFY fileTypeChanged) 27 | Q_PROPERTY(QSize size READ size NOTIFY propertyChanged) 28 | Q_PROPERTY(int channels READ channels NOTIFY propertyChanged) 29 | Q_PROPERTY(QPointF position READ position WRITE setPosition NOTIFY positionChanged) 30 | Q_PROPERTY(float scale READ scale WRITE setScale NOTIFY scaleChanged) 31 | Q_PROPERTY(qreal brightness READ brightness WRITE setBrightness NOTIFY brightnessChanged) 32 | Q_PROPERTY(qreal minBrightness READ minBrightness CONSTANT FINAL) 33 | Q_PROPERTY(qreal maxBrightness READ maxBrightness CONSTANT FINAL) 34 | Q_PROPERTY(qreal gamma READ gamma WRITE setGamma NOTIFY gammaChanged) 35 | Q_PROPERTY(qreal minGamma READ minGamma CONSTANT FINAL) 36 | Q_PROPERTY(qreal maxGamma READ maxGamma CONSTANT FINAL) 37 | Q_PROPERTY(bool isFloat READ isFloat NOTIFY propertyChanged) 38 | Q_PROPERTY(DisplayMode displayMode READ displayMode WRITE setDisplayMode NOTIFY displayModeChanged) 39 | Q_PROPERTY(QPoint pixelPosition READ pixelPosition NOTIFY pixelPositionChanged) 40 | Q_PROPERTY(QVector4D pixelValue READ pixelValue NOTIFY pixelValueChanged) 41 | Q_PROPERTY(bool isComparison READ isComparison NOTIFY isComparisonChanged) 42 | Q_PROPERTY(ComparisonMode comparisonMode READ comparisonMode WRITE setComparisonMode NOTIFY comparisonModeChanged) 43 | Q_PROPERTY(float comparisonSeparator READ comparisonSeparator WRITE setComparisonSeparator NOTIFY comparisonSeparatorChanged) 44 | Q_PROPERTY(bool hasLayers READ hasLayers NOTIFY propertyChanged) 45 | Q_PROPERTY(QList layers READ layers NOTIFY propertyChanged) 46 | Q_PROPERTY(int layer READ layer WRITE setLayer NOTIFY layerChanged) 47 | 48 | public: 49 | enum class ComparisonMode { Difference, SideBySide }; 50 | Q_ENUMS(ComparisonMode) 51 | 52 | enum class DisplayMode { Default, NoAlpha, AlphaOnly }; 53 | Q_ENUMS(DisplayMode) 54 | 55 | struct Comparison 56 | { 57 | std::shared_ptr image; 58 | ComparisonMode mode = ComparisonMode::Difference; 59 | float separator = 0.5f; 60 | 61 | Comparison() = default; 62 | Comparison(std::shared_ptr i) : image(std::move(i)) {} 63 | }; 64 | 65 | ImageDocument(QUrl const& url, QObject * parent = nullptr); 66 | ImageDocument(QUrl const& base, QUrl const& comparison, QObject * parent = nullptr); 67 | ImageDocument(QObject * parent = nullptr); 68 | 69 | void init(); 70 | 71 | QString const& name() const { return name_; } 72 | QUrl const& url() const { return url_; } 73 | bool busy() const { return (watcher_ && watcher_->isRunning()) || (comparisonWatcher_ && comparisonWatcher_->isRunning()); } 74 | QStringList const& errorText() const { return errorText_; } 75 | QUrl directory() const; 76 | QString fileType() const; 77 | QPointF position() const { return position_; } 78 | int width() const { return image_->width(); } 79 | int height() const { return image_->height(); } 80 | QSize size() const { return QSize(image_->width(), image_->height()); } 81 | int channels() const; 82 | float scale() const { return scale_; } 83 | qreal brightness() const { return brightness_; } 84 | qreal minBrightness() const { return -10.0; } 85 | qreal maxBrightness() const { return 10.0; } 86 | qreal gamma() const { return image_->format() == Image::Float ? gamma_ : 2.2; } 87 | qreal minGamma() const { return 1.0; } 88 | qreal maxGamma() const { return 8.0; } 89 | bool isFloat() const { return image_->format() == Image::Float; } 90 | DisplayMode displayMode() const { return displayMode_; } 91 | void const* pixels() const { return image_->data(); } 92 | std::shared_ptr const& image() { return image_; } 93 | QPoint pixelPosition() const { return pixelPosition_; } 94 | QVector4D pixelValue() const; 95 | bool isDefault() const; 96 | bool isComparison() const { return (bool)comparison_; } 97 | std::optional const& comparison() const { return comparison_; } 98 | ComparisonMode comparisonMode() const { return comparison_.value_or(Comparison()).mode; } 99 | float comparisonSeparator() const { return comparison_.value_or(Comparison()).separator; } 100 | bool hasLayers() const { return image_->layers().size() > 1; } 101 | QList layers() const; 102 | int layer() const { return layer_; } 103 | 104 | enum class ErrorCategory { Image, Comparison, Generic }; 105 | void setError(QString const& errorText, ErrorCategory category); 106 | 107 | void setPosition(QPointF pos); 108 | void move(QPointF offset); 109 | void setScale(qreal scale); 110 | void setBrightness(qreal brightness); 111 | void setGamma(qreal gamma); 112 | void setDisplayMode(DisplayMode displayMode); 113 | void setCurrentPixel(QPoint index); 114 | void setComparisonMode(ComparisonMode mode); 115 | void setComparisonSeparator(float value); 116 | void setLayer(int layer); 117 | 118 | Q_INVOKABLE void resetError(); 119 | Q_INVOKABLE void store(QUrl const& url); 120 | 121 | signals: 122 | void busyChanged(); 123 | void errorTextChanged(); 124 | void propertyChanged(); 125 | void positionChanged(); 126 | void scaleChanged(); 127 | void brightnessChanged(); 128 | void gammaChanged(); 129 | void displayModeChanged(); 130 | void pixelPositionChanged(); 131 | void pixelValueChanged(); 132 | void isComparisonChanged(); 133 | void comparisonModeChanged(); 134 | void comparisonSeparatorChanged(); 135 | void fileTypeChanged(); 136 | void layerChanged(); 137 | 138 | private: 139 | typedef std::shared_ptr> LoadResult; 140 | QFutureWatcher* setupWatcher(QUrl const& url, bool comparison); 141 | void load(QString const& path, QFutureWatcher* watcher); 142 | void loadFinished(QFutureWatcher* watcher, QUrl const& url, bool comparison); 143 | 144 | template 145 | bool check(Result const& result, ErrorCategory category, QString const& prefix = "") { 146 | if (!result) { 147 | setError(prefix + QString::fromStdString(result.error()), category); 148 | } 149 | return (bool)result; 150 | } 151 | 152 | QString name_ = "HDRV"; 153 | QUrl url_ ; 154 | QUrl comparisonUrl_; 155 | QStringList errorText_ = { "","","" }; 156 | QPointF position_; 157 | qreal scale_ = 1.0f; 158 | qreal brightness_ = 0.0f; 159 | qreal gamma_ = 2.2f; 160 | DisplayMode displayMode_ = DisplayMode::Default; 161 | QPoint pixelPosition_; 162 | QVector4D pixelValue_; 163 | std::shared_ptr image_; 164 | std::optional comparison_; 165 | int layer_ = 0; 166 | QFutureWatcher* watcher_ = nullptr; 167 | QFutureWatcher* comparisonWatcher_ = nullptr; 168 | }; 169 | 170 | using ImageComparison = ImageDocument::Comparison; 171 | using ComparisonMode = ImageDocument::ComparisonMode; 172 | 173 | } 174 | 175 | Q_DECLARE_METATYPE(hdrv::ImageDocument*); 176 | -------------------------------------------------------------------------------- /viewer/model/Settings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #ifdef WIN32 11 | # include 12 | #endif // WIN32 13 | 14 | namespace hdrv { 15 | 16 | Settings::Settings(QObject * parent) 17 | : QObject(parent) 18 | { 19 | QCoreApplication::setOrganizationName("hdrv"); 20 | QCoreApplication::setApplicationName("hdrv"); 21 | QSettings::setDefaultFormat(QSettings::IniFormat); 22 | 23 | #ifdef WIN32 24 | QFileInfo thumbDll(QDir(QCoreApplication::applicationDirPath()), "thumbnails.dll"); 25 | thumbnailsAvailable_ = thumbDll.exists(); 26 | if (thumbnailsAvailable_) { 27 | thumbnailDllPath_ = thumbDll.absoluteFilePath(); 28 | } 29 | #endif // WIN32 30 | } 31 | 32 | void registerDll(std::string const& dllPath, bool remove = false) 33 | { 34 | #ifdef WIN32 35 | std::ostringstream oss; 36 | oss << "/s"; 37 | if (remove) { 38 | oss << " /u"; 39 | } 40 | oss << " \"" << dllPath << "\""; 41 | ShellExecuteA(0, "runas", "regsvr32.exe", oss.str().c_str(), nullptr, SW_SHOWNORMAL); 42 | #endif // WIN32 43 | } 44 | 45 | void Settings::install() 46 | { 47 | registerDll(thumbnailDllPath_.toStdString()); 48 | } 49 | 50 | void Settings::uninstall() 51 | { 52 | registerDll(thumbnailDllPath_.toStdString(), true); 53 | } 54 | 55 | bool Settings::singleInstance() const 56 | { 57 | QSettings settings; 58 | return settings.value("Startup/SingleInstance").toBool(); 59 | } 60 | 61 | void Settings::setSingleInstance(bool singleInstance) 62 | { 63 | QSettings settings; 64 | settings.setValue("Startup/SingleInstance", QVariant(singleInstance)); 65 | 66 | emit singleInstanceChanged(singleInstance); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /viewer/model/Settings.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace hdrv { 6 | 7 | class Settings : public QObject 8 | { 9 | Q_OBJECT 10 | Q_PROPERTY(bool thumbnailsAvailable READ thumbnailsAvailable CONSTANT FINAL) 11 | Q_PROPERTY(bool singleInstance READ singleInstance WRITE setSingleInstance NOTIFY singleInstanceChanged) 12 | 13 | public: 14 | Settings(QObject * parent = nullptr); 15 | 16 | bool thumbnailsAvailable() const { return thumbnailsAvailable_; } 17 | bool singleInstance() const; 18 | void setSingleInstance(bool singleInstance); 19 | 20 | Q_INVOKABLE void install(); 21 | Q_INVOKABLE void uninstall(); 22 | 23 | signals: 24 | void singleInstanceChanged(bool singleInstance); 25 | 26 | private: 27 | bool thumbnailsAvailable_ = false; 28 | QString thumbnailDllPath_; 29 | }; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /viewer/qtquickcontrols2.conf: -------------------------------------------------------------------------------- 1 | [Controls] 2 | Style=Material 3 | 4 | [Material] 5 | Theme=Light 6 | Variant=Dense 7 | Accent=DeepOrange 8 | -------------------------------------------------------------------------------- /viewer/shader/RenderImage.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | uniform sampler2D tex; 4 | uniform sampler2D comparison; 5 | 6 | uniform vec2 position; 7 | uniform vec2 scale; 8 | uniform vec2 regionSize; 9 | uniform float gamma; 10 | uniform float brightness; 11 | uniform int display; 12 | uniform int mode; 13 | uniform float separator; 14 | 15 | varying highp vec2 coords; 16 | 17 | #define Difference 0 18 | #define SideBySide 1 19 | 20 | void main() 21 | { 22 | vec2 pos = (coords - position) / scale; 23 | if(pos.x >= 0.0 && pos.x <= 1.0 && pos.y >= 0.0 && pos.y <= 1.0) { 24 | vec3 checker = (int(floor(0.1*coords.x*regionSize.x) + floor(0.1*coords.y*regionSize.y)) & 1) > 0 ? vec3(0.4) : vec3(0.6); 25 | vec4 texel = texture2D(tex, pos); 26 | 27 | if (mode == Difference) { 28 | vec4 comp = texture2D(comparison, pos); 29 | texel = vec4(abs(comp - texel).xyz, 1.0); 30 | } else if (mode == SideBySide) { 31 | if (pos.x > separator) { 32 | texel = texture2D(comparison, pos); 33 | } 34 | } 35 | 36 | vec3 color = pow(brightness * texel.xyz, vec3(gamma)); 37 | switch(display) { 38 | case 1: // No Alpha 39 | gl_FragColor = vec4(color.xyz, 1.0); 40 | break; 41 | case 2: // Alpha Only 42 | gl_FragColor = vec4(vec3(texel.w), 1.0); 43 | break; 44 | case 3: // Normal 45 | gl_FragColor = vec4(texel.xyz * 0.5 + 0.5, 1.0); 46 | break; 47 | case 4: // Integer 48 | gl_FragColor = vec4(floatBitsToUint(texel)); 49 | break; 50 | default: // Default 51 | gl_FragColor = vec4(mix(checker, color.xyz, texel.w), 1.0); 52 | break; 53 | } 54 | } else { 55 | gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /viewer/shader/RenderImage.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | attribute highp vec4 vertices; 4 | varying highp vec2 coords; 5 | 6 | void main() 7 | { 8 | gl_Position = vertices; 9 | coords = vertices.xy * 0.5 + 0.5; 10 | } 11 | -------------------------------------------------------------------------------- /viewer/view/AppSettings.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2 | import QtQuick.Controls 3 | import QtQuick.Layouts 4 | import Hdrv 1.0 5 | 6 | Rectangle { 7 | color: '#FAFAFA' 8 | 9 | ColumnLayout { 10 | spacing: 10 11 | anchors.left: parent.left 12 | anchors.right: parent.right 13 | anchors.top: parent.top 14 | anchors.topMargin: 10 15 | anchors.leftMargin: 10 16 | anchors.rightMargin: 10 17 | 18 | Text { text: 'Single Instance' } 19 | 20 | Switch { 21 | id: singleInstanceSwitch 22 | Layout.fillWidth: true 23 | text: singleInstanceSwitch.checked ? 'Enabled' : 'Disabled' 24 | checked: server.running 25 | onClicked: { 26 | if(server.running) { 27 | server.stop(); 28 | } else { 29 | client.remoteStopServer(); 30 | server.start(); 31 | } 32 | } 33 | } 34 | 35 | Text { 36 | Layout.fillWidth: true 37 | text: 'Images are always opened in a new tab if HDRV is already running.' 38 | wrapMode: Text.Wrap 39 | } 40 | 41 | CheckBox { 42 | Layout.fillWidth: true 43 | text: 'Enable on startup' 44 | checked: settings.singleInstance 45 | onClicked: settings.singleInstance = this.checked 46 | } 47 | 48 | Text { 49 | text: 'Thumbnails' 50 | visible: settings.thumbnailsAvailable 51 | } 52 | Text { 53 | Layout.fillWidth: true 54 | text: 'Provides thumbnails for supported HDR formats in Windows Explorer.' 55 | visible: settings.thumbnailsAvailable 56 | wrapMode: Text.Wrap 57 | } 58 | 59 | RowLayout { 60 | Layout.fillWidth: true 61 | spacing: 10 62 | visible: settings.thumbnailsAvailable 63 | 64 | Button { 65 | Layout.fillWidth: true 66 | text: 'Install' 67 | onClicked: settings.install() 68 | } 69 | 70 | Button { 71 | Layout.fillWidth: true 72 | text: 'Uninstall' 73 | onClicked: settings.uninstall() 74 | } 75 | } 76 | 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /viewer/view/ExportButton.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2 | import QtQuick.Controls 3 | import QtQuick.Layouts 4 | import Qt.labs.platform 1.1 5 | 6 | Control { 7 | property bool exportable: images.current.isFloat && !images.current.isComparison 8 | 9 | RowLayout { 10 | anchors.fill: parent 11 | spacing: 0 12 | 13 | ToolButton { 14 | id: exportHDRButton 15 | Layout.fillWidth: true 16 | text: 'HDR' 17 | enabled: exportable 18 | onClicked: { 19 | storeImageDialog.selectedNameFilter.index = 0 20 | storeImageDialog.open() 21 | } 22 | } 23 | 24 | ToolButton { 25 | id: exportPFMButton 26 | Layout.fillWidth: true 27 | text: 'PFM' 28 | enabled: exportable 29 | onClicked: { 30 | storeImageDialog.selectedNameFilter.index = 1 31 | storeImageDialog.open() 32 | } 33 | } 34 | 35 | ToolButton { 36 | id: exportEXRButton 37 | Layout.fillWidth: true 38 | text: 'EXR' 39 | enabled: exportable 40 | onClicked: { 41 | storeImageDialog.selectedNameFilter.index = 2 42 | storeImageDialog.open() 43 | } 44 | } 45 | 46 | ToolButton { 47 | id: exportPNGButton 48 | text: 'PNG' 49 | Layout.fillWidth: true 50 | enabled: exportable 51 | onClicked: { 52 | storeImageDialog.selectedNameFilter.index = 3 53 | storeImageDialog.open() 54 | } 55 | } 56 | 57 | FileDialog { 58 | id: storeImageDialog 59 | title: 'Choose a filename' 60 | folder: images.current.directory 61 | fileMode: FileDialog.SaveFile 62 | nameFilters: [ 'Radiance HDR (*.hdr)', 'PFM image (*.pfm)', 'OpenEXR image (*.exr)', 'PNG image (*.png)' ] 63 | onAccepted: images.current.store(storeImageDialog.file); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /viewer/view/IPCClient.cpp: -------------------------------------------------------------------------------- 1 | #include "IPCClient.hpp" 2 | 3 | #include 4 | #include 5 | 6 | namespace hdrv { 7 | 8 | namespace { 9 | 10 | bool sendCommand(QString const & command) { 11 | QLocalSocket socket; 12 | socket.connectToServer("hdrv"); 13 | if (socket.waitForConnected(50)) { 14 | socket.write(command.toUtf8()); 15 | if (socket.waitForBytesWritten(500)) { 16 | socket.close(); 17 | socket.waitForDisconnected(50); 18 | return true; 19 | } 20 | } 21 | 22 | return false; 23 | } 24 | 25 | } 26 | 27 | bool IPCClient::remoteOpenFile(QUrl const & url) 28 | { 29 | QFileInfo f(url.toLocalFile()); 30 | return sendCommand(QString("open %1").arg(f.absoluteFilePath())); 31 | } 32 | 33 | bool IPCClient::remoteStopServer() 34 | { 35 | return sendCommand("exit"); 36 | } 37 | 38 | bool IPCClient::isServerAvailable() 39 | { 40 | return sendCommand(""); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /viewer/view/IPCClient.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace hdrv { 7 | 8 | class IPCClient : public QObject 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | Q_INVOKABLE bool remoteOpenFile(QUrl const & url); 14 | Q_INVOKABLE bool remoteStopServer(); 15 | Q_INVOKABLE bool isServerAvailable(); 16 | }; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /viewer/view/IPCServer.cpp: -------------------------------------------------------------------------------- 1 | #include "IPCServer.hpp" 2 | 3 | #include 4 | #include 5 | 6 | namespace hdrv { 7 | 8 | IPCServer::IPCServer(QObject * parent) 9 | : QObject(parent) 10 | , localServer_(nullptr) 11 | { 12 | localServer_ = new QLocalServer(this); 13 | 14 | connect(localServer_, SIGNAL(newConnection()), this, SLOT(newConnection())); 15 | } 16 | 17 | void IPCServer::start() 18 | { 19 | if (!localServer_->isListening()) { 20 | localServer_->listen("hdrv"); 21 | emit runningChanged(); 22 | } 23 | } 24 | 25 | void IPCServer::stop() 26 | { 27 | if (localServer_->isListening()) { 28 | localServer_->close(); 29 | emit runningChanged(); 30 | } 31 | } 32 | 33 | bool IPCServer::isRunning() 34 | { 35 | return localServer_->isListening(); 36 | } 37 | 38 | void IPCServer::newConnection() 39 | { 40 | while (localServer_->hasPendingConnections()) { 41 | auto * socket = localServer_->nextPendingConnection(); 42 | 43 | connect(socket, SIGNAL(disconnected()), socket, SLOT(deleteLater())); 44 | connect(socket, &QLocalSocket::readyRead, [&, socket]() { 45 | while (socket->bytesAvailable() > 0) { 46 | QString cmd = socket->readLine(); 47 | if (cmd.startsWith("open")) { 48 | QString filename = cmd.right(cmd.length() - 5); 49 | emit openFile(QUrl::fromLocalFile(filename)); 50 | } else if (cmd.startsWith("exit")) { 51 | socket->disconnectFromServer(); 52 | stop(); 53 | } 54 | } 55 | }); 56 | } 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /viewer/view/IPCServer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace hdrv { 6 | 7 | class IPCServer : public QObject 8 | { 9 | Q_OBJECT 10 | Q_PROPERTY(bool running READ isRunning NOTIFY runningChanged) 11 | 12 | public: 13 | IPCServer(QObject * parent = nullptr); 14 | 15 | Q_INVOKABLE void start(); 16 | Q_INVOKABLE void stop(); 17 | 18 | bool isRunning(); 19 | 20 | signals: 21 | void runningChanged(); 22 | void openFile(QUrl const & url); 23 | 24 | private slots: 25 | void newConnection(); 26 | 27 | private: 28 | QLocalServer* localServer_; 29 | }; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /viewer/view/ImageArea.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace hdrv { 6 | 7 | ImageArea::ImageArea() 8 | : images_(nullptr) 9 | { 10 | connect(this, &QQuickItem::windowChanged, this, &ImageArea::handleWindowChanged); 11 | setAcceptedMouseButtons(Qt::AllButtons); 12 | setAcceptHoverEvents(true); 13 | } 14 | 15 | void ImageArea::setModel(ImageCollection * images) 16 | { 17 | if (images_ != images) { 18 | if (images_) { 19 | disconnect(images_, 0, this, 0); 20 | } 21 | images_ = images; 22 | connect(images_, &ImageCollection::itemsChanged,this, &ImageArea::connectImages); 23 | connect(images_, &ImageCollection::currentChanged, window(), &QQuickWindow::update); 24 | connectImages(); 25 | emit modelChanged(); 26 | } 27 | } 28 | 29 | void ImageArea::setColor(QColor const& color) 30 | { 31 | color_ = color; 32 | emit colorChanged(); 33 | if (window()) { 34 | window()->update(); 35 | } 36 | } 37 | 38 | RenderRegion calculateRenderRegion(QSize windowSize, QPointF position, qreal width, qreal height, qreal ratio) 39 | { 40 | int w = int(ratio * width); 41 | int h = int(ratio * height); 42 | int x = int(ratio * position.x()); 43 | int y = int(ratio * (windowSize.height() - position.y() - height)); 44 | return { QPoint(x, y), QSize(w, h) }; 45 | } 46 | 47 | void ImageArea::sync() 48 | { 49 | if (images_) { 50 | if (!renderer_) { 51 | renderer_ = std::make_unique(); 52 | connect(window(), &QQuickWindow::beforeRendering, renderer_.get(), &ImageRenderer::init, Qt::DirectConnection); 53 | connect(window(), &QQuickWindow::beforeRenderPassRecording, renderer_.get(), &ImageRenderer::paint, Qt::DirectConnection); 54 | } 55 | auto & img = *images_->current(); 56 | auto pos = mapToItem(nullptr, position()); 57 | qreal ratio = window()->devicePixelRatio(); 58 | renderer_->setRenderRegion(calculateRenderRegion(window()->size(), pos, width(), height(), ratio)); 59 | renderer_->setClearColor(color_); 60 | renderer_->updateImages(images_->vector()); 61 | renderer_->setCurrent(img.image(), img.layer()); 62 | renderer_->setSettings({QVector2D(img.position()), img.scale(), (float)img.brightness(), (float)img.gamma(), img.displayMode()}); 63 | renderer_->setComparison(img.comparison()); 64 | renderer_->setWindow(window()); 65 | } 66 | } 67 | 68 | QRectF ImageArea::imageBounds(ImageDocument const & img) const 69 | { 70 | QRectF bounds(QPointF(0, 0), QSizeF(img.width() * img.scale(), img.height() * img.scale())); 71 | bounds.moveTo(0.5 * QPointF(width(), height()) - 0.5 * img.scale() * QPointF(img.width(), img.height())); 72 | bounds.translate(-img.position()); 73 | return bounds; 74 | } 75 | 76 | void ImageArea::reposition(ImageDocument & img) 77 | { 78 | QSizeF wsize = QSizeF(width(), height()); 79 | QRectF bounds = imageBounds(img); 80 | 81 | QPointF newPos = img.position(); 82 | if (bounds.width() <= wsize.width()) { 83 | newPos.setX(0); 84 | } else { 85 | if (bounds.left() > 0) { 86 | newPos.setX(std::floor(wsize.width() / 2 - bounds.width() / 2)); 87 | } else if (bounds.right() < wsize.width()) { 88 | newPos.setX(std::floor(-wsize.width() / 2 + bounds.width() / 2)); 89 | } 90 | } 91 | if (bounds.height() <= height()) { 92 | newPos.setY(0); 93 | } else { 94 | if (bounds.top() > 0) { 95 | newPos.setY(std::floor(wsize.height() / 2 - bounds.height() / 2)); 96 | } else if (bounds.bottom() < wsize.height()) { 97 | newPos.setY(std::floor(-wsize.height() / 2 + bounds.height() / 2)); 98 | } 99 | } 100 | 101 | img.setPosition(newPos); 102 | } 103 | 104 | void ImageArea::updateComparisonSeparator(ImageDocument & img, QPointF pos) 105 | { 106 | if (img.isComparison() && img.comparisonMode() == ComparisonMode::SideBySide) { 107 | auto bounds = imageBounds(img); 108 | float s = (pos.x() - bounds.left()) / bounds.width(); 109 | img.setComparisonSeparator(s); 110 | } 111 | } 112 | 113 | void ImageArea::mousePressEvent(QMouseEvent * event) 114 | { 115 | if (!images_) return; 116 | 117 | if (event->button() == Qt::MouseButton::LeftButton) { 118 | setCursor(Qt::ClosedHandCursor); 119 | mousePosition_ = event->position(); 120 | } else if (event->button() == Qt::MouseButton::RightButton && images_) { 121 | auto & img = *images_->current(); 122 | img.setComparisonMode(ComparisonMode::SideBySide); 123 | setCursor(Qt::SplitHCursor); 124 | updateComparisonSeparator(*images_->current(), event->position()); 125 | } 126 | } 127 | 128 | void ImageArea::mouseReleaseEvent(QMouseEvent *) 129 | { 130 | unsetCursor(); 131 | } 132 | 133 | void ImageArea::mouseMoveEvent(QMouseEvent * event) 134 | { 135 | if (images_) { 136 | auto & img = *images_->current(); 137 | 138 | if (event->buttons() & Qt::MouseButton::LeftButton) { 139 | img.move(mousePosition_ - event->position()); 140 | mousePosition_ = event->position(); 141 | reposition(img); 142 | } 143 | if (event->buttons() & Qt::MouseButton::RightButton) { 144 | updateComparisonSeparator(img, event->position()); 145 | } 146 | } 147 | } 148 | 149 | void ImageArea::wheelEvent(QWheelEvent * event) 150 | { 151 | if (images_) { 152 | float mul = event->angleDelta().y() > 0 ? 2.0 : 0.5; 153 | 154 | auto & img = *images_->current(); 155 | auto bounds = imageBounds(img); 156 | if (bounds.contains(event->position())) { 157 | int cx = bounds.center().x(); 158 | int cy = bounds.center().y(); 159 | QPointF pos = (event->position() - QPointF(cx, cy)); 160 | QPointF newPos = mul * pos; 161 | 162 | img.move(newPos - pos); 163 | } 164 | 165 | float scale = img.scale() * mul; 166 | img.setScale(scale); 167 | 168 | reposition(*images_->current()); 169 | } 170 | } 171 | 172 | void ImageArea::hoverMoveEvent(QHoverEvent * event) 173 | { 174 | if (images_ && images_->current()) { 175 | auto & img = *images_->current(); 176 | const auto & bounds = imageBounds(img); 177 | if (bounds.contains(event->position())) { 178 | QPointF positionOnImage = (event->position() - bounds.topLeft()) / img.scale(); 179 | images_->current()->setCurrentPixel(QPoint(positionOnImage.x(), positionOnImage.y())); 180 | } 181 | } 182 | } 183 | 184 | void ImageArea::geometryChange(const QRectF & newGeometry, const QRectF & oldGeometry) 185 | { 186 | if (images_) { 187 | reposition(*images_->current()); 188 | } 189 | QQuickItem::geometryChange(newGeometry, oldGeometry); 190 | } 191 | 192 | void ImageArea::handleWindowChanged(QQuickWindow * window) 193 | { 194 | if (window) { 195 | connect(window, &QQuickWindow::beforeSynchronizing, this, &ImageArea::sync, Qt::DirectConnection); 196 | connect(window, &QQuickWindow::sceneGraphInvalidated, this, &ImageArea::cleanup, Qt::DirectConnection); 197 | } 198 | } 199 | 200 | void ImageArea::connectImages() 201 | { 202 | for (auto image : images_->vector()) { 203 | connect(image, &ImageDocument::propertyChanged, window(), &QQuickWindow::update, Qt::UniqueConnection); 204 | } 205 | } 206 | 207 | void ImageArea::cleanup() 208 | { 209 | renderer_ = nullptr; 210 | } 211 | 212 | struct CleanupJob : public QRunnable 213 | { 214 | std::unique_ptr renderer; 215 | CleanupJob(std::unique_ptr&& r) : renderer(std::move(r)) {} 216 | void run() override { renderer.reset(); } 217 | }; 218 | 219 | void ImageArea::releaseResources() 220 | { 221 | window()->scheduleRenderJob(new CleanupJob(std::move(renderer_)), QQuickWindow::BeforeSynchronizingStage); 222 | } 223 | 224 | } 225 | -------------------------------------------------------------------------------- /viewer/view/ImageArea.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace hdrv { 13 | 14 | class ImageArea : public QQuickItem 15 | { 16 | Q_OBJECT 17 | Q_PROPERTY(ImageCollection* model READ model WRITE setModel NOTIFY modelChanged) 18 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) 19 | 20 | public: 21 | ImageArea(); 22 | 23 | ImageCollection * model() const { return images_; } 24 | QColor const& color() const { return color_; } 25 | 26 | void setModel(ImageCollection * v); 27 | void setColor(QColor const& color); 28 | 29 | signals: 30 | void modelChanged(); 31 | void colorChanged(); 32 | 33 | public slots: 34 | void sync(); 35 | void cleanup(); 36 | 37 | protected: 38 | void mousePressEvent(QMouseEvent * event) override; 39 | void mouseReleaseEvent(QMouseEvent * event) override; 40 | void mouseMoveEvent(QMouseEvent * event) override; 41 | void wheelEvent(QWheelEvent * event) override; 42 | void hoverMoveEvent(QHoverEvent * event) override; 43 | void geometryChange(const QRectF & newGeometry, const QRectF & oldGeometry) override; 44 | void releaseResources() override; 45 | 46 | private slots: 47 | void handleWindowChanged(QQuickWindow * window); 48 | void connectImages(); 49 | 50 | private: 51 | QRectF imageBounds(ImageDocument const & img) const; 52 | void reposition(ImageDocument & img); 53 | void updateComparisonSeparator(ImageDocument & img, QPointF pos); 54 | 55 | QColor color_; 56 | ImageCollection * images_; 57 | std::unique_ptr renderer_; 58 | QPointF mousePosition_; 59 | }; 60 | 61 | } -------------------------------------------------------------------------------- /viewer/view/ImageProperties.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2 | import QtQuick.Controls 3 | import QtQuick.Layouts 4 | import Hdrv 1.0 5 | 6 | Rectangle { 7 | color: '#FAFAFA' 8 | 9 | function presentFloat(num, maxDecimals) { 10 | var str = num.toString(); 11 | var i = str.indexOf('.'); 12 | if (i != -1) { 13 | str = str.substr(0, Math.min(str.length, i + maxDecimals + 1)); 14 | } 15 | return str; 16 | } 17 | 18 | ColumnLayout { 19 | anchors.left: parent.left 20 | anchors.right: parent.right 21 | anchors.top: parent.top 22 | anchors.leftMargin: 10 23 | anchors.rightMargin: 10 24 | anchors.topMargin: 10 25 | 26 | spacing: 10 27 | 28 | ColumnLayout { 29 | visible: images.current.hasLayers 30 | Layout.fillWidth: true 31 | Text { text: 'Image' } 32 | ComboBox { 33 | Layout.fillWidth: true 34 | model: images.current.layers 35 | onCurrentIndexChanged: images.current.layer = currentIndex 36 | currentIndex: images.current.layer 37 | } 38 | } 39 | 40 | ColumnLayout { 41 | Layout.fillWidth: true 42 | Text { 43 | id: renderingHeader 44 | text: 'Rendering' 45 | } 46 | 47 | Text { 48 | text: 'Zoom: ' + images.current.scale + 'x' 49 | MouseArea { 50 | anchors.fill: parent 51 | onDoubleClicked: images.current.scale = 1.0 52 | } 53 | } 54 | Slider { 55 | id: scaleSlider 56 | Layout.fillWidth: true 57 | from: -4 58 | to: 4 59 | stepSize: 1.0 60 | value: Math.log2(images.current.scale) 61 | onValueChanged: images.current.scale = Math.pow(2, scaleSlider.value) 62 | } 63 | 64 | Text { 65 | text: 'Brightness: ' + (brightnessSlider.value >= 0 ? '+' : '') + brightnessSlider.value.toFixed(1) 66 | MouseArea { 67 | anchors.fill: parent 68 | onDoubleClicked: images.current.brightness = 0.0 69 | } 70 | } 71 | Slider { 72 | id: brightnessSlider 73 | Layout.fillWidth: true 74 | from: images.current.minBrightness 75 | to: images.current.maxBrightness 76 | stepSize: 0.1 77 | value: images.current.brightness 78 | onValueChanged: images.current.brightness = brightnessSlider.value; 79 | } 80 | 81 | Text { 82 | text: 'Gamma: ' + gammaSlider.value.toFixed(1) 83 | visible: images.current.isFloat 84 | MouseArea { 85 | anchors.fill: parent 86 | onDoubleClicked: images.current.gamma = 2.2 87 | } 88 | } 89 | Slider { 90 | id: gammaSlider 91 | Layout.fillWidth: true 92 | from: images.current.minGamma 93 | to: images.current.maxGamma 94 | stepSize: 0.1 95 | value: images.current.gamma 96 | onValueChanged: images.current.gamma = gammaSlider.value; 97 | visible: images.current.isFloat 98 | } 99 | 100 | Text { text: 'Display Mode' } 101 | ComboBox { 102 | id: 'displayModeSelection' 103 | Layout.fillWidth: true 104 | model: [ "Default", "No Alpha", "Alpha Only" ] 105 | onCurrentIndexChanged: images.current.displayMode = currentIndex; 106 | currentIndex: images.current.displayMode 107 | } 108 | } 109 | 110 | ColumnLayout { 111 | Text { 112 | text: 'Comparison' 113 | visible: images.current.isComparison 114 | } 115 | Row { 116 | RadioButton { 117 | id: differenceButton 118 | text: 'Difference' 119 | visible: images.current.isComparison 120 | ButtonGroup.group: comparisonModeGroup 121 | } 122 | RadioButton { 123 | id: sideBySideButton 124 | text: 'Side by side' 125 | visible: images.current.isComparison 126 | ButtonGroup.group: comparisonModeGroup 127 | } 128 | } 129 | ButtonGroup { 130 | id: comparisonModeGroup 131 | checkedButton: images.current.comparisonMode == ImageDocument.Difference ? differenceButton : sideBySideButton 132 | onClicked: { 133 | if (differenceButton.checked) images.current.comparisonMode = ImageDocument.Difference; 134 | else images.current.comparisonMode = ImageDocument.SideBySide; 135 | } 136 | } 137 | } 138 | 139 | ColumnLayout { 140 | Layout.fillWidth: true 141 | Text { text: 'Export' } 142 | ExportButton { 143 | Layout.fillWidth: true 144 | } 145 | } 146 | } 147 | 148 | function channelName(i, numChannels, displayFormat) { 149 | if(numChannels < 3) { 150 | return ['L','A'][i]; 151 | } else { 152 | if(displayFormat == 'normal') { 153 | return ['X','Y','Z','A'][i]; 154 | } else { 155 | return ['R','G','B','A'][i]; 156 | } 157 | } 158 | } 159 | 160 | function format(vec, i, numChannels, imageIsFloat, displayFormat) { 161 | var vec = [vec.x, vec.y, vec.z, vec.w]; 162 | var round = function(x) { return Math.floor(x * 1000.0) / 1000.0; }; 163 | 164 | if(displayFormat == 'float') { 165 | if(imageIsFloat) { 166 | return round(vec[i]); 167 | } else { 168 | return round(vec[i] / 255.0); 169 | } 170 | } else if(displayFormat == 'byte') { 171 | if(imageIsFloat) { 172 | var v = Math.floor(vec[i] * 255.0); 173 | return (v > 255) ? ('' + v + '') : v; 174 | } else { 175 | return vec[i]; 176 | } 177 | } else if(displayFormat == 'normal') { 178 | if(imageIsFloat) { 179 | if(i < 3) { 180 | var v = round(2.0 * vec[i] - 1.0); 181 | return (v < -1.0 || v > 1.0) ? ('' + v + '') : v; 182 | } else { 183 | return round(vec[i]); 184 | } 185 | } else { 186 | if(i < 3) { 187 | if(vec[i] == 0) { 188 | return '---'; 189 | } else { 190 | return round((vec[i] - 128.0)/127.0); 191 | } 192 | } else { 193 | return round(Math.floor(vec[i] / 255.0)); 194 | } 195 | } 196 | } else { 197 | return round(vec[i]); 198 | } 199 | } 200 | 201 | GridLayout { 202 | columns: 2 203 | columnSpacing: 5 204 | rowSpacing: 5 205 | anchors.left: parent.left 206 | anchors.right: parent.right 207 | anchors.bottom: parent.bottom 208 | anchors.leftMargin: 10 209 | anchors.rightMargin: 10 210 | anchors.bottomMargin: 10 211 | 212 | Text { text: 'Resolution:' } 213 | Text { text: images.current.size.width + ' x ' + images.current.size.height } 214 | Text { text: 'Cursor position:' } 215 | Text { text: images.current.pixelPosition.x + ', ' + images.current.pixelPosition.y } 216 | Text { text: 'Cursor texel value'; Layout.columnSpan: 2 } 217 | Repeater { 218 | model: images.current.channels 219 | Text { 220 | text: channelName(index, images.current.channels, channelFormat.checkedButton.formatType) + ': ' 221 | + format(images.current.pixelValue, index, images.current.channels, images.current.isFloat, channelFormat.checkedButton.formatType); 222 | Layout.columnSpan: 2 223 | Layout.leftMargin: 10 224 | } 225 | } 226 | ButtonGroup { 227 | id: channelFormat 228 | buttons: formatButtons.children 229 | } 230 | RowLayout { 231 | id: formatButtons 232 | Layout.columnSpan: 2 233 | Layout.leftMargin: 10 234 | 235 | ToolButton { 236 | property string formatType: 'auto' 237 | text: 'Auto' 238 | checkable: true 239 | checked: true 240 | } 241 | ToolButton { 242 | property string formatType: 'float' 243 | text: 'Float' 244 | checkable: true 245 | } 246 | ToolButton { 247 | property string formatType: 'byte' 248 | text: 'Byte' 249 | checkable: true 250 | } 251 | ToolButton { 252 | property string formatType: 'normal' 253 | text: 'Normal' 254 | visible: images.current.channels >= 3 255 | checkable: true 256 | } 257 | } 258 | } 259 | } 260 | -------------------------------------------------------------------------------- /viewer/view/ImageRenderer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | float const vertexData[] = {-1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f}; 13 | 14 | QString readFile(QString const& name) 15 | { 16 | QFile file(name); 17 | if (!file.open(QFile::ReadOnly | QFile::Text)) { 18 | qCritical() << "Cannot read shader source: " << name; 19 | return ""; 20 | } 21 | QTextStream stream(&file); 22 | return stream.readAll(); 23 | } 24 | 25 | std::unique_ptr createProgram() 26 | { 27 | auto program = std::make_unique(); 28 | program->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, readFile(":/hdrv/shader/RenderImage.vert")); 29 | program->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, readFile(":/hdrv/shader/RenderImage.frag")); 30 | program->bindAttributeLocation("vertices", 0); 31 | program->link(); 32 | return program; 33 | } 34 | 35 | namespace hdrv { 36 | 37 | QOpenGLTexture::TextureFormat format(Image const& image) 38 | { 39 | switch (image.format()) { 40 | case Image::Float: { 41 | switch (image.channels()) { 42 | case 1: return QOpenGLTexture::R32F; 43 | case 3: return QOpenGLTexture::RGB32F; 44 | case 4: return QOpenGLTexture::RGBA32F; 45 | default: return QOpenGLTexture::RGBA32F; 46 | } 47 | } 48 | case Image::Byte: { 49 | switch (image.channels()) { 50 | case 1: return QOpenGLTexture::R8_UNorm; 51 | case 3: return QOpenGLTexture::RGBFormat; 52 | case 4: return QOpenGLTexture::RGBAFormat; 53 | default: return QOpenGLTexture::RGBAFormat; 54 | } 55 | } 56 | default: return QOpenGLTexture::RGBA32F; 57 | } 58 | } 59 | 60 | QOpenGLTexture::PixelFormat pixelFormat(int channelCount) 61 | { 62 | switch (channelCount) { 63 | case 1: return QOpenGLTexture::Luminance; 64 | case 2: return QOpenGLTexture::RG; 65 | case 3: return QOpenGLTexture::RGB; 66 | case 4: return QOpenGLTexture::RGBA; 67 | default: 68 | qWarning() << "Cannot render image with " << channelCount << " channels."; 69 | return QOpenGLTexture::Luminance; 70 | } 71 | } 72 | 73 | QOpenGLTexture::PixelType pixelType(Image const& image) 74 | { 75 | return image.format() == Image::Float ? QOpenGLTexture::PixelType::Float32 : QOpenGLTexture::PixelType::UInt8; 76 | } 77 | 78 | std::unique_ptr createTexture(Image const& image, Image::Layer const& layer) 79 | { 80 | QOpenGLPixelTransferOptions options; 81 | if (image.format() == Image::Byte) { 82 | options.setAlignment(1); // GL_UNPACK_ALIGNMENT 83 | } 84 | auto texture = std::make_unique(QOpenGLTexture::Target2D); 85 | texture->setSize(image.width(), image.height()); 86 | texture->setFormat(format(image)); 87 | texture->allocateStorage(pixelFormat(layer.channels), pixelType(image)); 88 | texture->setData(pixelFormat(layer.channels), pixelType(image), image.data() + layer.offset, &options); 89 | texture->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear); 90 | texture->setMagnificationFilter(QOpenGLTexture::Nearest); 91 | texture->setWrapMode(QOpenGLTexture::ClampToBorder); 92 | texture->generateMipMaps(); 93 | if (layer.display == Image::Luminance || layer.display == Image::Depth) { 94 | texture->setSwizzleMask(QOpenGLTexture::RedValue, QOpenGLTexture::RedValue, 95 | QOpenGLTexture::RedValue, QOpenGLTexture::OneValue); 96 | } 97 | return texture; 98 | } 99 | 100 | std::vector> createTextures(Image const& image) 101 | { 102 | std::vector> result; 103 | if (image.layers().empty()) { 104 | auto display = image.channels() == 1 ? Image::Luminance : Image::Color; 105 | result.push_back(createTexture(image, Image::Layer{"", image.channels(), display, 0})); 106 | } else { 107 | for (auto& layer : image.layers()) { 108 | result.push_back(createTexture(image, layer)); 109 | } 110 | } 111 | return result; 112 | } 113 | 114 | QVector2D texturePosition(QVector2D regionSize, QVector2D imageSize, QVector2D imagePosition) 115 | { 116 | auto offset = (regionSize - imageSize) / 2.0f; 117 | auto roffset = QVector2D(std::floor(offset.x()), std::floor(offset.y())); 118 | return (roffset + QVector2D(-imagePosition.x(), imagePosition.y())) / regionSize; 119 | } 120 | 121 | QVector2D textureScale(QVector2D regionSize, QVector2D imageSize) 122 | { 123 | return imageSize / regionSize; 124 | } 125 | 126 | void ImageRenderer::updateImages(std::vector const& images) 127 | { 128 | // Erase textures for images that no longer exist 129 | for (auto iter = textures_.begin(); iter != textures_.end(); ) { 130 | auto matchImage = [iter](ImageDocument * doc) { 131 | return doc->image() == iter->first 132 | || (doc->comparison() && doc->comparison()->image == iter->first); 133 | }; 134 | if (std::find_if(images.begin(), images.end(), matchImage) == images.end()) { 135 | textures_.erase(iter++); 136 | } else { 137 | ++iter; 138 | } 139 | } 140 | // Create textures for new images 141 | auto createTextureFor = [this](std::shared_ptr const& image) { 142 | auto & tex = textures_[image]; 143 | if (tex.empty()) { 144 | tex = createTextures(*image); 145 | } 146 | }; 147 | for (auto doc : images) { 148 | createTextureFor(doc->image()); 149 | if (auto const& c = doc->comparison()) { 150 | createTextureFor(c->image); 151 | } 152 | } 153 | } 154 | 155 | void ImageRenderer::init() 156 | { 157 | if (!program_) { 158 | QSGRendererInterface* rif = window_->rendererInterface(); 159 | Q_ASSERT(rif->graphicsApi() == QSGRendererInterface::OpenGL || rif->graphicsApi() == QSGRendererInterface::OpenGLRhi); 160 | 161 | initializeOpenGLFunctions(); 162 | program_ = createProgram(); 163 | } 164 | } 165 | 166 | QOpenGLTexture& ImageRenderer::findTexture(std::shared_ptr const& image, int layer) 167 | { 168 | auto i = textures_.find(image); 169 | Q_ASSERT(i != textures_.end()); 170 | if (i->second.size() == 1) { 171 | return *i->second[0]; 172 | } 173 | Q_ASSERT(layer < i->second.size()); 174 | return *i->second[layer]; 175 | } 176 | 177 | void ImageRenderer::paint() 178 | { 179 | window_->beginExternalCommands(); 180 | 181 | program_->bind(); 182 | program_->enableAttributeArray(0); 183 | 184 | glBindBuffer(GL_ARRAY_BUFFER, 0); 185 | program_->setAttributeArray(0, GL_FLOAT, vertexData, 2); 186 | 187 | auto const& region = renderRegion_; 188 | auto const& image = *current_; 189 | auto& texture = findTexture(current_, layer_); 190 | QVector2D regionSize(float(region.size.width()), float(region.size.height())); 191 | QVector2D imageSize(float(image.width()) * settings_.scale, float(image.height()) * settings_.scale); 192 | 193 | texture.setBorderColor(clearColor_); 194 | texture.bind(0); 195 | program_->setUniformValue("tex", 0); 196 | program_->setUniformValue("position", texturePosition(regionSize, imageSize, settings_.position)); 197 | program_->setUniformValue("scale", textureScale(regionSize, imageSize)); 198 | program_->setUniformValue("regionSize", regionSize); 199 | program_->setUniformValue("brightness", std::pow(2.0f, settings_.brightness)); 200 | program_->setUniformValue("gamma", current_->format() == Image::Float ? 1.0f / settings_.gamma : 1.0f); 201 | program_->setUniformValue("display", (int)settings_.displayMode); 202 | if (comparison_) { 203 | findTexture(comparison_->image, 0).bind(1); 204 | program_->setUniformValue("comparison", 1); 205 | program_->setUniformValue("mode", (int)comparison_->mode); 206 | program_->setUniformValue("separator", comparison_->separator); 207 | } else { 208 | program_->setUniformValue("mode", -1); 209 | } 210 | 211 | glViewport(region.offset.x(), region.offset.y(), region.size.width(), region.size.height()); 212 | 213 | glDisable(GL_DEPTH_TEST); 214 | glClearColor(clearColor_.redF(), clearColor_.greenF(), clearColor_.blueF(), 1.0f); 215 | glClear(GL_COLOR_BUFFER_BIT); 216 | glEnable(GL_BLEND); 217 | glBlendFunc(GL_SRC_ALPHA, GL_ONE); 218 | 219 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 220 | 221 | texture.release(0); 222 | program_->disableAttributeArray(0); 223 | program_->release(); 224 | 225 | window_->endExternalCommands(); 226 | } 227 | 228 | } 229 | -------------------------------------------------------------------------------- /viewer/view/ImageRenderer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | class QQuickWindow; 15 | 16 | namespace hdrv { 17 | 18 | struct RenderRegion 19 | { 20 | QPoint offset; 21 | QSize size; 22 | }; 23 | 24 | struct ImageSettings 25 | { 26 | QVector2D position; 27 | float scale; 28 | float brightness; 29 | float gamma; 30 | ImageDocument::DisplayMode displayMode; 31 | }; 32 | 33 | class ImageRenderer : public QObject, protected QOpenGLFunctions 34 | { 35 | Q_OBJECT 36 | 37 | public: 38 | using ImageTextures = std::map, std::vector>>; 39 | 40 | void setRenderRegion(RenderRegion region) { renderRegion_ = region; } 41 | void setClearColor(QColor color) { clearColor_ = color; } 42 | void setSettings(ImageSettings settings) { settings_ = settings; } 43 | void setCurrent(std::shared_ptr const& image, int layer) { current_ = image; layer_ = layer; } 44 | void setComparison(std::optional const& c) { comparison_ = c; } 45 | void setWindow(QQuickWindow* window) { window_ = window; } 46 | void updateImages(std::vector const& images); 47 | 48 | public slots: 49 | void init(); 50 | void paint(); 51 | 52 | private: 53 | QOpenGLTexture& findTexture(std::shared_ptr const& image, int layer); 54 | 55 | RenderRegion renderRegion_; 56 | QColor clearColor_; 57 | ImageSettings settings_; 58 | ImageTextures textures_; 59 | int layer_ = 0; 60 | std::shared_ptr current_; 61 | std::optional comparison_; 62 | std::unique_ptr program_; 63 | QQuickWindow* window_; 64 | }; 65 | 66 | } -------------------------------------------------------------------------------- /viewer/view/Main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2 | import QtQuick.Layouts 3 | import QtQuick.Controls.Material 4 | import Hdrv 1.0 5 | 6 | 7 | ApplicationWindow { 8 | width: 1200 9 | height: 800 10 | visible: true 11 | color: 'black' 12 | title: images.current.name + ' - hdrv' 13 | 14 | function loadNextFile(prev) { 15 | var url = images.nextFile(prev); 16 | if (url != "") { 17 | images.replace(images.currentIndex, url); 18 | } 19 | } 20 | 21 | ColumnLayout { 22 | anchors.fill: parent 23 | spacing: 0 24 | 25 | Rectangle { 26 | color: '#404040' 27 | Layout.preferredHeight: 28 28 | Layout.fillWidth: true 29 | 30 | RowLayout { 31 | anchors.fill: parent 32 | 33 | TabNav { 34 | Layout.fillWidth: true 35 | Layout.fillHeight: true 36 | } 37 | 38 | ToolButton { 39 | id: imagePropertiesButton 40 | Layout.alignment: Qt.AlignBottom 41 | Layout.preferredHeight: parent.height - 4 42 | Layout.preferredWidth: settingsButton.height 43 | checkable: true 44 | contentItem: Image { 45 | source: 'qrc:/hdrv/media/Properties.png' 46 | } 47 | background: Rectangle { 48 | color: parent.hovered || parent.checked ? '#FAFAFA' : '#C0C0C0' 49 | } 50 | onClicked: if (imagePropertiesButton.checked) settingsButton.checked = false; 51 | } 52 | 53 | ToolButton { 54 | id: settingsButton 55 | Layout.alignment: Qt.AlignBottom 56 | Layout.preferredHeight: parent.height - 4 57 | Layout.preferredWidth: settingsButton.height 58 | Layout.rightMargin: 4 59 | checkable: true 60 | contentItem: Image { 61 | source: 'qrc:/hdrv/media/Settings.png' 62 | } 63 | background: Rectangle { 64 | color: parent.hovered || parent.checked ? '#FAFAFA' : '#C0C0C0' 65 | } 66 | onClicked: if (settingsButton.checked) imagePropertiesButton.checked = false; 67 | } 68 | } 69 | } 70 | 71 | Rectangle { 72 | Layout.preferredHeight: 4 73 | Layout.fillWidth: true 74 | color: '#FAFAFA' 75 | } 76 | 77 | RowLayout { 78 | Layout.fillWidth: true 79 | Layout.fillHeight: true 80 | spacing: 0 81 | 82 | ImageArea { 83 | color: 'black' 84 | model: images 85 | Layout.fillHeight: true 86 | Layout.fillWidth: true 87 | 88 | DropArea { 89 | id: dropArea; 90 | anchors.fill: parent; 91 | onEntered: drag.accept(Qt.CopyAction); 92 | onDropped: { 93 | for (var i = 0; i < drop.urls.length; ++i) { 94 | images.load(drop.urls[i]); 95 | } 96 | } 97 | } 98 | 99 | Rectangle { 100 | id: errorBox 101 | anchors.left: parent.left 102 | anchors.right: parent.right 103 | anchors.top: parent.top 104 | anchors.margins: 10 105 | height: Math.max(errorTextLabel.contentHeight, errorCloseButton.height) + 20 106 | color: '#C0C0C0' 107 | radius: 10 108 | visible: images.current.errorText.join('').length > 0 109 | 110 | Text { 111 | id: errorTextLabel 112 | anchors.left: parent.left 113 | anchors.right: errorCloseButton.left 114 | anchors.top: parent.top 115 | height: parent.height 116 | horizontalAlignment: Text.AlignHCenter 117 | verticalAlignment: Text.AlignVCenter 118 | text: images.current.errorText.join('').replace(/^\n+|\n+$/g, '') 119 | color: '#000000' 120 | styleColor: '#CCCCCC' 121 | } 122 | 123 | Button { 124 | id: errorCloseButton 125 | anchors.right: parent.right 126 | anchors.top: parent.top 127 | anchors.topMargin: 10 128 | anchors.rightMargin: 10 129 | text: "Close" 130 | onClicked: images.current.resetError() 131 | } 132 | } 133 | } 134 | 135 | Rectangle { 136 | Layout.fillHeight: true 137 | Layout.preferredWidth: 1 138 | color: 'darkgrey' 139 | } 140 | 141 | ImageProperties { 142 | id: imageProperties 143 | visible: imagePropertiesButton.checked 144 | enabled: imagePropertiesButton.checked 145 | focus: imagePropertiesButton.checked 146 | Layout.fillHeight: true 147 | Layout.minimumWidth: 280 148 | } 149 | 150 | AppSettings { 151 | id: settingsPane 152 | visible: settingsButton.checked 153 | Layout.fillHeight: true 154 | Layout.minimumWidth: 280 155 | } 156 | } 157 | 158 | Shortcut { 159 | sequence: '+' 160 | context: Qt.ApplicationShortcut 161 | onActivated: images.current.brightness = Math.round(images.current.brightness + 1.0) 162 | } 163 | 164 | Shortcut { 165 | sequence: '-' 166 | context: Qt.ApplicationShortcut 167 | onActivated: images.current.brightness = Math.round(images.current.brightness - 1.0) 168 | } 169 | 170 | Shortcut { 171 | sequence: 'R' 172 | context: Qt.ApplicationShortcut 173 | onActivated: { 174 | images.current.position = Qt.point(0, 0) 175 | images.current.scale = 1.0 176 | } 177 | } 178 | 179 | Shortcut { 180 | sequence: StandardKey.Close 181 | context: Qt.ApplicationShortcut 182 | onActivated: { 183 | if (images.items.length > 1) images.remove(images.currentIndex); 184 | else Qt.quit(); 185 | } 186 | } 187 | 188 | Shortcut { 189 | sequence: StandardKey.MoveToPreviousChar 190 | context: Qt.ApplicationShortcut 191 | onActivated: loadNextFile(true) 192 | } 193 | 194 | Shortcut { 195 | sequence: StandardKey.MoveToNextChar 196 | context: Qt.ApplicationShortcut 197 | onActivated: loadNextFile(false) 198 | } 199 | 200 | Shortcut { 201 | sequence: 'C' 202 | context: Qt.ApplicationShortcut 203 | onActivated: { 204 | if(images.current.isComparison) { 205 | images.current.comparisonMode = ImageDocument.Difference; 206 | } else { 207 | if(images.recentItems.length > 1) { 208 | var i = images.recentItems[images.recentItems.length-2]; 209 | if(!images.items[i].isComparison) { 210 | images.compare(i); 211 | } 212 | } 213 | } 214 | } 215 | } 216 | 217 | Shortcut { 218 | sequence: 'S' 219 | context: Qt.ApplicationShortcut 220 | onActivated: { 221 | if(images.recentItems.length > 1) { 222 | var i = images.recentItems[images.recentItems.length-2]; 223 | images.currentIndex = i; 224 | } 225 | } 226 | } 227 | } 228 | } 229 | -------------------------------------------------------------------------------- /viewer/view/TabNav.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2 | import QtQuick.Controls 3 | import Qt.labs.folderlistmodel 4 | import Qt.labs.platform 1.1 5 | import Qt.labs.settings 6 | import QtQuick.Layouts 7 | import Hdrv 1.0 8 | 9 | ListView { 10 | property color activeColor: '#FAFAFA' 11 | property color inactiveColor: '#C0C0C0' 12 | 13 | id: imageTabList 14 | orientation: Qt.Horizontal 15 | spacing: 2 16 | focus: false 17 | model: images.items 18 | delegate: imageTabDelegate 19 | currentIndex: images.currentIndex 20 | 21 | Component { 22 | id: imageTabDelegate 23 | Item { 24 | id: imageTabItem 25 | height: 28 26 | width: imageTabText.width + 85 27 | 28 | function closeTab(index) { 29 | if (images.items.length > 1) images.remove(index); 30 | else Qt.quit(); 31 | } 32 | 33 | Rectangle { 34 | anchors.left: parent.left 35 | anchors.right: parent.right 36 | anchors.top: parent.top 37 | anchors.leftMargin: 4 38 | anchors.topMargin: 4 39 | color: imageTabItem.ListView.isCurrentItem ? activeColor : inactiveColor 40 | height: parent.height - 4 41 | 42 | BusyIndicator { 43 | id: busyIndicator 44 | anchors.left: parent.left 45 | anchors.top: parent.top 46 | anchors.bottom: parent.bottom 47 | running: busy 48 | } 49 | 50 | Image { 51 | id: imageTabIcon 52 | anchors.left: parent.left 53 | anchors.top: parent.top 54 | anchors.leftMargin: 3 55 | anchors.topMargin: 4 56 | source: 'qrc:/hdrv/media/' + fileType + '.png' 57 | visible: !busy 58 | } 59 | 60 | Text { 61 | id: imageTabText 62 | anchors.left: imageTabIcon.right 63 | anchors.top: parent.top 64 | anchors.leftMargin: 4 65 | anchors.topMargin: 5 66 | text: name; 67 | } 68 | 69 | RowLayout { 70 | id: buttonArea 71 | anchors.top: parent.top 72 | anchors.topMargin: 2 73 | anchors.right: parent.right 74 | anchors.rightMargin: 3 75 | spacing: 0 76 | 77 | ToolButton { 78 | id: compareImageButton 79 | Layout.alignment: Qt.AlignVCenter 80 | visible: !isComparison && !images.current.isComparison && images.current.url != url 81 | icon.source: 'qrc:/hdrv/media/Compare.png' 82 | icon.color: compareImageButton.hovered ? 'black' : '#505050' 83 | background: null 84 | onClicked: images.compare(index) 85 | ToolTip.visible: hovered 86 | ToolTip.delay: 500 87 | ToolTip.text: 'Compare current image to this image.' 88 | } 89 | 90 | ToolButton { 91 | id: closeImageButton 92 | Layout.alignment: Qt.AlignVCenter 93 | icon.source: 'qrc:/hdrv/media/Close.png' 94 | icon.color: closeImageButton.hovered ? 'black' : '#505050' 95 | background: null 96 | onClicked: closeTab(index) 97 | } 98 | 99 | } 100 | 101 | Shortcut { 102 | sequence: (index + 1).toString() 103 | enabled: (index + 1) <= 9 104 | context: Qt.ApplicationShortcut 105 | onActivated: images.currentIndex = index 106 | } 107 | 108 | MouseArea { 109 | anchors.left: parent.left 110 | anchors.right: buttonArea.left 111 | anchors.top: parent.top 112 | anchors.bottom: parent.bottom 113 | acceptedButtons: Qt.LeftButton | Qt.MiddleButton 114 | onClicked: { 115 | if(mouse.button == Qt.MiddleButton) closeTab(index) 116 | else images.currentIndex = index 117 | } 118 | } 119 | } 120 | } 121 | } 122 | 123 | footer: Item { 124 | ToolButton { 125 | anchors.left: parent.left 126 | anchors.top: parent.top 127 | anchors.leftMargin: 5 128 | anchors.topMargin: 4 129 | height: 28 130 | icon.source: 'qrc:/hdrv/media/Open.png' 131 | background: Rectangle { 132 | color: parent.hovered ? '#F0C020' : inactiveColor 133 | } 134 | onClicked: loadImageDialog.open() 135 | } 136 | 137 | FileDialog { 138 | id: loadImageDialog 139 | title: 'Choose an image file' 140 | folder: StandardPaths.writableLocation(StandardPaths.PicturesLocation) 141 | fileMode: FileDialog.OpenFiles 142 | nameFilters: [ 'Supported image files (' + images.supportedFormats().join(' ') + ')', 143 | 'Image files (*.png *.jpg *.bmp *.gif)', 144 | 'HDR image files (*.hdr *.pic *.pfm *.ppm *.exr)', 145 | 'All files (*)' ] 146 | onAccepted: { 147 | for (var i = 0; i < loadImageDialog.files.length; ++i) { 148 | images.load(loadImageDialog.files[i]); 149 | } 150 | } 151 | } 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /viewer/viewer.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | qtquickcontrols2.conf 4 | 5 | 6 | view/ExportButton.qml 7 | view/Main.qml 8 | view/TabNav.qml 9 | view/ImageProperties.qml 10 | view/AppSettings.qml 11 | shader/RenderImage.vert 12 | shader/RenderImage.frag 13 | ../media/Open.png 14 | ../media/Save.png 15 | ../media/Properties.png 16 | ../media/Close.png 17 | ../media/Compare.png 18 | ../media/FormatHDR.png 19 | ../media/FormatPFM.png 20 | ../media/FormatEXR.png 21 | ../media/FormatByte.png 22 | ../media/Comparison.png 23 | ../media/Default.png 24 | ../media/Settings.png 25 | 26 | --------------------------------------------------------------------------------