├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── __init__.py ├── addon_preferences.py ├── get_image_size.py ├── img └── ts_ui.gif ├── main_operators.py ├── tsynth_props.py ├── tsynth_ui.py └── utils.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows thumbnail cache files 2 | Thumbs.db 3 | ehthumbs.db 4 | ehthumbs_vista.db 5 | 6 | # Folder config file 7 | Desktop.ini 8 | 9 | # Recycle Bin used on file shares 10 | $RECYCLE.BIN/ 11 | 12 | # Windows Installer files 13 | *.cab 14 | *.msi 15 | *.msm 16 | *.msp 17 | 18 | # Windows shortcuts 19 | *.lnk 20 | 21 | # ========================= 22 | # Operating System Files 23 | # ========================= 24 | *.pyc 25 | .history/ 26 | .vscode/ 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 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 | This blender addon is GUI for : [texture-synthesis](https://github.com/EmbarkStudios/texture-synthesis) 2 | 3 | ![ts_ui.gif](./img/ts_ui.gif) 4 | 5 | After installing addon go to addon preferences and select directory where texture-synthesis.exe is installed. 6 | 7 | Addon panel is located in IMAGE_EDITOR -> Right Sidebar -> Texture Synthesis panel. 8 | 9 | And there is trick - if you Shift + click on 'Run texture synthesis' button then all images in folder will be converted to tileable textures (only works with 'Simple generate' synthesis method though) 10 | -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | Copyright (C) 2019 JOSECONSCO 4 | Created by JOSECONSCO (loosely based on 'dynamic enum' blender template and Simple Asset Manager) 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | ''' 20 | #You need to download https://github.com/EmbarkStudios/texture-synthesis to use this addon. 21 | 22 | #DONE: why check_file_was_generated sometimes fails to load result? 23 | #TODO: wait for inpaitn fix: https://github.com/EmbarkStudios/texture-synthesis/issues/41 24 | 25 | bl_info = { 26 | "name": "Texture Synthesis", 27 | "author": "Jose Conseco", 28 | "version": (1, 1), 29 | "blender": (2, 80, 0), 30 | "location": "Image Editor > Side Panel (N) > Texture Synthesis", 31 | "description": "Texture Synthesis", 32 | "warning": "", 33 | "wiki_url": "https://github.com/EmbarkStudios/texture-synthesis", 34 | "category": "Textures", 35 | } 36 | 37 | if "bpy" in locals(): 38 | import importlib 39 | importlib.reload(get_image_size) 40 | importlib.reload(tsynth_props) 41 | importlib.reload(utils) 42 | importlib.reload(addon_preferences) 43 | importlib.reload(tsynth_ui) 44 | importlib.reload(main_operators) 45 | else: 46 | from . import get_image_size 47 | from . import tsynth_props 48 | from . import utils 49 | from . import addon_preferences 50 | from . import tsynth_ui 51 | from . import main_operators 52 | 53 | import bpy 54 | 55 | 56 | # We can store multiple preview collections here, 57 | # however in this example we only store "main" 58 | 59 | 60 | classes = ( 61 | addon_preferences.TextureSynthPreferences, 62 | tsynth_ui.TSYNTH_PT_TextureSynthesis, 63 | tsynth_ui.VIEW_3D_UL_sel_imgs, 64 | # tsynth_ui.TSYNTH_PT_Previews, 65 | tsynth_ui.TSYNTH_OT_AddImg, 66 | tsynth_ui.TSYNTH_OT_RemoveImg, 67 | tsynth_ui.TSYNTH_OT_ClearImg, 68 | tsynth_props.SelectedImages, 69 | tsynth_props.TextSynth_Settings, 70 | main_operators.TSYNTH_OT_TextureSynthesis, 71 | main_operators.TSYNTH_OT_RefreshDir, 72 | ) 73 | 74 | def register(): 75 | for cls in classes: 76 | bpy.utils.register_class(cls) 77 | bpy.types.Scene.tsynth_params = bpy.props.PointerProperty(type=tsynth_props.TextSynth_Settings) 78 | tsynth_props.register_thumbs() 79 | 80 | 81 | 82 | def unregister(): 83 | for cls in reversed(classes): 84 | bpy.utils.unregister_class(cls) 85 | 86 | del bpy.context.scene.tsynth_params.my_previews 87 | del bpy.types.Scene.tsynth_params 88 | 89 | tsynth_props.unregister_thumbs() 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /addon_preferences.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Copyright (C) 2019 JOSECONSCO 3 | Created by JOSECONSCO (loosely based on 'dynamic enum' blender template and Simple Asset Manager) 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 | 20 | import bpy 21 | import os, platform 22 | from pathlib import Path 23 | from .tsynth_ui import TSYNTH_PT_TextureSynthesis 24 | from .utils import get_addon_preferences, addon_name_lowercase 25 | 26 | 27 | def check_file_exist(filePath): 28 | """Retuns absolute file path, and bool - file exist?""" 29 | abspathToFix = Path(bpy.path.abspath(filePath)) # crappy format like c:\\..\\...\\ddada.fbx 30 | outputPathStr = str(abspathToFix.resolve()) 31 | if abspathToFix.is_dir(): 32 | outputPathStr += '\\' 33 | return outputPathStr, os.path.isfile(outputPathStr) 34 | 35 | panels = ( 36 | TSYNTH_PT_TextureSynthesis, 37 | ) 38 | 39 | 40 | def update_panel(self, context): 41 | message = "Texture Synthesis: Updating Panel locations has failed" 42 | try: 43 | for panel in panels: 44 | if "bl_rna" in panel.__dict__: 45 | bpy.utils.unregister_class(panel) 46 | 47 | for panel in panels: 48 | panel.bl_category = get_addon_preferences().category 49 | bpy.utils.register_class(panel) 50 | 51 | except Exception as e: 52 | print("\n[{}]\n{}\n\nError:\n{}".format(__name__, message, e)) 53 | pass 54 | 55 | 56 | class TextureSynthPreferences(bpy.types.AddonPreferences): 57 | bl_idname = addon_name_lowercase() 58 | 59 | def check_ts_exist(self, context): 60 | tx_executable = "texture-synthesis.exe" if platform.system() == "Windows" else "texture-synthesis" 61 | 62 | absPath, ts_exists = check_file_exist(self.text_synth_path) 63 | self['text_synth_path'] = absPath 64 | if ts_exists and os.path.basename(absPath) == tx_executable: 65 | self.display_info = "texture-synthesis.exe found in: " + absPath 66 | else: 67 | self.display_info = "texture-synthesis.exe not found in: " + absPath 68 | 69 | text_synth_path: bpy.props.StringProperty(name="Path to texture-synthesis.exe", description="", default="", subtype='FILE_PATH', update=check_ts_exist) 70 | category: bpy.props.StringProperty(name="Tab Category", description="Choose a name for the category of the panel", default="Texture Synthesis", update=update_panel) 71 | display_info: bpy.props.StringProperty(name="Info", description="", default="") 72 | 73 | def draw(self, context): 74 | layout = self.layout 75 | col = layout.column() 76 | col.prop(self, "category", text="") 77 | col.prop(self, "text_synth_path", text="") 78 | col.label(text=self.display_info) 79 | -------------------------------------------------------------------------------- /get_image_size.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | from __future__ import print_function 4 | """ 5 | 6 | get_image_size.py 7 | ==================== 8 | 9 | :Name: get_image_size 10 | :Purpose: extract image dimensions given a file path 11 | 12 | :Author: Paulo Scardine (based on code from Emmanuel VAÏSSE) 13 | 14 | :Created: 26/09/2013 15 | :Copyright: (c) Paulo Scardine 2013 16 | :Licence: MIT 17 | 18 | """ 19 | import collections 20 | import json 21 | import os 22 | import io 23 | import struct 24 | 25 | FILE_UNKNOWN = "Sorry, don't know how to get size for this file." 26 | 27 | 28 | class UnknownImageFormat(Exception): 29 | pass 30 | 31 | 32 | types = collections.OrderedDict() 33 | BMP = types['BMP'] = 'BMP' 34 | GIF = types['GIF'] = 'GIF' 35 | ICO = types['ICO'] = 'ICO' 36 | JPEG = types['JPEG'] = 'JPEG' 37 | PNG = types['PNG'] = 'PNG' 38 | TIFF = types['TIFF'] = 'TIFF' 39 | 40 | image_fields = ['path', 'type', 'file_size', 'width', 'height'] 41 | 42 | 43 | class Image(collections.namedtuple('Image', image_fields)): 44 | 45 | def to_str_row(self): 46 | return ("%d\t%d\t%d\t%s\t%s" % ( 47 | self.width, 48 | self.height, 49 | self.file_size, 50 | self.type, 51 | self.path.replace('\t', '\\t'), 52 | )) 53 | 54 | def to_str_row_verbose(self): 55 | return ("%d\t%d\t%d\t%s\t%s\t##%s" % ( 56 | self.width, 57 | self.height, 58 | self.file_size, 59 | self.type, 60 | self.path.replace('\t', '\\t'), 61 | self)) 62 | 63 | def to_str_json(self, indent=None): 64 | return json.dumps(self._asdict(), indent=indent) 65 | 66 | 67 | def get_image_size(file_path): 68 | """ 69 | Return (width, height) for a given img file content - no external 70 | dependencies except the os and struct builtin modules 71 | """ 72 | img = get_image_metadata(file_path) 73 | return (img.width, img.height) 74 | 75 | 76 | def get_image_size_from_bytesio(input, size): 77 | """ 78 | Return (width, height) for a given img file content - no external 79 | dependencies except the os and struct builtin modules 80 | 81 | Args: 82 | input (io.IOBase): io object support read & seek 83 | size (int): size of buffer in byte 84 | """ 85 | img = get_image_metadata_from_bytesio(input, size) 86 | return (img.width, img.height) 87 | 88 | 89 | def get_image_metadata(file_path): 90 | """ 91 | Return an `Image` object for a given img file content - no external 92 | dependencies except the os and struct builtin modules 93 | 94 | Args: 95 | file_path (str): path to an image file 96 | 97 | Returns: 98 | Image: (path, type, file_size, width, height) 99 | """ 100 | size = os.path.getsize(file_path) 101 | 102 | # be explicit with open arguments - we need binary mode 103 | with io.open(file_path, "rb") as input: 104 | return get_image_metadata_from_bytesio(input, size, file_path) 105 | 106 | 107 | def get_image_metadata_from_bytesio(input, size, file_path=None): 108 | """ 109 | Return an `Image` object for a given img file content - no external 110 | dependencies except the os and struct builtin modules 111 | 112 | Args: 113 | input (io.IOBase): io object support read & seek 114 | size (int): size of buffer in byte 115 | file_path (str): path to an image file 116 | 117 | Returns: 118 | Image: (path, type, file_size, width, height) 119 | """ 120 | height = -1 121 | width = -1 122 | data = input.read(26) 123 | msg = " raised while trying to decode as JPEG." 124 | 125 | if (size >= 10) and data[:6] in (b'GIF87a', b'GIF89a'): 126 | # GIFs 127 | imgtype = GIF 128 | w, h = struct.unpack("= 24) and data.startswith(b'\211PNG\r\n\032\n') 132 | and (data[12:16] == b'IHDR')): 133 | # PNGs 134 | imgtype = PNG 135 | w, h = struct.unpack(">LL", data[16:24]) 136 | width = int(w) 137 | height = int(h) 138 | elif (size >= 16) and data.startswith(b'\211PNG\r\n\032\n'): 139 | # older PNGs 140 | imgtype = PNG 141 | w, h = struct.unpack(">LL", data[8:16]) 142 | width = int(w) 143 | height = int(h) 144 | elif (size >= 2) and data.startswith(b'\377\330'): 145 | # JPEG 146 | imgtype = JPEG 147 | input.seek(0) 148 | input.read(2) 149 | b = input.read(1) 150 | try: 151 | while (b and ord(b) != 0xDA): 152 | while (ord(b) != 0xFF): 153 | b = input.read(1) 154 | while (ord(b) == 0xFF): 155 | b = input.read(1) 156 | if (ord(b) >= 0xC0 and ord(b) <= 0xC3): 157 | input.read(3) 158 | h, w = struct.unpack(">HH", input.read(4)) 159 | break 160 | else: 161 | input.read( 162 | int(struct.unpack(">H", input.read(2))[0]) - 2) 163 | b = input.read(1) 164 | width = int(w) 165 | height = int(h) 166 | except struct.error: 167 | raise UnknownImageFormat("StructError" + msg) 168 | except ValueError: 169 | raise UnknownImageFormat("ValueError" + msg) 170 | except Exception as e: 171 | raise UnknownImageFormat(e.__class__.__name__ + msg) 172 | elif (size >= 26) and data.startswith(b'BM'): 173 | # BMP 174 | imgtype = 'BMP' 175 | headersize = struct.unpack("= 40: 181 | w, h = struct.unpack("= 8) and data[:4] in (b"II\052\000", b"MM\000\052"): 190 | # Standard TIFF, big- or little-endian 191 | # BigTIFF and other different but TIFF-like formats are not 192 | # supported currently 193 | imgtype = TIFF 194 | byteOrder = data[:2] 195 | boChar = ">" if byteOrder == "MM" else "<" 196 | # maps TIFF type id to size (in bytes) 197 | # and python format char for struct 198 | tiffTypes = { 199 | 1: (1, boChar + "B"), # BYTE 200 | 2: (1, boChar + "c"), # ASCII 201 | 3: (2, boChar + "H"), # SHORT 202 | 4: (4, boChar + "L"), # LONG 203 | 5: (8, boChar + "LL"), # RATIONAL 204 | 6: (1, boChar + "b"), # SBYTE 205 | 7: (1, boChar + "c"), # UNDEFINED 206 | 8: (2, boChar + "h"), # SSHORT 207 | 9: (4, boChar + "l"), # SLONG 208 | 10: (8, boChar + "ll"), # SRATIONAL 209 | 11: (4, boChar + "f"), # FLOAT 210 | 12: (8, boChar + "d") # DOUBLE 211 | } 212 | ifdOffset = struct.unpack(boChar + "L", data[4:8])[0] 213 | try: 214 | countSize = 2 215 | input.seek(ifdOffset) 216 | ec = input.read(countSize) 217 | ifdEntryCount = struct.unpack(boChar + "H", ec)[0] 218 | # 2 bytes: TagId + 2 bytes: type + 4 bytes: count of values + 4 219 | # bytes: value offset 220 | ifdEntrySize = 12 221 | for i in range(ifdEntryCount): 222 | entryOffset = ifdOffset + countSize + i * ifdEntrySize 223 | input.seek(entryOffset) 224 | tag = input.read(2) 225 | tag = struct.unpack(boChar + "H", tag)[0] 226 | if(tag == 256 or tag == 257): 227 | # if type indicates that value fits into 4 bytes, value 228 | # offset is not an offset but value itself 229 | type = input.read(2) 230 | type = struct.unpack(boChar + "H", type)[0] 231 | if type not in tiffTypes: 232 | raise UnknownImageFormat( 233 | "Unkown TIFF field type:" + 234 | str(type)) 235 | typeSize = tiffTypes[type][0] 236 | typeChar = tiffTypes[type][1] 237 | input.seek(entryOffset + 8) 238 | value = input.read(typeSize) 239 | value = int(struct.unpack(typeChar, value)[0]) 240 | if tag == 256: 241 | width = value 242 | else: 243 | height = value 244 | if width > -1 and height > -1: 245 | break 246 | except Exception as e: 247 | raise UnknownImageFormat(str(e)) 248 | elif size >= 2: 249 | # see http://en.wikipedia.org/wiki/ICO_(file_format) 250 | imgtype = 'ICO' 251 | input.seek(0) 252 | reserved = input.read(2) 253 | if 0 != struct.unpack(" 1: 260 | import warnings 261 | warnings.warn("ICO File contains more than one image") 262 | # http://msdn.microsoft.com/en-us/library/ms997538.aspx 263 | w = input.read(1) 264 | h = input.read(1) 265 | width = ord(w) 266 | height = ord(h) 267 | else: 268 | raise UnknownImageFormat(FILE_UNKNOWN) 269 | 270 | return Image(path=file_path, 271 | type=imgtype, 272 | file_size=size, 273 | width=width, 274 | height=height) 275 | 276 | 277 | import unittest 278 | 279 | 280 | class Test_get_image_size(unittest.TestCase): 281 | data = [{ 282 | 'path': 'lookmanodeps.png', 283 | 'width': 251, 284 | 'height': 208, 285 | 'file_size': 22228, 286 | 'type': 'PNG'}] 287 | 288 | def setUp(self): 289 | pass 290 | 291 | def test_get_image_size_from_bytesio(self): 292 | img = self.data[0] 293 | p = img['path'] 294 | with io.open(p, 'rb') as fp: 295 | b = fp.read() 296 | fp = io.BytesIO(b) 297 | sz = len(b) 298 | output = get_image_size_from_bytesio(fp, sz) 299 | self.assertTrue(output) 300 | self.assertEqual(output, 301 | (img['width'], 302 | img['height'])) 303 | 304 | def test_get_image_metadata_from_bytesio(self): 305 | img = self.data[0] 306 | p = img['path'] 307 | with io.open(p, 'rb') as fp: 308 | b = fp.read() 309 | fp = io.BytesIO(b) 310 | sz = len(b) 311 | output = get_image_metadata_from_bytesio(fp, sz) 312 | self.assertTrue(output) 313 | for field in image_fields: 314 | self.assertEqual(getattr(output, field), None if field == 'path' else img[field]) 315 | 316 | def test_get_image_metadata(self): 317 | img = self.data[0] 318 | output = get_image_metadata(img['path']) 319 | self.assertTrue(output) 320 | for field in image_fields: 321 | self.assertEqual(getattr(output, field), img[field]) 322 | 323 | def test_get_image_metadata__ENOENT_OSError(self): 324 | with self.assertRaises(OSError): 325 | get_image_metadata('THIS_DOES_NOT_EXIST') 326 | 327 | def test_get_image_metadata__not_an_image_UnknownImageFormat(self): 328 | with self.assertRaises(UnknownImageFormat): 329 | get_image_metadata('README.rst') 330 | 331 | def test_get_image_size(self): 332 | img = self.data[0] 333 | output = get_image_size(img['path']) 334 | self.assertTrue(output) 335 | self.assertEqual(output, 336 | (img['width'], 337 | img['height'])) 338 | 339 | def tearDown(self): 340 | pass 341 | 342 | 343 | def main(argv=None): 344 | """ 345 | Print image metadata fields for the given file path. 346 | 347 | Keyword Arguments: 348 | argv (list): commandline arguments (e.g. sys.argv[1:]) 349 | Returns: 350 | int: zero for OK 351 | """ 352 | import logging 353 | import optparse 354 | import sys 355 | 356 | prs = optparse.OptionParser( 357 | usage="%prog [-v|--verbose] [--json|--json-indent] []", 358 | description="Print metadata for the given image paths " 359 | "(without image library bindings).") 360 | 361 | prs.add_option('--json', 362 | dest='json', 363 | action='store_true') 364 | prs.add_option('--json-indent', 365 | dest='json_indent', 366 | action='store_true') 367 | 368 | prs.add_option('-v', '--verbose', 369 | dest='verbose', 370 | action='store_true',) 371 | prs.add_option('-q', '--quiet', 372 | dest='quiet', 373 | action='store_true',) 374 | prs.add_option('-t', '--test', 375 | dest='run_tests', 376 | action='store_true',) 377 | 378 | argv = list(argv) if argv is not None else sys.argv[1:] 379 | (opts, args) = prs.parse_args(args=argv) 380 | loglevel = logging.INFO 381 | if opts.verbose: 382 | loglevel = logging.DEBUG 383 | elif opts.quiet: 384 | loglevel = logging.ERROR 385 | logging.basicConfig(level=loglevel) 386 | log = logging.getLogger() 387 | log.debug('argv: %r', argv) 388 | log.debug('opts: %r', opts) 389 | log.debug('args: %r', args) 390 | 391 | if opts.run_tests: 392 | import sys 393 | sys.argv = [sys.argv[0]] + args 394 | import unittest 395 | return unittest.main() 396 | 397 | output_func = Image.to_str_row 398 | if opts.json_indent: 399 | import functools 400 | output_func = functools.partial(Image.to_str_json, indent=2) 401 | elif opts.json: 402 | output_func = Image.to_str_json 403 | elif opts.verbose: 404 | output_func = Image.to_str_row_verbose 405 | 406 | EX_OK = 0 407 | EX_NOT_OK = 2 408 | 409 | if len(args) < 1: 410 | prs.print_help() 411 | print('') 412 | prs.error("You must specify one or more paths to image files") 413 | 414 | errors = [] 415 | for path_arg in args: 416 | try: 417 | img = get_image_metadata(path_arg) 418 | print(output_func(img)) 419 | except KeyboardInterrupt: 420 | raise 421 | except OSError as e: 422 | log.error((path_arg, e)) 423 | errors.append((path_arg, e)) 424 | except Exception as e: 425 | log.exception(e) 426 | errors.append((path_arg, e)) 427 | pass 428 | if len(errors): 429 | import pprint 430 | print("ERRORS", file=sys.stderr) 431 | print("======", file=sys.stderr) 432 | print(pprint.pformat(errors, indent=2), file=sys.stderr) 433 | return EX_NOT_OK 434 | return EX_OK 435 | 436 | 437 | if __name__ == "__main__": 438 | import sys 439 | sys.exit(main(argv=sys.argv[1:])) 440 | -------------------------------------------------------------------------------- /img/ts_ui.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JoseConseco/texture_synthesis/5bceee82c8455ea0d81da3c0bc62a143d8cdae35/img/ts_ui.gif -------------------------------------------------------------------------------- /main_operators.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Copyright (C) 2019 JOSECONSCO 3 | Created by JOSECONSCO (loosely based on 'dynamic enum' blender template and Simple Asset Manager) 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 | 20 | import bpy 21 | from .utils import get_addon_preferences 22 | import os 23 | import time 24 | from pathlib import Path 25 | from mathutils import Vector 26 | import bpy.utils.previews 27 | from tempfile import gettempdir 28 | import functools 29 | import subprocess 30 | from . import tsynth_props 31 | 32 | LAST_EDIT_TIME = None 33 | COUNT_TIME = 0 34 | 35 | def check_file_was_generated(out_path): 36 | global LAST_EDIT_TIME, COUNT_TIME 37 | current_time = time.time() 38 | if current_time - COUNT_TIME > 30: # we waited 20 max seconds. Else quit timer 39 | COUNT_TIME = 0 40 | print(f'Waited 30 sec for {out_path} to be generated, no output detected. Time passed: {current_time - COUNT_TIME:.1} sec\nSkipping loading generated file') 41 | return 42 | if LAST_EDIT_TIME is None: # dir and or did not exist. Use isFile to check img was generated 43 | if os.path.isfile(out_path): 44 | time.sleep(.300) # just give time for file to be written? 45 | existing_imgs = bpy.data.images[:] 46 | x= bpy.data.images.load(out_path, check_existing=True) 47 | if x in existing_imgs: 48 | x.reload() 49 | LAST_EDIT_TIME = 0 50 | return 51 | else: 52 | if os.path.getmtime(out_path) > LAST_EDIT_TIME: 53 | time.sleep(.300) 54 | existing_imgs = bpy.data.images[:] 55 | x = bpy.data.images.load(out_path, check_existing=True) 56 | if x in existing_imgs: 57 | x.reload() 58 | LAST_EDIT_TIME = 0 59 | return 60 | return 1 # else wait another 0.5 sec 61 | 62 | 63 | class TSYNTH_OT_TextureSynthesis(bpy.types.Operator): 64 | ''' 65 | 1. Single example generation: 66 | ts.exe --out out/01.jpg generate imgs/1.jpg 67 | 68 | 2. Multi example generation: 69 | ts.exe --rand-init 10 --seed 211 --in-size 300x300 -o out/02.png --debug-out-dir out generate imgs/multiexample/1.jpg imgs/multiexample/2.jpg imgs/multiexample/3.jpg imgs/multiexample/4.jpg 70 | 71 | 3. Guided Synthesis 72 | ts.exe -o out/03.png generate --target-guide imgs/masks/2_target.jpg --guides imgs/masks/2_example.jpg -- imgs/2.jpg 73 | 74 | 4. Style Transfer: 75 | ts.exe --alpha 0.8 -o out/04.png transfer-style --style imgs/multiexample/4.jpg --guide imgs/tom.jpg 76 | 77 | 5. Inpaint: 78 | ts.exe --out-size 400 --inpaint imgs/masks/3_inpaint.jpg -o out/05.png generate imgs/3.jpg 79 | 80 | 6. Tiling texture: 81 | ts.exe --inpaint imgs/masks/1_tile.jpg --out-size 400 --tiling -o out/06.bmp generate imgs/1.jpg 82 | 83 | 7. Combining texture synthesis 'verbs': 84 | 85 | ''' 86 | bl_idname = "object.run_tsynthesis" 87 | bl_label = "Run Texture Synthesis" 88 | bl_description = "Synthesise texture image.\n[Shift+Click] will generate output image for all source image files in folder." 89 | bl_options = {'REGISTER'} 90 | 91 | shift_clicked = False 92 | 93 | def invoke(self, context, event): 94 | if event.shift: 95 | self.shift_clicked = True 96 | return self.execute(context) 97 | 98 | @staticmethod 99 | def get_output_path(context, out_name): 100 | tsynth_params = context.scene.tsynth_params 101 | # in_name = os.path.split(tsynth_params.input_images_dir)[1][:-4] 102 | if tsynth_params.out_method == 'TARGET_DIR': 103 | # os.path.dirname() 104 | out_path = os.path.join(os.path.realpath(tsynth_params.out_image_path), out_name) 105 | elif tsynth_params.out_method == 'OVERRIDE': 106 | out_path = os.path.join(tsynth_params.input_images_dir, out_name) 107 | elif tsynth_params.out_method == 'LOAD': 108 | tmp = os.path.join(gettempdir(), 'tsynth_params') 109 | if not os.path.isdir: 110 | os.makedirs(tmp) 111 | out_path = os.path.join(tmp, out_name) 112 | return out_path 113 | 114 | def execute(self, context): 115 | tsynth_params = context.scene.tsynth_params 116 | 117 | if tsynth_params.out_method != 'OVERRIDE' or tsynth_params.gen_type == 'multi-generate': 118 | out_name = tsynth_params.output_file_name 119 | else: # if output override and not 'multi-generate' 120 | out_name = tsynth_params.my_previews[:-3]+'png' # texture_synthesis.exe only works with png 121 | out_path = self.get_output_path(context, out_name) 122 | 123 | in_size = f"{tsynth_params.in_size_preset_x}x{tsynth_params.in_size_preset_y}" if tsynth_params.in_size_from_preset else f"{int(tsynth_params.in_size_x*tsynth_params.in_size_percent/100)}x{int(tsynth_params.in_size_y*tsynth_params.in_size_percent/100)}" 124 | out_size = f"{tsynth_params.out_size_preset_x}x{tsynth_params.out_size_preset_y}" if tsynth_params.out_size_from_preset else f"{int(tsynth_params.out_size_x*tsynth_params.out_size_percent/100)}x{int(tsynth_params.out_size_y*tsynth_params.out_size_percent/100)}" 125 | input_img_path = os.path.join(tsynth_params.input_images_dir, tsynth_params.my_previews) 126 | command = [get_addon_preferences().text_synth_path, 127 | "--out", out_path, 128 | "--out-size", out_size, 129 | "--seed", str(tsynth_params.seed), 130 | "--rand-init", str(tsynth_params.rand_init), 131 | "--k-neighs", str(tsynth_params.k_neighs), 132 | "--cauchy", str(tsynth_params.cauchy), 133 | "--backtrack-pct", str(tsynth_params.backtrack_pct/100), 134 | "--backtrack-stages", str(tsynth_params.backtrack_stages), 135 | "--in-size", in_size] 136 | if tsynth_params.tiling: 137 | command.append('--tiling') 138 | # if tsynth_params.gen_type != 'generate': 139 | if tsynth_params.gen_type == 'generate': 140 | if self.shift_clicked: 141 | pcoll = tsynth_props.preview_collections["main"] 142 | for ico_name in pcoll.keys(): 143 | out_name = ico_name[:-3]+'png' # texture_synthesis.exe only works with png 144 | out_path = self.get_output_path(context, out_name) 145 | command[2] = out_path # change output name for each generated img 146 | multi_command = command + ['generate', os.path.join(tsynth_params.input_images_dir, ico_name)] 147 | print(multi_command) 148 | subprocess.Popen(multi_command) 149 | return {'FINISHED'} 150 | 151 | command.extend(['generate', input_img_path]) 152 | 153 | elif tsynth_params.gen_type == 'multi-generate': 154 | sel_images = [os.path.join(tsynth_params.input_images_dir, img_info.image_name) for img_info in tsynth_params.selected_imgs] 155 | command.extend(['generate']+sel_images) 156 | 157 | elif tsynth_params.gen_type == 'guided-synthesis': 158 | if not tsynth_params.from_guide or not tsynth_params.from_guide.has_data: 159 | self.report({'ERROR'}, 'From guide image is empty. Canceling') 160 | return {'CANCELLED'} 161 | if not tsynth_params.to_guide or not tsynth_params.to_guide.has_data: 162 | self.report({'ERROR'}, 'To guide image is empty. Canceling') 163 | return {'CANCELLED'} 164 | tsynth_params.from_guide.filepath_raw = out_path[:-4] + '_from.png' 165 | tsynth_params.from_guide.save() 166 | tsynth_params.to_guide.filepath_raw = out_path[:-4] + '_to.png' 167 | tsynth_params.to_guide.save() 168 | command.extend(['generate', 169 | '--target-guide', tsynth_params.to_guide.filepath_raw, 170 | '--guides', tsynth_params.from_guide.filepath_raw, 171 | '--', input_img_path]) # ? or '--'+tsynth_params.input_img ? 172 | 173 | elif tsynth_params.gen_type == 'transfer-style': # TODO: 174 | if tsynth_params.to_guide is None: 175 | self.report({'ERROR'}, 'To guide image is empty!. Canceling') 176 | return {'CANCELLED'} 177 | # tsynth_params.to_guide.filepath_raw = out_path[:-4] + 'to_guide.png' #it should be loaded img.... 178 | tsynth_params.to_guide.save() 179 | command[1:1] = ['--alpha', str(tsynth_params.alpha)] # add at begning after program name 180 | command.extend(['transfer-style', 181 | '--style', input_img_path, 182 | '--guide', bpy.path.abspath(tsynth_params.to_guide.filepath_raw)]) 183 | 184 | elif tsynth_params.gen_type == 'inpaint': 185 | if not tsynth_params.to_guide or not tsynth_params.to_guide.has_data: 186 | self.report({'ERROR'}, 'To guide image is empty. Canceling') 187 | return {'CANCELLED'} 188 | tsynth_params.to_guide.filepath_raw = out_path[:-4] + '_inpaint.png' 189 | tsynth_params.to_guide.save() 190 | command.extend(['--inpaint', bpy.path.abspath(tsynth_params.to_guide.filepath_raw), 191 | 'generate', input_img_path]) 192 | 193 | print(command) 194 | subprocess.Popen(command) 195 | 196 | global LAST_EDIT_TIME, COUNT_TIME # we will wait till file is generated 197 | if os.path.isfile(out_path): 198 | LAST_EDIT_TIME = os.path.getmtime(out_path) 199 | else: 200 | LAST_EDIT_TIME = None 201 | COUNT_TIME = time.time() 202 | bpy.app.timers.register(functools.partial(check_file_was_generated, out_path), first_interval=1) 203 | return {'FINISHED'} 204 | 205 | 206 | class TSYNTH_OT_RefreshDir(bpy.types.Operator): 207 | bl_idname = "object.refresh_directory" 208 | bl_label = "Refresh Icons" 209 | bl_description = "Refresh Icons From Directory" 210 | bl_options = {"REGISTER","UNDO"} 211 | 212 | def execute(self, context): 213 | tsynth_props.FORCE_REFRESH_ICO = True 214 | return {"FINISHED"} 215 | -------------------------------------------------------------------------------- /tsynth_props.py: -------------------------------------------------------------------------------- 1 | 2 | ''' 3 | Copyright (C) 2019 JOSECONSCO 4 | Created by JOSECONSCO (loosely based on 'dynamic enum' blender template and Simple Asset Manager) 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | ''' 20 | 21 | import bpy 22 | import os 23 | from . import get_image_size 24 | from tempfile import gettempdir 25 | from . import tsynth_ui 26 | 27 | preview_collections = {} 28 | FORCE_REFRESH_ICO = False 29 | 30 | class SelectedImages(bpy.types.PropertyGroup): 31 | image_name: bpy.props.StringProperty() 32 | 33 | class TextSynth_Settings(bpy.types.PropertyGroup): 34 | def update_input_img_size(self, context): 35 | input_img_path = os.path.join(self.input_images_dir, self.my_previews) if self.gen_type != 'transfer-style' else bpy.path.abspath(self.to_guide.filepath_raw) 36 | try: 37 | width, height = get_image_size.get_image_size(input_img_path) 38 | except get_image_size.UnknownImageFormat: 39 | width, height = 400, 400 40 | print(f'Updating output size {width}x{height}') 41 | self['in_size_x'], self['in_size_y'] = width, height 42 | self['out_size_x'], self['out_size_y'] = width, height 43 | 44 | def set_abs_path(self, context): 45 | abs_p = bpy.path.abspath(self['out_image_path']) 46 | if os.path.exists(abs_p): 47 | try: 48 | f = open(abs_p+'write_test.txt', "w+") 49 | except OSError as e: 50 | print(e) 51 | self['out_image_path'] = str(gettempdir()) 52 | tsynth_ui.MESSAGE = f'No permission to write to: {abs_p}. Select different folder' 53 | else: 54 | tsynth_ui.MESSAGE = None 55 | f.close() 56 | os.remove(abs_p+'write_test.txt') 57 | self['out_image_path'] = abs_p 58 | else: 59 | self['out_image_path'] = str(gettempdir()) 60 | 61 | def limited_previews_from_directory_items(self, context): 62 | ''' Dam blender limit enum to 32 max items, with ENUM_FLAG ''' 63 | items = self.enum_previews_from_directory_items(context) 64 | # for i,item in enumerate(items): 65 | # item[4] = i**2 # has to be power of 2 for ENUM_FLAG 66 | return items[:32] 67 | 68 | def enum_previews_from_directory_items(self, context): 69 | """EnumProperty callback""" 70 | global FORCE_REFRESH_ICO 71 | enum_items = [] 72 | if context is None: 73 | return enum_items 74 | 75 | tsynth_params = context.scene.tsynth_params 76 | directory = tsynth_params.input_images_dir 77 | 78 | # Get the preview collection (defined in register func). 79 | pcoll = preview_collections["main"] 80 | 81 | if directory == pcoll.input_images_dir: 82 | if not FORCE_REFRESH_ICO: 83 | return pcoll.my_previews 84 | else: 85 | FORCE_REFRESH_ICO = False 86 | 87 | 88 | # bpy.ops.object.clear_img_synth() 89 | pcoll.clear() 90 | print("Scanning directory: %s" % directory) 91 | 92 | if directory and os.path.exists(directory): 93 | # Scan the directory for png files 94 | image_paths = [] 95 | for fn in os.listdir(directory): 96 | if fn.lower().endswith((".png", ".bmp", ".jpg")): 97 | image_paths.append(fn) 98 | 99 | for i, name in enumerate(image_paths): 100 | # generates a thumbnail preview for a file. 101 | filepath = os.path.join(directory, name) 102 | icon = pcoll.get(name) 103 | if not icon: 104 | thumb = pcoll.load(name, filepath, 'IMAGE') 105 | else: 106 | thumb = pcoll[name] 107 | short_name = name[:10]+'..' + name[-5:] if len(name) > 20 else name 108 | enum_items.append((name, short_name, "", thumb.icon_id, i)) 109 | 110 | pcoll.my_previews = enum_items 111 | pcoll.input_images_dir = directory 112 | return pcoll.my_previews 113 | 114 | def suffix_fix(self, context): 115 | file_name, ext = os.path.splitext(self.output_file_name) 116 | self['output_file_name'] = file_name+'.png' 117 | 118 | def in_dir_up(self,context): 119 | bpy.ops.object.clear_img_synth() 120 | 121 | def active_img_up(self,context): 122 | self.my_previews = self.selected_imgs[self.active_img].image_name 123 | 124 | input_images_dir: bpy.props.StringProperty(name="Dir:", description="Input images directory for texture synthesis", default="", subtype='DIR_PATH', update=in_dir_up) 125 | my_previews: bpy.props.EnumProperty(items=enum_previews_from_directory_items, name='Input Image', update=update_input_img_size) 126 | 127 | # my_previews_multi: bpy.props.EnumProperty(items=limited_previews_from_directory_items, name='Input Image', description='Max 32 icons. This is how blender rolls', options={'ENUM_FLAG'}) 128 | selected_imgs: bpy.props.CollectionProperty(type=SelectedImages) 129 | active_img: bpy.props.IntProperty(name='active_img', description='', default=1, update=active_img_up) 130 | 131 | out_image_path: bpy.props.StringProperty(name="Dir", description="", default=gettempdir(), subtype='DIR_PATH', update=set_abs_path) 132 | gen_type: bpy.props.EnumProperty(name='Synthesise', 133 | items=[('generate', 'Simple Generate', 'Generate similar-looking images from a single example'), 134 | ('multi-generate', 'Multi Generate', 'We can also provide multiple example images and the algorithm will "remix" them into a new image.'), 135 | ('guided-synthesis', 'Guided Synthesis', 'We can also guide the generation by providing a transformation "FROM"-"TO" in a form of guide maps'), 136 | ('transfer-style', 'Style Transfer', 'Texture synthesis API supports auto-generation of example guide maps, which produces a style transfer-like effect.'), 137 | ('inpaint', 'Inpaint', 'We can also fill-in missing information with inpaint. By changing the seed, we will get different version of the "fillment".'), 138 | ], default='generate') 139 | tiling: bpy.props.BoolProperty(name='Tiling', description='Enables tiling of the output image', default=True) 140 | seed: bpy.props.IntProperty(name='Seed', description='A seed value for the random generator to give pseudo-deterministic result.' 141 | ' Smaller details will be different from generation to generation due to the non-deterministic nature of multi-threading', default=1, min=1) 142 | rand_init: bpy.props.IntProperty(name='Random Initiation', description='The number of randomly initialized pixels before the main resolve loop starts', default=1, min=1) 143 | k_neighs: bpy.props.IntProperty( 144 | name='Neighbours', description='The number of neighboring pixels each pixel is aware of during the generation, larger numbers means more global structures are captured. Default=50', default=50, min=1, soft_max=100) 145 | cauchy: bpy.props.FloatProperty(name='Cauchy', description='The distribution dispersion used for picking ' 146 | 'best candidate (controls the distribution "tail flatness").Values close to 0.0 will produce "harsh" borders between generated "chunks".' 147 | ' Values closer to 1.0 will produce a smoother gradient on those borders', min=0, max=1, default=1.0) 148 | backtrack_stages: bpy.props.IntProperty(name='Backtrack Stages', description='The number of backtracking stages. Backtracking prevents "garbage" generation', default=5, min=0, max=10) 149 | backtrack_pct: bpy.props.IntProperty(name='Backtrack Percentage', description='The percentage of pixels to be backtracked during each p_stage.', default=50, min=0, max=100) 150 | output_file_name: bpy.props.StringProperty(name='Name', default='Generated.png', update=suffix_fix) 151 | 152 | to_guide: bpy.props.PointerProperty(name='To', type=bpy.types.Image, update=update_input_img_size) 153 | from_guide: bpy.props.PointerProperty(name='From', type=bpy.types.Image) 154 | 155 | alpha: bpy.props.FloatProperty( 156 | name='Guide Importance', description='Alpha parameter controls the \'importance\' of the user guide maps. If you want to preserve more details from the example map, make sure the number smaller than 1.0 (Range: 0.0 - 1.0).', default=0.8, min=0.0, soft_max=1.0) 157 | 158 | in_size_from_preset: bpy.props.BoolProperty(name='Input size from preset', description='Input size from preset', default=False) 159 | in_size_percent: bpy.props.IntProperty(name='%', description='Input size multiplier', default=100, min=0, soft_max=100, subtype='PERCENTAGE') 160 | in_size_x: bpy.props.IntProperty(name='Input x', default=400) 161 | in_size_y: bpy.props.IntProperty(name='Input y', default=400) 162 | in_size_preset_x: bpy.props.EnumProperty(name='Input', description='Input size from preset', # can be x * x , or x * y 163 | items=[('64', '64', ''), 164 | ('128', '128', ''), 165 | ('256', '256', ''), 166 | ('512', '512', ''), 167 | ('1024', '1024', '') 168 | ], default='512') 169 | in_size_preset_y: bpy.props.EnumProperty(name='Input', description='Input size from preset', # can be x * x , or x * y 170 | items=[('64', '64', ''), 171 | ('128', '128', ''), 172 | ('256', '256', ''), 173 | ('512', '512', ''), 174 | ('1024', '1024', '') 175 | ], default='512') 176 | 177 | out_size_from_preset: bpy.props.BoolProperty(name='Output', description='Output size from preset', default=False) 178 | out_size_percent: bpy.props.IntProperty(name='%', description='Output size multiplier', default=100, min=0, soft_max=100, subtype='PERCENTAGE') 179 | out_size_x: bpy.props.IntProperty(name='Output x', default=400) 180 | out_size_y: bpy.props.IntProperty(name='Output y', default=400) 181 | out_size_preset_x: bpy.props.EnumProperty(name='Output Size', description='From Preset', # can be x * x , or x * y 182 | items=[('64', '64', ''), 183 | ('128', '128', ''), 184 | ('256', '256', ''), 185 | ('512', '512', ''), 186 | ('1024', '1024', '') 187 | ], default='512') 188 | out_size_preset_y: bpy.props.EnumProperty(name='Output Size', description='From Preset', # can be x * x , or x * y 189 | items=[('64', '64', ''), 190 | ('128', '128', ''), 191 | ('256', '256', ''), 192 | ('512', '512', ''), 193 | ('1024', '1024', '') 194 | ], default='512') 195 | 196 | out_method: bpy.props.EnumProperty(name='Method', description='How / where to save generated image', 197 | items=[('TARGET_DIR', 'To Directory', 'Write to target dir'), 198 | ('OVERRIDE', 'Override input image', 'Override input image'), 199 | ('LOAD', 'To image data', 'Generate image to temp folder and load result to blender') 200 | ], default='TARGET_DIR') 201 | 202 | 203 | 204 | def register_thumbs(): 205 | # Note that preview collections returned by bpy.utils.previews 206 | # are regular Python objects - you can use them to store custom data. 207 | # 208 | # This is especially useful here, since: 209 | # - It avoids us regenerating the whole enum over and over. 210 | # - It can store enum_items' strings 211 | # (remember you have to keep those strings somewhere in py, 212 | # else they get freed and Blender references invalid memory!). 213 | 214 | pcoll = bpy.utils.previews.new() 215 | pcoll.input_images_dir = "" 216 | pcoll.my_previews = () 217 | 218 | preview_collections["main"] = pcoll 219 | 220 | 221 | def unregister_thumbs(): 222 | for pcoll in preview_collections.values(): 223 | bpy.utils.previews.remove(pcoll) 224 | preview_collections.clear() 225 | -------------------------------------------------------------------------------- /tsynth_ui.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Copyright (C) 2019 JOSECONSCO 3 | Created by JOSECONSCO (loosely based on 'dynamic enum' blender template and Simple Asset Manager) 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 | import bpy 20 | import os 21 | from . import tsynth_props 22 | 23 | MESSAGE = None 24 | 25 | class VIEW_3D_UL_sel_imgs(bpy.types.UIList): 26 | def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index): 27 | pcoll = tsynth_props.preview_collections["main"] 28 | # row = col.row(align=True) 29 | # for ico_name in tsynth_params.my_previews_multi: 30 | # layout.template_icon(pcoll[item.image_name].icon_id, scale=5.0) 31 | layout.label(text=item.image_name, icon_value=pcoll[item.image_name].icon_id) 32 | 33 | # def draw_filter(self, context, layout): 34 | # pass 35 | 36 | 37 | class TSYNTH_OT_AddImg(bpy.types.Operator): 38 | bl_idname = "object.add_img_synth" 39 | bl_label = "add_img_synth" 40 | bl_description = "Add Image" 41 | bl_options = {"REGISTER","UNDO"} 42 | 43 | name: bpy.props.StringProperty(name='name', description='', default='') 44 | 45 | def execute(self, context): 46 | tsynth_params = context.scene.tsynth_params 47 | new_img = tsynth_params.selected_imgs.add() 48 | new_img.image_name = self.name 49 | return {"FINISHED"} 50 | 51 | 52 | class TSYNTH_OT_RemoveImg(bpy.types.Operator): 53 | bl_idname = "object.remove_img_synth" 54 | bl_label = "remove_img_synth" 55 | bl_description = "Remove Image" 56 | bl_options = {"REGISTER", "UNDO"} 57 | 58 | idx: bpy.props.IntProperty(name='idx', description='', default=1, min=0, max=100, subtype='PERCENTAGE') 59 | 60 | def execute(self, context): 61 | tsynth_params = context.scene.tsynth_params 62 | if self.idx < len(tsynth_params.selected_imgs): 63 | tsynth_params.selected_imgs.remove(self.idx) 64 | # tsynth_params.active_img %= len(tsynth_params.selected_imgs) 65 | return {"FINISHED"} 66 | 67 | 68 | class TSYNTH_OT_ClearImg(bpy.types.Operator): 69 | bl_idname = "object.clear_img_synth" 70 | bl_label = "clear_img_synth" 71 | bl_description = "Clear Images" 72 | bl_options = {"REGISTER", "UNDO"} 73 | 74 | def execute(self, context): 75 | tsynth_params = context.scene.tsynth_params 76 | tsynth_params.selected_imgs.clear() 77 | return {"FINISHED"} 78 | 79 | # class TSYNTH_PT_Previews(bpy.types.Panel): 80 | # bl_idname = 'TSYNTH_PT_Previews' 81 | # bl_label = 'PanelName' 82 | # bl_space_type = 'VIEW_3D' 83 | # bl_region_type = 'UI' 84 | # bl_ui_units_x = 5 85 | 86 | # def draw(self, context): 87 | # layout = self.layout 88 | # col = layout.column(align=True) 89 | # col.scale_y = 1.2 90 | # col.prop(context.scene.tsynth_params, 'my_previews_multi', expand=True) 91 | 92 | 93 | class TSYNTH_PT_TextureSynthesis(bpy.types.Panel): 94 | bl_idname = "TSYNTH_PT_TextureSynthesis" 95 | bl_label = "Texture Synthesis" 96 | bl_space_type = 'IMAGE_EDITOR' 97 | bl_region_type = 'UI' 98 | bl_category = 'Texture Synthesis' 99 | # bl_context = 'objectmode' 100 | 101 | def draw(self, context): 102 | tsynth_params = context.scene.tsynth_params 103 | layout = self.layout.box() 104 | layout.prop(tsynth_params, 'gen_type') 105 | 106 | box = layout.box() 107 | box.label(text='Input Image(s)') 108 | col = box.column(align=True) 109 | if tsynth_params.gen_type == 'guided-synthesis': 110 | split = col.split(factor=0.14, align=True) 111 | split.label(text='From') 112 | split.template_ID(tsynth_params, "from_guide", new="image.new", open="image.open") 113 | 114 | split = col.split(factor=0.14, align=True) 115 | split.label(text='To') 116 | split.template_ID(tsynth_params, "to_guide", new="image.new", open="image.open") 117 | row = col.row(align=True) 118 | # row.prop(tsynth_params, 'from_guide') 119 | # row.prop(tsynth_params, 'to_guide') 120 | 121 | if tsynth_params.gen_type == 'transfer-style': 122 | row = col.row(align=True) 123 | row.prop(tsynth_params, 'alpha') 124 | 125 | split = col.split(factor=0.14, align=True) 126 | split.label(text='Guide') 127 | split.template_ID(tsynth_params, "to_guide", new="image.new", open="image.open") 128 | row = col.row(align=True) 129 | 130 | box.label(text='Style:') 131 | if tsynth_params.gen_type == 'inpaint': 132 | split = col.split(factor=0.14, align=True) 133 | split.label(text='Mask') 134 | split.template_ID(tsynth_params, "to_guide", new="image.new", open="image.open") 135 | 136 | col = box.column(align=True) 137 | row = col.row(align=True) 138 | row.prop(tsynth_params, "input_images_dir") 139 | row.operator("object.refresh_directory", text='', icon='FILE_REFRESH') 140 | 141 | col.template_icon_view(tsynth_params, "my_previews", show_labels=True, scale=4.0, scale_popup=5.0) 142 | row = col.row(align=True) 143 | row.prop(tsynth_params, "my_previews", text='') 144 | if tsynth_params.input_images_dir and tsynth_params.my_previews: 145 | img_open = row.operator("image.open", icon='IMPORT', text='').filepath = os.path.join(tsynth_params.input_images_dir, tsynth_params.my_previews) 146 | 147 | if tsynth_params.gen_type == 'multi-generate': # also multigenerate 148 | row = box.row() 149 | row.template_list("VIEW_3D_UL_sel_imgs", "", tsynth_params, "selected_imgs", tsynth_params, "active_img", rows=1) 150 | 151 | col = row.column(align=True) 152 | col.operator("object.add_img_synth", icon='ADD', text="").name = tsynth_params.my_previews 153 | col.operator("object.remove_img_synth", icon='REMOVE', text="").idx = tsynth_params.active_img 154 | 155 | 156 | # pcoll = tsynth_props.preview_collections["main"] 157 | # row = col.row(align=True) 158 | # for ico_name in tsynth_params.my_previews_multi: 159 | # row.template_icon(pcoll[ico_name].icon_id, scale=4.0) 160 | # # col.template_icon_view(tsynth_params, "my_previews_multi", show_labels=True) 161 | # col.prop_with_popover(tsynth_params, 'my_previews', text='', panel='TSYNTH_PT_Previews') # 'my_previews' cos it wont work with 'my_previews_multi' 162 | 163 | #* SETTINGS 164 | box = layout.box() 165 | box.label(text='Settings') 166 | box_col = box.column(align=True) 167 | box_col.prop(tsynth_params, 'tiling', icon='OUTLINER_OB_LIGHTPROBE') 168 | box_col.prop(tsynth_params, 'seed') 169 | box_col.prop(tsynth_params, 'rand_init') 170 | box_col.prop(tsynth_params, 'backtrack_pct') 171 | box_col.prop(tsynth_params, 'backtrack_stages') 172 | box_col.prop(tsynth_params, 'k_neighs') 173 | box_col.prop(tsynth_params, 'cauchy') 174 | 175 | col = box.column(align=True) 176 | row = col.row(align=True) 177 | if tsynth_params.in_size_from_preset: 178 | row.prop(tsynth_params, 'in_size_preset_x') 179 | row.prop(tsynth_params, 'in_size_preset_y', text='') 180 | else: 181 | row.label(text='Input') 182 | row.prop(tsynth_params, 'in_size_x', text='x') 183 | row.prop(tsynth_params, 'in_size_y', text='y') 184 | row.prop(tsynth_params, 'in_size_percent') 185 | row.prop(tsynth_params, 'in_size_from_preset', icon='PRESET', text='') 186 | 187 | row = col.row(align=True) 188 | if tsynth_params.out_size_from_preset: 189 | row.prop(tsynth_params, 'out_size_preset_x') 190 | row.prop(tsynth_params, 'out_size_preset_y', text='') 191 | else: 192 | row.label(text='Output') 193 | row.prop(tsynth_params, 'out_size_x', text='x') 194 | row.prop(tsynth_params, 'out_size_y', text='y') 195 | row.prop(tsynth_params, 'out_size_percent') 196 | row.prop(tsynth_params, 'out_size_from_preset', icon='PRESET', text='') 197 | 198 | #* OUTPUT 199 | box = layout.box() 200 | box.label(text='Output') 201 | col = box.column(align=True) 202 | col.prop(tsynth_params, 'out_method') 203 | 204 | if tsynth_params.out_method == 'TARGET_DIR': 205 | col.prop(tsynth_params, 'out_image_path') 206 | if MESSAGE: 207 | col.label(text=MESSAGE) 208 | if tsynth_params.out_method != 'OVERRIDE' or tsynth_params.gen_type == 'multi-generate': 209 | col.prop(tsynth_params, 'output_file_name') 210 | 211 | layout.operator("object.run_tsynthesis", icon='NODE_TEXTURE') 212 | -------------------------------------------------------------------------------- /utils.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Copyright (C) 2019 JOSECONSCO 3 | Created by JOSECONSCO (loosely based on 'dynamic enum' blender template and Simple Asset Manager) 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 | 20 | import bpy 21 | 22 | def get_addon_name(): 23 | return __package__.split(".")[0] 24 | 25 | def addon_name_lowercase(): 26 | return get_addon_name().lower() 27 | 28 | def get_addon_preferences(): 29 | return bpy.context.preferences.addons[get_addon_name()].preferences 30 | --------------------------------------------------------------------------------