├── CMakeLists.txt ├── LICENSE.txt ├── README.md ├── debian ├── changelog ├── compat ├── control ├── copyright ├── rules └── source │ └── format ├── images ├── gimp-2.8.x.png └── gimp-2.9.x.jpg └── src ├── CMakeLists.txt ├── config.h.in ├── webp-dialog.c ├── webp-dialog.h ├── webp-load.c ├── webp-load.h ├── webp-save.c ├── webp-save.h ├── webp.c └── webp.h /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # gimp-webp - WebP Plugin for the GIMP 2 | # Copyright (C) 2016 Nathan Osman & Ben Touchette 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | cmake_minimum_required(VERSION 2.8.12) 18 | project(gimp-webp C) 19 | 20 | # Set project version 21 | set(PROJECT_VERSION_MAJOR 0) 22 | set(PROJECT_VERSION_MINOR 4) 23 | set(PROJECT_VERSION_PATCH 0) 24 | 25 | find_package(PkgConfig REQUIRED) 26 | 27 | # Because Gimp 2.8.x and 2.9.x are so vastly different, they must be handled 28 | # differently - check the version of Gimp installed on the system. 29 | 30 | pkg_check_modules(GIMP REQUIRED 31 | gimp-2.0>=2.8 32 | gimpui-2.0>=2.8 33 | ) 34 | 35 | message(STATUS "Gimp ${GIMP_gimp-2.0_VERSION} found") 36 | 37 | include_directories(${GIMP_INCLUDE_DIRS}) 38 | link_directories(${GIMP_LIBRARY_DIRS}) 39 | 40 | if("${GIMP_gimp-2.0_VERSION}" VERSION_LESS "2.9") 41 | set(GIMP_2_9 0) 42 | else() 43 | set(GIMP_2_9 1) 44 | 45 | # GEGL is required 46 | pkg_check_modules(GEGL REQUIRED 47 | gegl-0.3>=0.3.8 48 | ) 49 | 50 | message(STATUS "GEGL ${GEGL_gegl-0.3_VERSION} found") 51 | 52 | include_directories(${GEGL_INCLUDE_DIRS}) 53 | link_directories(${GEGL_LIBRARY_DIRS}) 54 | endif() 55 | 56 | # Do the same for libwebp - 0.5 is required for animation support. (TODO: 57 | # verify if this is indeed the case.) 58 | 59 | pkg_check_modules(WEBP REQUIRED 60 | libwebp>=0.4 61 | libwebpmux>=0.4 62 | ) 63 | 64 | message(STATUS "WebP ${WEBP_libwebp_VERSION} found") 65 | 66 | include_directories(${WEBP_INCLUDE_DIRS}) 67 | link_directories(${WEBP_LIBRARY_DIRS}) 68 | 69 | if("${WEBP_libwebp_VERSION}" VERSION_LESS "0.5") 70 | set(WEBP_0_5 0) 71 | else() 72 | set(WEBP_0_5 1) 73 | endif() 74 | 75 | # Ensure that files in ${CMAKE_CURRENT_BINARY_DIR} are available 76 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 77 | 78 | # Include the source directory 79 | add_subdirectory(src) 80 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## gimp-webp 2 | 3 | This plugin provides [Gimp](https://www.gimp.org/) with the ability to load and export [WebP](https://developers.google.com/speed/webp/) images. During export, a dialog is presented that provides access to image quality settings. 4 | 5 | ![Gimp 2.8.x Export Dialog](images/gimp-2.8.x.png) 6 | ![Gimp 2.9.x Export Dialog](images/gimp-2.9.x.jpg) 7 | 8 | The plugin is designed to run on all platforms currently supported by the Gimp. 9 | 10 | ### Building 11 | 12 | In order to build this plugin, you will need the following app, tools, and libraries installed: 13 | 14 | - CMake 2.8.12+ 15 | - Gimp 2.8 or 2.9 development files 16 | - Webp 0.4+ development files 17 | 18 | The build process consists of: 19 | 20 | mkdir build 21 | cd build 22 | cmake .. 23 | make 24 | 25 | ### Installation 26 | 27 | On most *nix platforms, installation is as simple as: 28 | 29 | sudo make install 30 | 31 | If you don't have root privileges, you can copy the `src/file-webp` binary to the appropriate directory: 32 | 33 | - **Gimp 2.8.x:** — `~/.gimp-2.8/plug-ins/` 34 | - **Gimp 2.9.x:** — `~/.config/GIMP/2.9/plug-ins/` 35 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | gimp-webp (0.4) unstable; urgency=low 2 | 3 | * Merge draekko/gimp-webp master 4 | * Add conditional flags for compiling with Gimp 2.8.x and 2.9.x 5 | 6 | -- Nathan Osman Thu, 28 Jul 2016 10:43:50 -0700 7 | 8 | gimp-webp (0.3) unstable; urgency=low 9 | 10 | * Export dialog is no longer shown when running non-interactively 11 | * Settings dialog has been greatly simplified 12 | * Improved verbosity of error messages 13 | 14 | -- Nathan Osman Sat, 15 Aug 2015 15:29:42 -0700 15 | 16 | gimp-webp (0.2) unstable; urgency=low 17 | 18 | * Added support for lossless WebP images 19 | * Added support for reading and writing images with alpha channels 20 | * Added preset selection to export dialog 21 | * Progress is now displayed for exporting images 22 | 23 | -- Nathan Osman Sat, 06 Jun 2015 22:02:52 -0700 24 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: gimp-webp 2 | Section: graphics 3 | Priority: extra 4 | Maintainer: Nathan Osman 5 | Build-Depends: debhelper (>= 9), cmake, libgimp2.0-dev, libwebp-dev 6 | Standards-Version: 3.9.8 7 | Homepage: https://github.com/nathan-osman/gimp-webp 8 | 9 | Package: gimp-webp 10 | Architecture: any 11 | Depends: ${shlibs:Depends}, ${misc:Depends} 12 | Description: Gimp plugin providing WebP load and export 13 | This plugin provides Gimp with the ability to load and export WebP images. 14 | During export, a dialog is presented that provides access to image quality 15 | settings. 16 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | Format: http://dep.debian.net/deps/dep5 2 | Upstream-Name: gimp-webp 3 | Upstream-Contact: 2016 Nathan Osman 4 | Source: https://github.com/nathan-osman/gimp-webp 5 | 6 | Files: * 7 | Copyright: 2016 Nathan Osman 8 | Copyright: 2016 Ben Touchette 9 | License: GPL-3.0+ 10 | 11 | License: GPL-3.0+ 12 | This program is free software: you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation, either version 3 of the License, or 15 | (at your option) any later version. 16 | . 17 | This program is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU General Public License for more details. 21 | . 22 | You should have received a copy of the GNU General Public License 23 | along with this program. If not, see . 24 | . 25 | On Debian systems, the complete text of the GNU General 26 | Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". 27 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | %: 4 | dh $@ 5 | -------------------------------------------------------------------------------- /debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (native) 2 | -------------------------------------------------------------------------------- /images/gimp-2.8.x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathan-osman/gimp-webp/2ec56a34e1d009f0cb3d3708fa2fc98e4f33bc16/images/gimp-2.8.x.png -------------------------------------------------------------------------------- /images/gimp-2.9.x.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathan-osman/gimp-webp/2ec56a34e1d009f0cb3d3708fa2fc98e4f33bc16/images/gimp-2.9.x.jpg -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # gimp-webp - WebP Plugin for the GIMP 2 | # Copyright (C) 2016 Nathan Osman & Ben Touchette 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | # Prepare the configuration file 18 | configure_file(config.h.in "${CMAKE_CURRENT_BINARY_DIR}/config.h") 19 | 20 | # Specify each of the required source files 21 | set(SRC 22 | webp-dialog.c 23 | webp-load.c 24 | webp-save.c 25 | webp.c) 26 | 27 | # Build the file-webp executable 28 | add_executable(file-webp ${SRC}) 29 | target_link_libraries(file-webp ${GIMP_LIBRARIES} ${GEGL_LIBRARIES} ${WEBP_LIBRARIES}) 30 | 31 | # In order to determine the correct installation directory, we need to directly 32 | # invoke pkg-config to obtain the lib/ directory 33 | execute_process(COMMAND 34 | ${PKG_CONFIG_EXECUTABLE} --variable=gimplibdir gimp-2.0 35 | RESULT_VARIABLE PKG_CONFIG_RESULT 36 | OUTPUT_VARIABLE GIMP_LIB_DIR 37 | OUTPUT_STRIP_TRAILING_WHITESPACE) 38 | 39 | # Only set an installation directory if the command succeeded 40 | if(PKG_CONFIG_RESULT) 41 | message(WARNING "gimplibdir not set, install target unavailable") 42 | else() 43 | install(TARGETS file-webp RUNTIME DESTINATION "${GIMP_LIB_DIR}/plug-ins") 44 | endif() 45 | -------------------------------------------------------------------------------- /src/config.h.in: -------------------------------------------------------------------------------- 1 | /** 2 | * gimp-webp - WebP Plugin for the GIMP 3 | * Copyright (C) 2016 Nathan Osman & Ben Touchette 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __CONFIG_H__ 20 | #define __CONFIG_H__ 21 | 22 | #cmakedefine GIMP_2_9 23 | #cmakedefine WEBP_0_5 24 | 25 | #endif /* __CONFIG_H__ */ 26 | -------------------------------------------------------------------------------- /src/webp-dialog.c: -------------------------------------------------------------------------------- 1 | /** 2 | * gimp-webp - WebP Plugin for the GIMP 3 | * Copyright (C) 2016 Nathan Osman & Ben Touchette 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | #include "webp-dialog.h" 23 | #include "webp.h" 24 | 25 | struct { 26 | const gchar *id; 27 | const gchar *label; 28 | } presets[] = { 29 | { "default", "Default" }, 30 | { "picture", "Picture" }, 31 | { "photo", "Photo" }, 32 | { "drawing", "Drawing" }, 33 | { "icon", "Icon" }, 34 | { "text", "Text" }, 35 | { 0 } 36 | }; 37 | 38 | void save_dialog_response(GtkWidget *widget, 39 | gint response_id, 40 | gpointer data) 41 | { 42 | /* Store the response */ 43 | *(GtkResponseType *)data = response_id; 44 | 45 | /* Close the dialog */ 46 | gtk_widget_destroy(widget); 47 | } 48 | 49 | GtkListStore *save_dialog_presets() 50 | { 51 | GtkListStore *list_store; 52 | int i; 53 | 54 | /* Create the model */ 55 | list_store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); 56 | 57 | /* Insert the entries */ 58 | for(i = 0; presets[i].id; ++i) { 59 | gtk_list_store_insert_with_values(list_store, 60 | NULL, 61 | -1, 62 | 0, presets[i].id, 63 | 1, presets[i].label, 64 | -1); 65 | } 66 | 67 | return list_store; 68 | } 69 | 70 | void save_dialog_set_preset(GtkWidget *widget, 71 | gpointer data) 72 | { 73 | *(gchar **)data = gimp_string_combo_box_get_active(GIMP_STRING_COMBO_BOX(widget)); 74 | } 75 | 76 | void save_dialog_toggle_scale(GtkWidget *widget, 77 | gpointer data) 78 | { 79 | gimp_scale_entry_set_sensitive(GTK_OBJECT(data), 80 | !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))); 81 | } 82 | 83 | #ifdef WEBP_0_5 84 | void save_dialog_toggle_checkbox(GtkWidget *widget, 85 | gpointer data) 86 | { 87 | gtk_widget_set_sensitive(GTK_OBJECT(data), 88 | !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))); 89 | } 90 | #endif 91 | 92 | GtkResponseType save_dialog( 93 | WebPSaveParams *params 94 | #ifdef WEBP_0_5 95 | , gint32 image_ID 96 | , gint32 nLayers 97 | #endif 98 | ) 99 | { 100 | GtkWidget *dialog; 101 | GtkWidget *vbox; 102 | GtkWidget *label; 103 | GtkWidget *table; 104 | GtkWidget *preset_label; 105 | GtkListStore *preset_list; 106 | GtkWidget *preset_combo; 107 | GtkObject *quality_scale; 108 | GtkObject *alpha_quality_scale; 109 | GtkWidget *lossless_checkbox; 110 | #ifdef WEBP_0_5 111 | GtkWidget *animation_checkbox; 112 | GtkWidget *loop_anim_checkbox; 113 | gboolean animation_supported = FALSE; 114 | #endif 115 | GtkResponseType response; 116 | 117 | #ifdef WEBP_0_5 118 | /* Determine if the image contains more than one layer */ 119 | animation_supported = nLayers > 1; 120 | #endif 121 | 122 | /* Create the dialog */ 123 | dialog = gimp_export_dialog_new("WebP", 124 | BINARY_NAME, 125 | SAVE_PROCEDURE); 126 | 127 | /* Store the response when the dialog is closed */ 128 | g_signal_connect(dialog, 129 | "response", 130 | G_CALLBACK(save_dialog_response), 131 | &response); 132 | 133 | /* Quit the main loop when the dialog is closed */ 134 | g_signal_connect(dialog, 135 | "destroy", 136 | G_CALLBACK(gtk_main_quit), 137 | NULL); 138 | 139 | /* Create the vbox */ 140 | vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6); 141 | gtk_container_set_border_width(GTK_CONTAINER(vbox), 6); 142 | gtk_box_pack_start(GTK_BOX(gimp_export_dialog_get_content_area(dialog)), 143 | vbox, 144 | FALSE, FALSE, 145 | 0); 146 | gtk_widget_show(vbox); 147 | 148 | /* Create the descriptive label at the top */ 149 | label = gtk_label_new("Use the options below to customize the image."); 150 | gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); 151 | gtk_widget_show(label); 152 | 153 | /* Create the table */ 154 | table = gtk_table_new( 155 | #ifdef WEBP_0_5 156 | animation_supported == TRUE ? 6 : 4 157 | #else 158 | 4 159 | #endif 160 | , 3 161 | , FALSE 162 | ); 163 | gtk_table_set_row_spacings(GTK_TABLE(table), 6); 164 | gtk_table_set_col_spacings(GTK_TABLE(table), 6); 165 | gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); 166 | gtk_widget_show(table); 167 | 168 | /* Create the label for the selecting a preset */ 169 | preset_label = gtk_label_new("Preset:"); 170 | gtk_table_attach(GTK_TABLE(table), 171 | preset_label, 172 | 0, 1, 173 | 0, 1, 174 | 0, 0, 175 | 0, 0); 176 | gtk_widget_show(preset_label); 177 | 178 | /* Create the combobox containing the presets */ 179 | preset_list = save_dialog_presets(); 180 | preset_combo = gimp_string_combo_box_new(GTK_TREE_MODEL(preset_list), 0, 1); 181 | g_object_unref(preset_list); 182 | 183 | gimp_string_combo_box_set_active(GIMP_STRING_COMBO_BOX(preset_combo), params->preset); 184 | gtk_table_attach(GTK_TABLE(table), 185 | preset_combo, 186 | 1, 3, 187 | 0, 1, 188 | GTK_FILL, GTK_FILL, 189 | 0, 0); 190 | gtk_widget_show(preset_combo); 191 | 192 | g_signal_connect(preset_combo, "changed", 193 | G_CALLBACK(save_dialog_set_preset), 194 | ¶ms->preset); 195 | 196 | /* Create the slider for image quality */ 197 | quality_scale = gimp_scale_entry_new(GTK_TABLE(table), 198 | 0, 1, 199 | "Image quality:", 200 | 125, 201 | 0, 202 | params->quality, 203 | 0.0, 100.0, 204 | 1.0, 10.0, 205 | 0, TRUE, 206 | 0.0, 0.0, 207 | "Image quality", 208 | NULL); 209 | gimp_scale_entry_set_sensitive(quality_scale, !params->lossless); 210 | g_signal_connect(quality_scale, "value-changed", 211 | G_CALLBACK(gimp_float_adjustment_update), 212 | ¶ms->quality); 213 | 214 | /* Create the slider for alpha channel quality */ 215 | alpha_quality_scale = gimp_scale_entry_new(GTK_TABLE(table), 216 | 0, 2, 217 | "Alpha quality:", 218 | 125, 219 | 0, 220 | params->alpha_quality, 221 | 0.0, 100.0, 222 | 1.0, 10.0, 223 | 0, TRUE, 224 | 0.0, 0.0, 225 | "Alpha channel quality", 226 | NULL); 227 | gimp_scale_entry_set_sensitive(alpha_quality_scale, !params->lossless); 228 | g_signal_connect(alpha_quality_scale, "value-changed", 229 | G_CALLBACK(gimp_float_adjustment_update), 230 | ¶ms->alpha_quality); 231 | 232 | /* Create the lossless checkbox */ 233 | lossless_checkbox = gtk_check_button_new_with_label("Lossless"); 234 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lossless_checkbox), params->lossless); 235 | gtk_table_attach(GTK_TABLE(table), 236 | lossless_checkbox, 237 | 1, 3, 238 | 3, 4, 239 | GTK_FILL, GTK_FILL, 240 | 0, 0); 241 | gtk_widget_show(lossless_checkbox); 242 | 243 | g_signal_connect(lossless_checkbox, "toggled", 244 | G_CALLBACK(gimp_toggle_button_update), 245 | ¶ms->lossless); 246 | 247 | /* Enable and disable the sliders when the lossless option is selected */ 248 | g_signal_connect(lossless_checkbox, "toggled", 249 | G_CALLBACK(save_dialog_toggle_scale), 250 | quality_scale); 251 | g_signal_connect(lossless_checkbox, "toggled", 252 | G_CALLBACK(save_dialog_toggle_scale), 253 | alpha_quality_scale); 254 | 255 | #ifdef WEBP_0_5 256 | if (animation_supported == TRUE) { 257 | 258 | /* Create the animation checkbox */ 259 | animation_checkbox = gtk_check_button_new_with_label("Use animation"); 260 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(animation_checkbox), params->animation); 261 | gtk_table_attach(GTK_TABLE(table), 262 | animation_checkbox, 263 | 1, 3, 264 | 4, 5, 265 | GTK_FILL, GTK_FILL, 266 | 0, 0); 267 | gtk_widget_show(animation_checkbox); 268 | 269 | g_signal_connect(animation_checkbox, "toggled", 270 | G_CALLBACK(gimp_toggle_button_update), 271 | ¶ms->animation); 272 | 273 | /* Create the loop animation checkbox */ 274 | loop_anim_checkbox = gtk_check_button_new_with_label("Loop infinitely"); 275 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(loop_anim_checkbox), params->loop); 276 | gtk_table_attach(GTK_TABLE(table), 277 | loop_anim_checkbox, 278 | 1, 3, 279 | 5, 6, 280 | GTK_FILL, GTK_FILL, 281 | 0, 0); 282 | gtk_widget_show(loop_anim_checkbox); 283 | 284 | g_signal_connect(loop_anim_checkbox, "toggled", 285 | G_CALLBACK(gimp_toggle_button_update), 286 | ¶ms->loop); 287 | 288 | /* Enable and disable the loop checkbox when the animation checkbox is selected */ 289 | g_signal_connect(animation_checkbox, "toggled", 290 | G_CALLBACK(save_dialog_toggle_checkbox), 291 | loop_anim_checkbox); 292 | } 293 | #endif 294 | 295 | /* Display the dialog and enter the main event loop */ 296 | gtk_widget_show(dialog); 297 | gtk_main(); 298 | 299 | return response; 300 | } 301 | -------------------------------------------------------------------------------- /src/webp-dialog.h: -------------------------------------------------------------------------------- 1 | /** 2 | * gimp-webp - WebP Plugin for the GIMP 3 | * Copyright (C) 2016 Nathan Osman & Ben Touchette 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __WEBP_DIALOG_H__ 20 | #define __WEBP_DIALOG_H__ 21 | 22 | #include 23 | 24 | #include "config.h" 25 | #include "webp-save.h" 26 | 27 | GtkResponseType save_dialog( 28 | WebPSaveParams *params 29 | #ifdef WEBP_0_5 30 | , gint32 image_ID 31 | , gint32 nLayers 32 | #endif 33 | ); 34 | 35 | #endif /* __WEBP_DIALOG_H__ */ 36 | -------------------------------------------------------------------------------- /src/webp-load.c: -------------------------------------------------------------------------------- 1 | /** 2 | * gimp-webp - WebP Plugin for the GIMP 3 | * Copyright (C) 2016 Nathan Osman & Ben Touchette 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "config.h" 27 | #include "webp-load.h" 28 | 29 | #ifdef GIMP_2_9 30 | # include 31 | #endif 32 | 33 | /* Create a layer with the provided image data and add it to the image */ 34 | gboolean create_layer(gint32 image_ID, 35 | uint8_t *layer_data, 36 | gint32 position, 37 | gchar *name, 38 | gint width, 39 | gint height, 40 | gint32 offsetx, 41 | gint32 offsety) 42 | { 43 | gint32 layer_ID; 44 | #ifdef GIMP_2_9 45 | GeglBuffer *geglbuffer; 46 | GeglRectangle extent; 47 | #else 48 | GimpDrawable *drawable; 49 | GimpPixelRgn region; 50 | #endif 51 | 52 | layer_ID = gimp_layer_new(image_ID, 53 | name, 54 | width, height, 55 | GIMP_RGBA_IMAGE, 56 | 100, 57 | GIMP_NORMAL_MODE); 58 | 59 | #ifdef GIMP_2_9 60 | /* Retrieve the buffer for the layer */ 61 | geglbuffer = gimp_drawable_get_buffer(layer_ID); 62 | 63 | /* Copy the image data to the region */ 64 | gegl_rectangle_set(&extent, 0, 0, width, height); 65 | gegl_buffer_set(geglbuffer, &extent, 0, NULL, layer_data, GEGL_AUTO_ROWSTRIDE); 66 | 67 | /* Flush the drawable and detach */ 68 | gegl_buffer_flush(geglbuffer); 69 | 70 | g_object_unref(geglbuffer); 71 | #else 72 | /* Retrieve the drawable for the layer */ 73 | drawable = gimp_drawable_get(layer_ID); 74 | 75 | /* Get a pixel region from the layer */ 76 | gimp_pixel_rgn_init(®ion, 77 | drawable, 78 | 0, 0, 79 | width, height, 80 | FALSE, FALSE); 81 | 82 | /* Copy the image data to the region */ 83 | gimp_pixel_rgn_set_rect(®ion, 84 | layer_data, 85 | 0, 0, 86 | width, height); 87 | 88 | /* Flush the drawable and detach */ 89 | gimp_drawable_flush(drawable); 90 | gimp_drawable_detach(drawable); 91 | #endif 92 | 93 | /* Add the new layer to the image */ 94 | gimp_image_insert_layer(image_ID, layer_ID, -1, position); 95 | 96 | /* If layer offsets were provided, use them to position the image */ 97 | if (offsetx || offsety) { 98 | gimp_layer_set_offsets(layer_ID, offsetx, offsety); 99 | } 100 | 101 | /* TODO: fix this */ 102 | return TRUE; 103 | } 104 | 105 | gboolean load_image(const gchar *filename, 106 | gint32 *image_ID, 107 | GError **error) 108 | { 109 | gboolean status = FALSE; 110 | gchar *indata = NULL; 111 | gsize indatalen; 112 | gint width; 113 | gint height; 114 | WebPMux *mux = NULL; 115 | WebPData wp_data; 116 | uint32_t flags; 117 | uint8_t *outdata = NULL; 118 | 119 | #ifdef GIMP_2_9 120 | /* Initialize GEGL */ 121 | gegl_init(NULL, NULL); 122 | #endif 123 | 124 | do { 125 | 126 | /* Attempt to read the file contents from disk */ 127 | if (g_file_get_contents(filename, 128 | &indata, 129 | &indatalen, 130 | error) == FALSE) { 131 | break; 132 | } 133 | 134 | /* Validate WebP data, grabbing the width and height */ 135 | if (!WebPGetInfo(indata, indatalen, &width, &height)) { 136 | break; 137 | } 138 | 139 | /* Create a WebPMux from the contents of the file */ 140 | wp_data.bytes = (uint8_t*)indata; 141 | wp_data.size = indatalen; 142 | 143 | mux = WebPMuxCreate(&wp_data, 1); 144 | if (mux == NULL) { 145 | break; 146 | } 147 | 148 | /* Retrieve the features present */ 149 | if (WebPMuxGetFeatures(mux, &flags) != WEBP_MUX_OK) { 150 | break; 151 | } 152 | 153 | /* TODO: decode the image in "chunks" or "tiles" */ 154 | /* TODO: check if an alpha channel is present */ 155 | 156 | /* Create the new image and associated layer */ 157 | *image_ID = gimp_image_new(width, height, GIMP_RGB); 158 | 159 | #ifdef WEBP_0_5 160 | if (flags & ANIMATION_FLAG) { 161 | int frames, i; 162 | 163 | /* Retrieve the number of frames */ 164 | WebPMuxNumChunks(mux, WEBP_CHUNK_ANMF, &frames); 165 | 166 | /* Loop over each of the frames */ 167 | for (i = 0; i < frames; ++i) { 168 | WebPMuxFrameInfo frame = {0}; 169 | 170 | /* Retrieve the data for the frame */ 171 | if (WebPMuxGetFrame(mux, i, &frame) != WEBP_MUX_OK) { 172 | goto error; 173 | } 174 | 175 | /* Decode the frame */ 176 | outdata = WebPDecodeRGBA(frame.bitstream.bytes, 177 | frame.bitstream.size, 178 | &width, &height); 179 | 180 | /* Free the compressed data */ 181 | WebPDataClear(&frame.bitstream); 182 | 183 | if (!outdata) { 184 | goto error; 185 | } 186 | 187 | /* Create a layer for the frame */ 188 | char name[255]; 189 | snprintf(name, 255, "Frame %d", (i + 1)); 190 | 191 | if (create_layer(*image_ID, 192 | outdata, 193 | 0, 194 | (gchar*)name, 195 | width, height, 196 | frame.x_offset, 197 | frame.y_offset) == FALSE) { 198 | goto error; 199 | } 200 | } 201 | 202 | /* If all is well, jump *over* the error label - otherwise 203 | leave the loop and begin cleaning things up */ 204 | 205 | goto success; 206 | 207 | error: 208 | break; 209 | 210 | success: ; 211 | 212 | } else { 213 | #endif 214 | 215 | /* Attempt to decode the data as a WebP image */ 216 | outdata = WebPDecodeRGBA(indata, indatalen, &width, &height); 217 | if (!outdata) { 218 | break; 219 | } 220 | 221 | /* Create a single layer */ 222 | status = create_layer(*image_ID, 223 | outdata, 224 | 0, 225 | "Background", 226 | width, height, 227 | 0, 0); 228 | 229 | #ifdef WEBP_0_5 230 | } 231 | 232 | #ifdef GIMP_2_9 233 | /* Load a color profile if one was provided */ 234 | if (flags & ICCP_FLAG) { 235 | WebPData icc_profile; 236 | GimpColorProfile *profile; 237 | 238 | /* Load the ICC profile from the file */ 239 | WebPMuxGetChunk(mux, "ICCP", &icc_profile); 240 | 241 | /* Have Gimp load the color profile */ 242 | profile = gimp_color_profile_new_from_icc_profile( 243 | icc_profile.bytes, icc_profile.size, NULL); 244 | if (profile) { 245 | gimp_image_set_color_profile(image_ID, profile); 246 | g_object_unref(profile); 247 | } 248 | } 249 | #endif 250 | #endif 251 | /* Set the filename for the image */ 252 | gimp_image_set_filename(*image_ID, filename); 253 | 254 | } while(0); 255 | 256 | /* Delete the mux object */ 257 | if (mux) { 258 | WebPMuxDelete(mux); 259 | } 260 | 261 | /* Free the data read from disk */ 262 | if (indata) { 263 | g_free(indata); 264 | } 265 | 266 | return status; 267 | } 268 | -------------------------------------------------------------------------------- /src/webp-load.h: -------------------------------------------------------------------------------- 1 | /** 2 | * gimp-webp - WebP Plugin for the GIMP 3 | * Copyright (C) 2016 Nathan Osman & Ben Touchette 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __WEBP_LOAD_H__ 20 | #define __WEBP_LOAD_H__ 21 | 22 | #include 23 | 24 | gboolean load_image(const gchar *filename, 25 | gint32 *image_ID, 26 | GError **error); 27 | 28 | #endif /* __WEBP_LOAD_H__ */ 29 | -------------------------------------------------------------------------------- /src/webp-save.c: -------------------------------------------------------------------------------- 1 | /** 2 | * gimp-webp - WebP Plugin for the GIMP 3 | * Copyright (C) 2016 Nathan Osman & Ben Touchette 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "webp-save.h" 28 | 29 | #ifdef GIMP_2_9 30 | # include 31 | #endif 32 | 33 | /* Determine which WebP preset to use given its name */ 34 | WebPPreset webp_preset_by_name(gchar *name) 35 | { 36 | if (!strcmp(name, "picture")) { 37 | return WEBP_PRESET_PICTURE; 38 | } else if (!strcmp(name, "photo")) { 39 | return WEBP_PRESET_PHOTO; 40 | } else if (!strcmp(name, "drawing")) { 41 | return WEBP_PRESET_DRAWING; 42 | } else if (!strcmp(name, "icon")) { 43 | return WEBP_PRESET_ICON; 44 | } else if (!strcmp(name, "text")) { 45 | return WEBP_PRESET_TEXT; 46 | } else { 47 | return WEBP_PRESET_DEFAULT; 48 | } 49 | } 50 | 51 | /* Write the provided data to the file */ 52 | int webp_file_writer(const uint8_t *data, 53 | size_t data_size, 54 | const WebPPicture *picture) 55 | { 56 | FILE *outfile; 57 | 58 | /* Obtain the FILE* and write the data to the file */ 59 | outfile = (FILE*)picture->custom_ptr; 60 | return fwrite(data, sizeof(uint8_t), data_size, outfile) == data_size; 61 | } 62 | 63 | /* Update progress as data is written to the file */ 64 | int webp_file_progress(int percent, 65 | const WebPPicture *picture) 66 | { 67 | return gimp_progress_update(percent / 100.0); 68 | } 69 | 70 | /* Convert error into a human-readable message */ 71 | const gchar *webp_error_string(WebPEncodingError error_code) 72 | { 73 | switch(error_code) { 74 | case VP8_ENC_ERROR_OUT_OF_MEMORY: 75 | return "out of memory"; 76 | case VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY: 77 | return "not enough memory to flush bits"; 78 | case VP8_ENC_ERROR_NULL_PARAMETER: 79 | return "NULL parameter"; 80 | case VP8_ENC_ERROR_INVALID_CONFIGURATION: 81 | return "invalid configuration"; 82 | case VP8_ENC_ERROR_BAD_DIMENSION: 83 | return "bad image dimensions"; 84 | case VP8_ENC_ERROR_PARTITION0_OVERFLOW: 85 | return "partition is bigger than 512K"; 86 | case VP8_ENC_ERROR_PARTITION_OVERFLOW: 87 | return "partition is bigger than 16M"; 88 | case VP8_ENC_ERROR_BAD_WRITE: 89 | return "unable to flush bytes"; 90 | case VP8_ENC_ERROR_FILE_TOO_BIG: 91 | return "file is larger than 4GiB"; 92 | case VP8_ENC_ERROR_USER_ABORT: 93 | return "user aborted encoding"; 94 | case VP8_ENC_ERROR_LAST: 95 | return "list terminator"; 96 | default: 97 | return "unknown error"; 98 | } 99 | } 100 | 101 | /* Save a layer from an image */ 102 | gboolean save_layer(gint32 drawable_ID, 103 | WebPWriterFunction writer, 104 | void *custom_ptr, 105 | #ifdef WEBP_0_5 106 | gboolean animation, 107 | WebPAnimEncoder *enc, 108 | int frame_timestamp, 109 | #endif 110 | WebPSaveParams *params, 111 | GError **error) 112 | { 113 | gboolean status = FALSE; 114 | gint bpp; 115 | gint width; 116 | gint height; 117 | GimpImageType drawable_type; 118 | WebPConfig config; 119 | WebPPicture picture; 120 | guchar *buffer = NULL; 121 | #ifdef GIMP_2_9 122 | GeglBuffer *geglbuffer; 123 | GeglRectangle extent; 124 | #else 125 | GimpDrawable *drawable = NULL; 126 | GimpPixelRgn region; 127 | #endif 128 | 129 | /* Retrieve the image data */ 130 | bpp = gimp_drawable_bpp(drawable_ID); 131 | width = gimp_drawable_width(drawable_ID); 132 | height = gimp_drawable_height(drawable_ID); 133 | drawable_type = gimp_drawable_type(drawable_ID); 134 | 135 | /* Initialize the WebP configuration with a preset and fill in the 136 | * remaining values */ 137 | WebPConfigPreset(&config, 138 | webp_preset_by_name(params->preset), 139 | params->quality); 140 | 141 | config.lossless = params->lossless; 142 | config.method = 6; /* better quality */ 143 | config.alpha_quality = params->alpha_quality; 144 | 145 | /* Prepare the WebP structure */ 146 | WebPPictureInit(&picture); 147 | picture.use_argb = 1; 148 | picture.width = width; 149 | picture.height = height; 150 | picture.writer = writer; 151 | picture.custom_ptr = custom_ptr; 152 | picture.progress_hook = webp_file_progress; 153 | 154 | do { 155 | /* Attempt to allocate a buffer of the appropriate size */ 156 | buffer = (guchar *)g_malloc(bpp * width * height); 157 | if(!buffer) { 158 | g_set_error(error, 159 | G_FILE_ERROR, 160 | 0, 161 | "Unable to allocate buffer for layer"); 162 | break; 163 | } 164 | 165 | #ifdef GIMP_2_9 166 | /* Obtain the buffer and get its extent */ 167 | geglbuffer = gimp_drawable_get_buffer(drawable_ID); 168 | extent = *gegl_buffer_get_extent(geglbuffer); 169 | 170 | /* Read the layer buffer into our buffer */ 171 | gegl_buffer_get(geglbuffer, &extent, 1.0, NULL, buffer, 172 | GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); 173 | 174 | g_object_unref(geglbuffer); 175 | #else 176 | /* Get the drawable */ 177 | drawable = gimp_drawable_get(drawable_ID); 178 | 179 | /* Obtain the pixel region for the drawable */ 180 | gimp_pixel_rgn_init(®ion, 181 | drawable, 182 | 0, 0, 183 | width, 184 | height, 185 | FALSE, FALSE); 186 | 187 | /* Read the region into the buffer */ 188 | gimp_pixel_rgn_get_rect(®ion, 189 | buffer, 190 | 0, 0, 191 | width, 192 | height); 193 | 194 | gimp_drawable_detach(drawable); 195 | #endif 196 | 197 | /* Use the appropriate function to import the data from the buffer */ 198 | if(drawable_type == GIMP_RGB_IMAGE) { 199 | WebPPictureImportRGB(&picture, buffer, width * bpp); 200 | } else { 201 | WebPPictureImportRGBA(&picture, buffer, width * bpp); 202 | } 203 | 204 | #ifdef WEBP_0_5 205 | if (animation == TRUE) { 206 | 207 | if (!WebPAnimEncoderAdd(enc, &picture, frame_timestamp, &config)) { 208 | g_set_error(error, 209 | G_FILE_ERROR, 210 | picture.error_code, 211 | "WebP error: '%s'", 212 | webp_error_string(picture.error_code)); 213 | break; 214 | } 215 | } else { 216 | #endif 217 | if(!WebPEncode(&config, &picture)) { 218 | g_set_error(error, 219 | G_FILE_ERROR, 220 | picture.error_code, 221 | "WebP error: '%s'", 222 | webp_error_string(picture.error_code)); 223 | break; 224 | } 225 | #ifdef WEBP_0_5 226 | } 227 | #endif 228 | 229 | /* Everything succeeded */ 230 | status = TRUE; 231 | 232 | } while(0); 233 | 234 | /* Free the buffer */ 235 | if (buffer) { 236 | free(buffer); 237 | } 238 | 239 | return status; 240 | } 241 | 242 | #ifdef WEBP_0_5 243 | /* Save an animation to disk */ 244 | gboolean save_animation(gint32 nLayers, 245 | gint32 *allLayers, 246 | FILE *outfile, 247 | WebPSaveParams *params, 248 | GError **error) 249 | { 250 | gboolean status = FALSE; 251 | gboolean innerStatus = TRUE; 252 | WebPAnimEncoderOptions enc_options; 253 | WebPAnimEncoder *enc = NULL; 254 | int frame_timestamp = 0; 255 | WebPData webp_data = {0}; 256 | WebPMux *mux; 257 | WebPMuxAnimParams anim_params = {0}; 258 | 259 | /* Prepare for encoding an animation */ 260 | WebPAnimEncoderOptionsInit(&enc_options); 261 | 262 | do { 263 | int i; 264 | gint32 drawable_ID = allLayers[0]; 265 | 266 | /* Create the encoder */ 267 | enc = WebPAnimEncoderNew(gimp_drawable_width(drawable_ID), 268 | gimp_drawable_height(drawable_ID), 269 | &enc_options); 270 | 271 | /* Encode each layer */ 272 | for (i = 0; i < nLayers; i++) { 273 | if ((innerStatus = save_layer(allLayers[i], 274 | NULL, 275 | NULL, 276 | TRUE, 277 | enc, 278 | frame_timestamp, 279 | params, 280 | error)) == FALSE) { 281 | break; 282 | } 283 | } 284 | 285 | /* Check to make sure each layer was encoded correctly */ 286 | if (innerStatus == FALSE) { 287 | break; 288 | } 289 | 290 | /* Add NULL frame */ 291 | WebPAnimEncoderAdd(enc, NULL, frame_timestamp, NULL); 292 | 293 | /* Initialize the WebP image structure */ 294 | WebPDataInit(&webp_data); 295 | 296 | /* Write the animation to the image */ 297 | if (!WebPAnimEncoderAssemble(enc, &webp_data)) { 298 | g_set_error(error, 299 | G_FILE_ERROR, 300 | 0, 301 | "Encoding error: '%s'", 302 | WebPAnimEncoderGetError(enc)); 303 | break; 304 | } 305 | 306 | /* Create a Mux */ 307 | mux = WebPMuxCreate(&webp_data, 1); 308 | 309 | /* Set animation parameters */ 310 | anim_params.loop_count = params->loop == TRUE ? 0 : 1; 311 | WebPMuxSetAnimationParams(mux, &anim_params); 312 | 313 | /* Assemble the image */ 314 | WebPMuxAssemble(mux, &webp_data); 315 | 316 | /* Write to disk */ 317 | if (fwrite(webp_data.bytes, webp_data.size, 1, outfile) != 1) { 318 | break; 319 | } 320 | 321 | /* Everything succeeded */ 322 | status = TRUE; 323 | 324 | } while(0); 325 | 326 | /* Free image data */ 327 | WebPDataClear(&webp_data); 328 | 329 | /* Free the animation encoder */ 330 | if (enc) { 331 | WebPAnimEncoderDelete(enc); 332 | } 333 | 334 | return status; 335 | } 336 | #endif 337 | 338 | /* Save a WebP image to disk */ 339 | gboolean save_image(const gchar *filename, 340 | #ifdef WEBP_0_5 341 | gint32 nLayers, 342 | gint32 *allLayers, 343 | #endif 344 | gint32 drawable_ID, 345 | WebPSaveParams *params, 346 | GError **error) 347 | { 348 | gboolean status = FALSE; 349 | FILE *outfile = NULL; 350 | 351 | #ifdef GIMP_2_9 352 | /* Initialize GEGL */ 353 | gegl_init(NULL, NULL); 354 | #endif 355 | 356 | /* Begin displaying export progress */ 357 | gimp_progress_init_printf("Saving '%s'", 358 | gimp_filename_to_utf8(filename)); 359 | 360 | /* Attempt to open the output file */ 361 | if((outfile = g_fopen(filename, "wb+")) == NULL) { 362 | g_set_error(error, 363 | G_FILE_ERROR, 364 | g_file_error_from_errno(errno), 365 | "Unable to open '%s' for writing", 366 | gimp_filename_to_utf8(filename)); 367 | return FALSE; 368 | } 369 | 370 | #ifdef WEBP_0_5 371 | if (params->animation == TRUE) { 372 | status = save_animation(nLayers, 373 | allLayers, 374 | outfile, 375 | params, 376 | error); 377 | } else { 378 | #endif 379 | status = save_layer(drawable_ID, 380 | webp_file_writer, 381 | outfile, 382 | #ifdef WEBP_0_5 383 | FALSE, 384 | NULL, 385 | 0, 386 | #endif 387 | params, 388 | error); 389 | #ifdef WEBP_0_5 390 | } 391 | #endif 392 | 393 | /* Close the file */ 394 | if(outfile) { 395 | fclose(outfile); 396 | } 397 | 398 | return status; 399 | } 400 | -------------------------------------------------------------------------------- /src/webp-save.h: -------------------------------------------------------------------------------- 1 | /** 2 | * gimp-webp - WebP Plugin for the GIMP 3 | * Copyright (C) 2016 Nathan Osman & Ben Touchette 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __WEBP_SAVE_H__ 20 | #define __WEBP_SAVE_H__ 21 | 22 | #include 23 | 24 | #include "config.h" 25 | 26 | typedef struct { 27 | gchar *preset; 28 | gboolean lossless; 29 | gfloat quality; 30 | gfloat alpha_quality; 31 | #ifdef WEBP_0_5 32 | gboolean animation; 33 | gboolean loop; 34 | #endif 35 | } WebPSaveParams; 36 | 37 | gboolean save_image(const gchar *filename, 38 | #ifdef WEBP_0_5 39 | gint32 nLayers, 40 | gint32 *allLayers, 41 | #endif 42 | gint32 drawable_ID, 43 | WebPSaveParams *params, 44 | GError **error); 45 | 46 | #endif /* __WEBP_SAVE_H__ */ 47 | -------------------------------------------------------------------------------- /src/webp.c: -------------------------------------------------------------------------------- 1 | /** 2 | * gimp-webp - WebP Plugin for the GIMP 3 | * Copyright (C) 2016 Nathan Osman & Ben Touchette 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "config.h" 25 | #include "webp-dialog.h" 26 | #include "webp-load.h" 27 | #include "webp-save.h" 28 | #include "webp.h" 29 | 30 | const char BINARY_NAME[] = "file-webp"; 31 | const char LOAD_PROCEDURE[] = "file-webp-load"; 32 | const char SAVE_PROCEDURE[] = "file-webp-save"; 33 | 34 | /* Predeclare our entrypoints. */ 35 | void query(); 36 | void run(const gchar *, gint, const GimpParam *, gint *, GimpParam **); 37 | 38 | /* Declare our plugin entry points. */ 39 | GimpPlugInInfo PLUG_IN_INFO = { 40 | NULL, 41 | NULL, 42 | query, 43 | run 44 | }; 45 | 46 | MAIN() 47 | 48 | /* This function registers our load and save handlers. */ 49 | void query() 50 | { 51 | /* Load arguments. */ 52 | static const GimpParamDef load_arguments[] = { 53 | { GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" }, 54 | { GIMP_PDB_STRING, "filename", "The name of the file to load" }, 55 | { GIMP_PDB_STRING, "raw-filename", "The name entered" } 56 | }; 57 | 58 | /* Load return values. */ 59 | static const GimpParamDef load_return_values[] = { 60 | { GIMP_PDB_IMAGE, "image", "Output image" } 61 | }; 62 | 63 | /* Save arguments. */ 64 | static const GimpParamDef save_arguments[] = { 65 | { GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" }, 66 | { GIMP_PDB_IMAGE, "image", "Input image" }, 67 | { GIMP_PDB_DRAWABLE, "drawable", "Drawable to save" }, 68 | { GIMP_PDB_STRING, "filename", "The name of the file to save the image to" }, 69 | { GIMP_PDB_STRING, "raw-filename", "The name entered" }, 70 | { GIMP_PDB_STRING, "preset", "Name of preset to use" }, 71 | { GIMP_PDB_INT32, "lossless", "Use lossless encoding (0/1)" }, 72 | { GIMP_PDB_FLOAT, "quality", "Quality of the image (0 <= quality <= 100)" }, 73 | { GIMP_PDB_FLOAT, "alpha-quality", "Quality of the image's alpha channel (0 <= alpha-quality <= 100)" }, 74 | { GIMP_PDB_INT32, "animation", "Use layers for animation (0/1)" }, 75 | { GIMP_PDB_INT32, "anim-loop", "Loop animation infinitely (0/1)" }, 76 | }; 77 | 78 | /* Install the load procedure. */ 79 | gimp_install_procedure(LOAD_PROCEDURE, 80 | "Loads images in the WebP file format", 81 | "Loads images in the WebP file format", 82 | "Nathan Osman & Ben Touchette", 83 | "Copyright (C) 2016 Nathan Osman & Ben Touchette", 84 | "2016", 85 | "WebP image", 86 | NULL, 87 | GIMP_PLUGIN, 88 | G_N_ELEMENTS(load_arguments), 89 | G_N_ELEMENTS(load_return_values), 90 | load_arguments, 91 | load_return_values); 92 | 93 | /* Install the save procedure. */ 94 | gimp_install_procedure(SAVE_PROCEDURE, 95 | "Saves files in the WebP image format", 96 | "Saves files in the WebP image format", 97 | "Nathan Osman & Ben Touchette", 98 | "Copyright (C) 2016 Nathan Osman & Ben Touchette", 99 | "2016", 100 | "WebP image", 101 | "RGB*", 102 | GIMP_PLUGIN, 103 | G_N_ELEMENTS(save_arguments), 104 | 0, 105 | save_arguments, 106 | NULL); 107 | 108 | /* Register the load handlers. */ 109 | gimp_register_file_handler_mime(LOAD_PROCEDURE, "image/webp"); 110 | gimp_register_load_handler(LOAD_PROCEDURE, "webp", ""); 111 | 112 | /* Now register the save handlers. */ 113 | gimp_register_file_handler_mime(SAVE_PROCEDURE, "image/webp"); 114 | gimp_register_save_handler(SAVE_PROCEDURE, "webp", ""); 115 | } 116 | 117 | /* This function is called when one of our methods is invoked. */ 118 | void run(const gchar * name, 119 | gint nparams, 120 | const GimpParam * param, 121 | gint * nreturn_vals, 122 | GimpParam ** return_vals) 123 | { 124 | static GimpParam values[2]; 125 | GimpRunMode run_mode; 126 | GimpPDBStatusType status = GIMP_PDB_SUCCESS; 127 | gint32 image_ID; 128 | gint32 drawable_ID; 129 | GError *error = NULL; 130 | #ifdef WEBP_0_5 131 | gint32 nLayers; 132 | gint32 *allLayers; 133 | #endif 134 | 135 | /* Determine the current run mode */ 136 | run_mode = param[0].data.d_int32; 137 | 138 | /* Fill in the return values */ 139 | *nreturn_vals = 1; 140 | *return_vals = values; 141 | values[0].type = GIMP_PDB_STATUS; 142 | values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR; 143 | 144 | /* Determine which procedure is being invoked */ 145 | if(!strcmp(name, LOAD_PROCEDURE)) { 146 | 147 | /* No need to determine whether the plugin is being invoked 148 | * interactively here since we don't need a UI for loading */ 149 | 150 | if(load_image(param[1].data.d_string, &image_ID, &error) == TRUE) { 151 | 152 | /* Return the new image that was loaded */ 153 | *nreturn_vals = 2; 154 | values[1].type = GIMP_PDB_IMAGE; 155 | values[1].data.d_image = image_ID; 156 | 157 | } else { 158 | status = GIMP_PDB_EXECUTION_ERROR; 159 | } 160 | 161 | } else if(!strcmp(name, SAVE_PROCEDURE)) { 162 | 163 | WebPSaveParams params; 164 | GimpExportReturn export_ret = GIMP_EXPORT_CANCEL; 165 | 166 | /* Initialize the parameters to their defaults */ 167 | params.preset = "default"; 168 | params.lossless = FALSE; 169 | params.quality = 90.0f; 170 | params.alpha_quality = 100.0f; 171 | #ifdef WEBP_0_5 172 | params.animation = FALSE; 173 | params.loop = TRUE; 174 | #endif 175 | 176 | /* Load the image and drawable IDs */ 177 | image_ID = param[1].data.d_int32; 178 | drawable_ID = param[2].data.d_int32; 179 | 180 | #ifdef WEBP_0_5 181 | /* Load the image layers */ 182 | allLayers = gimp_image_get_layers(image_ID, &nLayers); 183 | #endif 184 | 185 | /* What happens next depends on the run mode */ 186 | switch(run_mode) { 187 | case GIMP_RUN_INTERACTIVE: 188 | case GIMP_RUN_WITH_LAST_VALS: 189 | 190 | gimp_ui_init(BINARY_NAME, FALSE); 191 | 192 | /* Attempt to export the image */ 193 | export_ret = gimp_export_image(&image_ID, 194 | &drawable_ID, 195 | "WEBP", 196 | GIMP_EXPORT_CAN_HANDLE_RGB | GIMP_EXPORT_CAN_HANDLE_ALPHA); 197 | 198 | /* Return immediately if canceled */ 199 | if(export_ret == GIMP_EXPORT_CANCEL) { 200 | values[0].data.d_status = GIMP_PDB_CANCEL; 201 | return; 202 | } 203 | 204 | /* Display the dialog */ 205 | if(save_dialog( 206 | ¶ms 207 | #ifdef WEBP_0_5 208 | , image_ID 209 | , nLayers 210 | #endif 211 | ) != GTK_RESPONSE_OK) { 212 | values[0].data.d_status = GIMP_PDB_CANCEL; 213 | return; 214 | } 215 | 216 | break; 217 | 218 | case GIMP_RUN_NONINTERACTIVE: 219 | 220 | /* Ensure the correct number of parameters were supplied 221 | Note: even if animation support is not available, 11 222 | parameters must still be supplied */ 223 | if(nparams != 11) { 224 | status = GIMP_PDB_CALLING_ERROR; 225 | break; 226 | } 227 | 228 | /* Load the parameters */ 229 | params.preset = param[5].data.d_string; 230 | params.lossless = param[6].data.d_int32; 231 | params.quality = param[7].data.d_float; 232 | params.alpha_quality = param[8].data.d_float; 233 | #ifdef WEBP_0_5 234 | params.animation = param[9].data.d_int32; 235 | params.loop = param[10].data.d_int32; 236 | #endif 237 | 238 | break; 239 | } 240 | 241 | /* Attempt to save the image */ 242 | if (!save_image(param[3].data.d_string, 243 | #ifdef WEBP_0_5 244 | nLayers, 245 | allLayers, 246 | #endif 247 | drawable_ID, 248 | ¶ms, 249 | &error)) { 250 | status = GIMP_PDB_EXECUTION_ERROR; 251 | } 252 | 253 | #ifdef WEBP_0_5 254 | g_free(allLayers); 255 | #endif 256 | } 257 | 258 | /* If an error was supplied, include it in the return values */ 259 | if(status != GIMP_PDB_SUCCESS && error) { 260 | *nreturn_vals = 2; 261 | values[1].type = GIMP_PDB_STRING; 262 | values[1].data.d_string = error->message; 263 | } 264 | 265 | values[0].data.d_status = status; 266 | } 267 | -------------------------------------------------------------------------------- /src/webp.h: -------------------------------------------------------------------------------- 1 | /** 2 | * gimp-webp - WebP Plugin for the GIMP 3 | * Copyright (C) 2016 Nathan Osman & Ben Touchette 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __WEBP_H__ 20 | #define __WEBP_H__ 21 | 22 | extern const char BINARY_NAME[]; 23 | extern const char SAVE_PROCEDURE[]; 24 | 25 | #endif /* __WEBP_H__ */ 26 | --------------------------------------------------------------------------------