Generative art and PSP scripting
Moderator: Kathy_9
-
dfkettle
- Posts: 13
- Joined: Sat Nov 25, 2017 11:06 pm
- System_Drive: C
- 32bit or 64bit: 64 Bit
- motherboard: H-RS880-uATX
- processor: AMD Phenom II X4 810 Processor
- ram: 16 GB
- Video Card: Integrated ATI Radeon HD 4200 graphics
- sound_card: Integrated Realtec ALC888S Audio
- Hard_Drive_Capacity: 1 TB
- Monitor/Display Make & Model: LG 19LG30 (flat screen TV)
- Corel programs: PSP, Painter Essentials, After Shot, VS
- Location: Owen Sound, ON, Canada
Generative art and PSP scripting
This isn't purely a technical issue, but I'm just curious if anyone in this forum is doing generative art in PSP using Python. I've done some work using stand-alone Python scripts and PIL (Python Imaging Library), as well as the computer language "Processing", and I'd like to try something similar using PSP scripts. Some things seem like they would be easier to do in stand-alone Python scripts (like getting and setting individual pixel values, which I don't think is even possible in the PSP environment), but other things seem easier in PSP. Is it possible to install PIL within the PSP environment and use it in PSP scripts? One problem I can see is that PSP is still using Python 2.7, but PIL has been converted to Python 3 (in the "Pillow" port). I'd probably have to find an old copy of the PIL library and copy it into the appropriate PSP folder. Also, I'm not sure how I'd convert images as they're stored in the PSP environment to images in PIL format, and vice versa. Has anyone tried this?
-
LeviFiction
- Advisor
- Posts: 6831
- Joined: Thu Oct 02, 2008 1:07 pm
- System_Drive: C
- 32bit or 64bit: 64 Bit
- motherboard: Alienware M17xR4
- processor: Intel Core i7-3630QM CPU - 2_40GH
- ram: 6 GB
- Video Card: NVIDIA GeForce GTX 660M
- sound_card: Sound Blaster Recon3Di
- Hard_Drive_Capacity: 500GB
- Corel programs: PSP: 8-2023
- Location: USA
Re: Generative art and PSP scripting
PSP does better with pure python libraries over compiled ones. I think this has something to do with the version of VC++ Corel used to compile with. But I could be wrong, I've never understood such things myself.
But it is what I blame on all of my failures at importing compiled libraries like PIL over to PSP. Very specifically it always gives me a DLL load failure message.
To get and set pixels you require PSP to use the eye-dropper tool, then getmaterial command, just to get the color, and using the paintbrush tool to set a color. But it is possible, it's just that because PSP is updating the UI on every command it's so painfully slow it's faster to do it in an external program most of the time or behind the scenes.
I once copied some code to do perlin noise inside of PSP, it's so slow generating the noise let alone setting it. I originally used the paint brush then found out just how impossible that is on a small image let alone a large one so I devised two different options.
1) I converted the data to BITMAP format and used the ctypes library to copy the image to the clipboard and used PSP's Paste function to add it as a new layer. This didn't always work. I need to review my understanding of the Windows clipboard API.
2) I saved the BITMAP data to an actual file, opened it in PSP and then did a copy and paste as new layer. This is the one I posted to the forums here. It's very ugly stupid code but it was more a proof of concept than anything else. Also all of my code is ugly. xD
If you can get PIl working with PSP It would be some awesome information and I hope you'll share.
I would also love to get Numpy and Pandas installed. I've asked Corel if they would make some ports for PSP but never got a reply.
To get and set pixels you require PSP to use the eye-dropper tool, then getmaterial command, just to get the color, and using the paintbrush tool to set a color. But it is possible, it's just that because PSP is updating the UI on every command it's so painfully slow it's faster to do it in an external program most of the time or behind the scenes.
I once copied some code to do perlin noise inside of PSP, it's so slow generating the noise let alone setting it. I originally used the paint brush then found out just how impossible that is on a small image let alone a large one so I devised two different options.
1) I converted the data to BITMAP format and used the ctypes library to copy the image to the clipboard and used PSP's Paste function to add it as a new layer. This didn't always work. I need to review my understanding of the Windows clipboard API.
2) I saved the BITMAP data to an actual file, opened it in PSP and then did a copy and paste as new layer. This is the one I posted to the forums here. It's very ugly stupid code but it was more a proof of concept than anything else. Also all of my code is ugly. xD
If you can get PIl working with PSP It would be some awesome information and I hope you'll share.
https://levifiction.wordpress.com/
-
dfkettle
- Posts: 13
- Joined: Sat Nov 25, 2017 11:06 pm
- System_Drive: C
- 32bit or 64bit: 64 Bit
- motherboard: H-RS880-uATX
- processor: AMD Phenom II X4 810 Processor
- ram: 16 GB
- Video Card: Integrated ATI Radeon HD 4200 graphics
- sound_card: Integrated Realtec ALC888S Audio
- Hard_Drive_Capacity: 1 TB
- Monitor/Display Make & Model: LG 19LG30 (flat screen TV)
- Corel programs: PSP, Painter Essentials, After Shot, VS
- Location: Owen Sound, ON, Canada
Re: Generative art and PSP scripting
Assuming I can get PIL working, any idea on how I'd convert a native PSP raster image to a PIL raster image, and vice versa? Unless I can do that, there isn't much point. I might as well do what I'm doing now, which is generating the image in a stand-alone Python/PIL script, then opening it in PSP to do further editing.
Here are some examples, if you're interested:
https://cuartooscurosite.wordpress.com/ ... ries-2017/
If it's not a trade secret, which version of VC++ does Corel use? I might be able to recompile the PIL library with the same version of VC++. But I don't think it should be necessary. There's probably some other issue causing the problem, like 32-bit vs. 64-bit libraries or something.
Thanks.
Here are some examples, if you're interested:
https://cuartooscurosite.wordpress.com/ ... ries-2017/
If it's not a trade secret, which version of VC++ does Corel use? I might be able to recompile the PIL library with the same version of VC++. But I don't think it should be necessary. There's probably some other issue causing the problem, like 32-bit vs. 64-bit libraries or something.
Thanks.
-
LeviFiction
- Advisor
- Posts: 6831
- Joined: Thu Oct 02, 2008 1:07 pm
- System_Drive: C
- 32bit or 64bit: 64 Bit
- motherboard: Alienware M17xR4
- processor: Intel Core i7-3630QM CPU - 2_40GH
- ram: 6 GB
- Video Card: NVIDIA GeForce GTX 660M
- sound_card: Sound Blaster Recon3Di
- Hard_Drive_Capacity: 500GB
- Corel programs: PSP: 8-2023
- Location: USA
Re: Generative art and PSP scripting
At the moment we have no direct access to the underlying image data in PSP (another requested feature I've been waiting on) so right now saving out the image as a format PIL can import or using the clipboard are our only methods if you want to use the current image. Otherwise, your current idea of generating in a separate script/program and importing into PSP is the only method I've found.
As I said I don't know anything about compiling. I'm only making a guess based on what I've read on stack overflow.
Here's what I've tried to get PIL installed.
1) Added a registry value pointing to the Python Libraries folder inside the PSP program files folder and run the PIL (and later pillow) installers so that they install themselves into the appropriate locations.
and when that failed
2) Downloaded a zip file version an manually added it into the site-packages folder.
Either way I get the same error.
In 64-bit it just says DLL Load Failue: can't find module specified.
In 32-bit it says DLL load failed: %1 is not a valid Win32 application.
So, I've got nothing. PSP does load TKinter just fine. All of the python basics work as expected. But my lack of understanding of more advanced things keeps me in the dark on what the problem is here.
As I said I don't know anything about compiling. I'm only making a guess based on what I've read on stack overflow.
Here's what I've tried to get PIL installed.
1) Added a registry value pointing to the Python Libraries folder inside the PSP program files folder and run the PIL (and later pillow) installers so that they install themselves into the appropriate locations.
and when that failed
2) Downloaded a zip file version an manually added it into the site-packages folder.
Either way I get the same error.
In 64-bit it just says DLL Load Failue: can't find module specified.
In 32-bit it says DLL load failed: %1 is not a valid Win32 application.
So, I've got nothing. PSP does load TKinter just fine. All of the python basics work as expected. But my lack of understanding of more advanced things keeps me in the dark on what the problem is here.
https://levifiction.wordpress.com/
-
dfkettle
- Posts: 13
- Joined: Sat Nov 25, 2017 11:06 pm
- System_Drive: C
- 32bit or 64bit: 64 Bit
- motherboard: H-RS880-uATX
- processor: AMD Phenom II X4 810 Processor
- ram: 16 GB
- Video Card: Integrated ATI Radeon HD 4200 graphics
- sound_card: Integrated Realtec ALC888S Audio
- Hard_Drive_Capacity: 1 TB
- Monitor/Display Make & Model: LG 19LG30 (flat screen TV)
- Corel programs: PSP, Painter Essentials, After Shot, VS
- Location: Owen Sound, ON, Canada
Re: Generative art and PSP scripting
I took a look at the Pillow web site, and on the Installation page (http://pillow.readthedocs.io/en/4.2.x/installation.html), I found the following notes:
Pillow < 2.0.0 supports Python versions 2.4, 2.5, 2.6, 2.7.
Pillow >= 2.0.0 < 4.0.0 supports Python versions 2.6, 2.7, 3.2, 3.3, 3.4, 3.5
Pillow >= 4.0.0 supports Python versions 2.7, 3.3, 3.4, 3.5, 3.6
So maybe that was the problem, the versions of Pillow and Python you had weren't compatible. Anyway, I'll give it a try and let you know what happens.
David.
Pillow < 2.0.0 supports Python versions 2.4, 2.5, 2.6, 2.7.
Pillow >= 2.0.0 < 4.0.0 supports Python versions 2.6, 2.7, 3.2, 3.3, 3.4, 3.5
Pillow >= 4.0.0 supports Python versions 2.7, 3.3, 3.4, 3.5, 3.6
So maybe that was the problem, the versions of Pillow and Python you had weren't compatible. Anyway, I'll give it a try and let you know what happens.
David.
-
LeviFiction
- Advisor
- Posts: 6831
- Joined: Thu Oct 02, 2008 1:07 pm
- System_Drive: C
- 32bit or 64bit: 64 Bit
- motherboard: Alienware M17xR4
- processor: Intel Core i7-3630QM CPU - 2_40GH
- ram: 6 GB
- Video Card: NVIDIA GeForce GTX 660M
- sound_card: Sound Blaster Recon3Di
- Hard_Drive_Capacity: 500GB
- Corel programs: PSP: 8-2023
- Location: USA
Re: Generative art and PSP scripting
I look forward to your results. 
According to that site all versions of pillow should support 2.7. PSP2018 has 2.7.5 as you know. I just tried it again with both Pillow 2.7 and Pillow 4.3. Both had load errors. I also made sure I was using the appropriate whl file for 32-bit and 64-bit versions.
I hope you can figure out something. Best of luck.
EDIT: I just tried an old version of PIL also meant for Python 2.7 from effbot. It will load Image but if you need to do anything that requies the _imaging.pyd file it fails. Claims it's not installed. So, at a complete loss.
EDIT 2: I installed 2.7 and all recommended files, compiled PIL and Pillow tried both, neither worked either. Also giving the same error.
EDIT 3: Okay, I have a crazy thought but I can't prove it. I'm noticing that inside the PSP program directory there are only files for Microsoft Visual C++ 7.1. Normally Python 2.7 is compiles with version 9.0 but I can't find any reference to these. Replacing the CorePython27.dll library inside PSP wih the python27.dll library that gets installed with python2.7 gave really weird errors and crashed PSP. So a straight swap isn't possible. And placing the msvc90.dll and manifest in the PSP directory didn't do anything either. So I have no way to test short of figuring out how to compile PIL for this older version of msvcr71. Which, again, i know nothing about compiling.
According to that site all versions of pillow should support 2.7. PSP2018 has 2.7.5 as you know. I just tried it again with both Pillow 2.7 and Pillow 4.3. Both had load errors. I also made sure I was using the appropriate whl file for 32-bit and 64-bit versions.
I hope you can figure out something. Best of luck.
EDIT: I just tried an old version of PIL also meant for Python 2.7 from effbot. It will load Image but if you need to do anything that requies the _imaging.pyd file it fails. Claims it's not installed. So, at a complete loss.
EDIT 2: I installed 2.7 and all recommended files, compiled PIL and Pillow tried both, neither worked either. Also giving the same error.
EDIT 3: Okay, I have a crazy thought but I can't prove it. I'm noticing that inside the PSP program directory there are only files for Microsoft Visual C++ 7.1. Normally Python 2.7 is compiles with version 9.0 but I can't find any reference to these. Replacing the CorePython27.dll library inside PSP wih the python27.dll library that gets installed with python2.7 gave really weird errors and crashed PSP. So a straight swap isn't possible. And placing the msvc90.dll and manifest in the PSP directory didn't do anything either. So I have no way to test short of figuring out how to compile PIL for this older version of msvcr71. Which, again, i know nothing about compiling.
https://levifiction.wordpress.com/
-
dfkettle
- Posts: 13
- Joined: Sat Nov 25, 2017 11:06 pm
- System_Drive: C
- 32bit or 64bit: 64 Bit
- motherboard: H-RS880-uATX
- processor: AMD Phenom II X4 810 Processor
- ram: 16 GB
- Video Card: Integrated ATI Radeon HD 4200 graphics
- sound_card: Integrated Realtec ALC888S Audio
- Hard_Drive_Capacity: 1 TB
- Monitor/Display Make & Model: LG 19LG30 (flat screen TV)
- Corel programs: PSP, Painter Essentials, After Shot, VS
- Location: Owen Sound, ON, Canada
Re: Generative art and PSP scripting
I posted a question on the Python forum (https://python-forum.io/Thread-Python-P ... t-Shop-Pro). Maybe somebody there can help us.
-
Radim
- Posts: 712
- Joined: Mon Nov 01, 2010 5:54 pm
- System_Drive: C
- 32bit or 64bit: 64 Bit
- ram: 4GB
- Monitor/Display Make & Model: 27 inch
Re: Generative art and PSP scripting
Perhaps PeStudio - https://www.winitor.com/ can be used to confirm a Visual C++ binary version.LeviFiction wrote:I look forward to your results.
According to that site all versions of pillow should support 2.7. PSP2018 has 2.7.5 as you know. I just tried it again with both Pillow 2.7 and Pillow 4.3. Both had load errors. I also made sure I was using the appropriate whl file for 32-bit and 64-bit versions.
I hope you can figure out something. Best of luck.
EDIT: I just tried an old version of PIL also meant for Python 2.7 from effbot. It will load Image but if you need to do anything that requies the _imaging.pyd file it fails. Claims it's not installed. So, at a complete loss.
EDIT 2: I installed 2.7 and all recommended files, compiled PIL and Pillow tried both, neither worked either. Also giving the same error.
EDIT 3: Okay, I have a crazy thought but I can't prove it. I'm noticing that inside the PSP program directory there are only files for Microsoft Visual C++ 7.1. Normally Python 2.7 is compiles with version 9.0 but I can't find any reference to these. Replacing the CorePython27.dll library inside PSP wih the python27.dll library that gets installed with python2.7 gave really weird errors and crashed PSP. So a straight swap isn't possible. And placing the msvc90.dll and manifest in the PSP directory didn't do anything either. So I have no way to test short of figuring out how to compile PIL for this older version of msvcr71. Which, again, i know nothing about compiling.
-
LeviFiction
- Advisor
- Posts: 6831
- Joined: Thu Oct 02, 2008 1:07 pm
- System_Drive: C
- 32bit or 64bit: 64 Bit
- motherboard: Alienware M17xR4
- processor: Intel Core i7-3630QM CPU - 2_40GH
- ram: 6 GB
- Video Card: NVIDIA GeForce GTX 660M
- sound_card: Sound Blaster Recon3Di
- Hard_Drive_Capacity: 500GB
- Corel programs: PSP: 8-2023
- Location: USA
Re: Generative art and PSP scripting
Thank you for pointing that out, Radim, very useful.
Good news, I was wrong. CorePython27.dll uses msvcr110.dll. Of course, PIL for 2.7 still uses msvcr90.dll. So you still have a miss-match of the DLL. And I still don't know if that's an actual issue.
Oh, and the tkinter.pyd files reference CorePython27.dll not python27.dll as well as msvcr110.dll instead of msvcr90.dll as well. Pillow's _imaging.pyd file references python27.dll and msvcr90.dll. So unless someone has the compiling know-how and stuff to recompile Pillow for these two references I'm not sure what to do. Or if it's even necessary.
Good news, I was wrong. CorePython27.dll uses msvcr110.dll. Of course, PIL for 2.7 still uses msvcr90.dll. So you still have a miss-match of the DLL. And I still don't know if that's an actual issue.
Oh, and the tkinter.pyd files reference CorePython27.dll not python27.dll as well as msvcr110.dll instead of msvcr90.dll as well. Pillow's _imaging.pyd file references python27.dll and msvcr90.dll. So unless someone has the compiling know-how and stuff to recompile Pillow for these two references I'm not sure what to do. Or if it's even necessary.
https://levifiction.wordpress.com/
-
LeviFiction
- Advisor
- Posts: 6831
- Joined: Thu Oct 02, 2008 1:07 pm
- System_Drive: C
- 32bit or 64bit: 64 Bit
- motherboard: Alienware M17xR4
- processor: Intel Core i7-3630QM CPU - 2_40GH
- ram: 6 GB
- Video Card: NVIDIA GeForce GTX 660M
- sound_card: Sound Blaster Recon3Di
- Hard_Drive_Capacity: 500GB
- Corel programs: PSP: 8-2023
- Location: USA
Re: Generative art and PSP scripting
Okay, dfkettle, I posted the question with what I knew on stackoverflow.
https://stackoverflow.com/questions/477 ... ike-pillow
I immediately got a suggestion, to create a symbolic link named "corepython27.dll" that points to the appropriate version of the python27.dll on my system. This requires that I have both the 64-bit and 32-bit versions of python27.dll on my computer, but that can be distributed. And it seems to work. Having never worked with PIL inside PSP I'm still not sure what the best method for working with it is, but I can verify we can use PIL in PSP now. I don't really like it as it's a lot to get it working, but so would compiling our own custom versions and distributing those. So this may be the best option.
For anyone interested the steps are as follows:
1) First you need to have the python27.dll somewhere on your computer. Some place you won't be moving it anytime soon. The usual place is in the C:\Windows folder.
I have put them into a convenient download folder for regular users, but obviously it's always best to get the DLLs from the source not from a link from some random guy int eh forums.
https://drive.google.com/open?id=1tjOgn ... ObZXpBsnl4
If you have a 32-bit computer - download the python27.dll 32-bit version and place it in C:\Windows\System32
if you have a 64-bit computer and 32-bit PSP download the python27.dll 32-bit version and place it in C:\Windows\SysWOW64\
if you have a 64-bit computer and 64-bit PSP download the python27.dll 64-bit version and place it in C:\Windows\System32
2) Next go into your version of PSP (64-bit or 32-bit or both) and rename the "CorePython27.dll" to something like "CorePython27.dll.old"
C:\Program Files (x86)\Corel\PaintSHop Pro XX\CorePython27.dll
C:\Program Files\ Corel\PaintSHop Pro XX\CorePython27.dll
3) Open up your command prompt (CMD) in administrator mode by either right-clicking on the program and select to run "As Administrator" or by selecting it and hitting CTRL + SHIFT + ENTER
4) Type the following code
So depending on your computer (32-bit or 64-bit) and which version of PSP you're trying to run PIL and the like in (32-bit or 64-bit) and where you placed the python27.dll that you downloaded your code may look like any of the following.
32-bit computer - 32-bit PSP and python27.dll
or
64-bit computer - 64-bit PSP and python27.dll
64-bit computer - 32-bit PSP and python27.dll
5) Place the library you want to use into your "C:\Program Files (x85)\Corel\Corel PaintSHop Pro 2018\Python Libraries\Lib\site-packages\" folder to make it available to PSP.
6) Write your script and run it to use the new library.
I'll also make a simple video for people when I get home tonight.
https://stackoverflow.com/questions/477 ... ike-pillow
I immediately got a suggestion, to create a symbolic link named "corepython27.dll" that points to the appropriate version of the python27.dll on my system. This requires that I have both the 64-bit and 32-bit versions of python27.dll on my computer, but that can be distributed. And it seems to work. Having never worked with PIL inside PSP I'm still not sure what the best method for working with it is, but I can verify we can use PIL in PSP now. I don't really like it as it's a lot to get it working, but so would compiling our own custom versions and distributing those. So this may be the best option.
For anyone interested the steps are as follows:
1) First you need to have the python27.dll somewhere on your computer. Some place you won't be moving it anytime soon. The usual place is in the C:\Windows folder.
I have put them into a convenient download folder for regular users, but obviously it's always best to get the DLLs from the source not from a link from some random guy int eh forums.
https://drive.google.com/open?id=1tjOgn ... ObZXpBsnl4
If you have a 32-bit computer - download the python27.dll 32-bit version and place it in C:\Windows\System32
if you have a 64-bit computer and 32-bit PSP download the python27.dll 32-bit version and place it in C:\Windows\SysWOW64\
if you have a 64-bit computer and 64-bit PSP download the python27.dll 64-bit version and place it in C:\Windows\System32
2) Next go into your version of PSP (64-bit or 32-bit or both) and rename the "CorePython27.dll" to something like "CorePython27.dll.old"
C:\Program Files (x86)\Corel\PaintSHop Pro XX\CorePython27.dll
C:\Program Files\ Corel\PaintSHop Pro XX\CorePython27.dll
3) Open up your command prompt (CMD) in administrator mode by either right-clicking on the program and select to run "As Administrator" or by selecting it and hitting CTRL + SHIFT + ENTER
4) Type the following code
Code: Select all
mklink <path_to_corepython27.dll> <path_to_python27.dll>
32-bit computer - 32-bit PSP and python27.dll
or
64-bit computer - 64-bit PSP and python27.dll
Code: Select all
mklink "C:\Program Files\Corel\Corel PaintShop Pro 2018\CorePython27.dll" "C:\Windows\System32\Python27.dll"
Code: Select all
mklink "C:\Program Files (x86)\Corel\Corel PaintShop Pro 2018\CorePython27.dll" "C:\Windows\SysWOW64\Python27.dll"
6) Write your script and run it to use the new library.
I'll also make a simple video for people when I get home tonight.
https://levifiction.wordpress.com/
