CPCWiki forum

General Category => GFX + Tunes => Topic started by: lightforce6128 on 01:54, 11 April 25

Title: GIMP plug-in to export CPC binary data
Post by: lightforce6128 on 01:54, 11 April 25
It started with a small annoyance: I draw an image in GIMP, and then I somehow have to convert the image data to the CPC format and also have to transfer the palette data. I did this with a small helper program on the command line. But this process was a bit cumbersome. Then I remembered that GIMP allows to write plug-ins.   ;)

After a bit of work I created something that works for GIMP 2.10.6 and 2.10.38 on Windows. Maybe it will also work for other versions and on other systems, but one never can be sure.

To make the plug-in work, you have to copy the plug-in script once to a GIMP folder (more details in the script comments). Rename from ".txt" to ".py". Then you can export indexed images (no RGB images) with 2, 4, or 16 colors to a '.bin' file for the CPC by simply selecting "Export" with image type "Amstrad CPC". Afterwards it is simply pressing <Ctrl>+<E>. So simple compared to the former process.   :D

For convenience also two additional files are exported:
- A small viewer for Locomotive BASIC that handles color setup and line interleaving.
- An assembler snippet with the hardware color codes.

I hope, this small plug-in could be of help for the one or the other.
Title: Re: GIMP plug-in to export CPC binary data
Post by: lightforce6128 on 03:36, 11 April 25
I confused some bits.   :-[

Also I learned that AMSDOS is a bit more restrictive with filenames.

I wanted to provide an updated version, but somehow this seems not to be possible with this forum system. What is the common workflow to replace something?
Title: Re: GIMP plug-in to export CPC binary data
Post by: McArti0 on 06:16, 11 April 25
Add new with suffix V2?
Title: Re: GIMP plug-in to export CPC binary data
Post by: eto on 07:15, 11 April 25
Quote from: lightforce6128 on 03:36, 11 April 25I confused some bits.  :-[

Also I learned that AMSDOS is a bit more restrictive with filenames.

I wanted to provide an updated version, but somehow this seems not to be possible with this forum system. What is the common workflow to replace something?
New comment and add a new upload. If you can't see the upload function click on preview, then the full editor appears. 

The first is a result of vandalism where people deleted all their posts. 

The latter is an annoyance of the forum software which uses a different editor when you click on ,,quick reply". This editor lacks the upload feature.
Title: Re: GIMP plug-in to export CPC binary data
Post by: robcfg on 14:00, 11 April 25
Nice!

How should I try it?
Title: Re: GIMP plug-in to export CPC binary data
Post by: lightforce6128 on 18:10, 11 April 25
Thanks @eto , that was the hint I needed. So here is the corrected version with the bits in the right order. (The Gate Array is optimized a bit too far, the bit order of colors is not really developer friendly. I always confuse them.)
Title: Re: GIMP plug-in to export CPC binary data
Post by: lightforce6128 on 18:59, 11 April 25
@robcfg : Here is a small guide on how to use GIMP and the plug-in:


The following steps needs to be done once for installation:



To create an image with GIMP, follow these steps:



Currently three files are stored: the image itself ('*.bin'), a viewer for Locomotive BASIC that sets the palette colors and interleaves the image lines ('*.bas'), and a small assembler snippet with the hardware color codes ('*.inc'). WARNING: Overwriting is only checked for the '*.bin' file itself. The other two files will be stored without any further question. If you already have a BASIC program with the same name as the image in the same folder, take care for it before exporting.

If the modern filenames are too complex for AMSDOS, the BASIC loader already refers to a simplified image name in its first line (100). If you rename the '*.bin' file manually, take care that the BASIC loader will use the same name.


There is much more about GIMP. A guide for an older versions that does not seem to be outdated can be found in our Wiki (https://www.cpcwiki.eu/index.php/Creating_images_for_the_Amstrad).
Title: Re: GIMP plug-in to export CPC binary data
Post by: robcfg on 22:02, 11 April 25
Ok, I managed to get it working in GIMP 2.10.36 on MacOS, but you may want to add a couple of things to the instructions.

1) You need to chmod +x the .py file as otherwise it won't be allowed to run.
2) On the Settings.../Folders/Plug-ins panel, there can be any number of paths, and you can add a new one if you fancy it. Now, the first path in the list (/Users/robcfg/Library/Application Support/GIMP/2.10/plug-ins in my case) didn't actually exist, so when I copied the script, it renamed it to "plug-ins" with no error message whatsoever. That is something the user needs to check in advance, or add their own folder.

After that and a bit of palette mangling, I managed to export it  ;D
Title: Re: GIMP plug-in to export CPC binary data
Post by: mahlemiut on 23:31, 11 April 25
Doesn't work in GIMP 3.0 unfortunately.  Looks like plugins were completely overhauled for 3.0, this plugin would likely need a complete re-write to work there.
Title: Re: GIMP plug-in to export CPC binary data
Post by: lightforce6128 on 00:51, 12 April 25
@robcfg : Good to hear that it works at least on two computers.  :)  Because there might be ongoing development, I decided to set up a Git repository. In the long run this is simpler to manage than to post source code files in a forum. I will add your findings to the description. And I will also export the image size to the assembler file. There it will also be needed, not only in the BASIC viewer.


@mahlemiut : I suspected that there would be problems, especially because of this "advertisement" on the Gimp download page:


QuoteUpdated on 2025-03-25: GIMP 3.0.2 installer revision 1

Fixes impossibility to run Python plug-ins (#13170)

Despite the message itself, its prominent placement gives me the thought that this feature is not stable at the moment. This looks like one should wait at least for version 3.1 to get something reliable that will not change on every other week. If Python scripts work on Gimp 3, then it would be a good idea to port the plug-in, because maybe one feature is available then that should in theory already be available in Gimp 2: Opening a dialog and ask the user for export options, like if the additional files should be exported or if full images should already use interleaved lines. In Gimp 2 I did not get it to work, although the source code somehow seems to handle this.
Title: Re: GIMP plug-in to export CPC binary data
Post by: mahlemiut on 02:05, 12 April 25
Ah, I have managed to get it to at least attempt to run the script.  It returns the following:
Traceback (most recent call last):
  File "/home/bsr/.config/GIMP/3.0/plug-ins/file_cpp_bin_save/file_cpp_bin_save.py", line 81, in <module>
    from gimpfu import *  # gimpfu.register, gimpfu.PF_*
ImportError: No module named gimpfu
Title: Re: GIMP plug-in to export CPC binary data
Post by: lightforce6128 on 07:13, 12 April 25
As far as I remember, the organization in modules has changed (different names, different number). Also, the older procedure-style interface was replaced with an object-oriented one.

Another new file export plug-in of Gimp 3 shows new imports (https://gitlab.gnome.org/GNOME/gimp/-/blob/GIMP_3_0_2/plug-ins/python/file-openraster.py?ref_type=tags#L16) and the new registration of plug-ins (https://gitlab.gnome.org/GNOME/gimp/-/blob/GIMP_3_0_2/plug-ins/python/file-openraster.py?ref_type=tags#L466). There are small changes in all Gimp-related function calls. They look similar, so porting the plug-in to Gimp 3 should be possible - at least in theory.

For example, updating the status bar has changed:

But from my experience now is not the right time for porting the plug-in. Gimp 3 doesn't seem stable to me yet. Version 3.1 might be better.
Title: Re: GIMP plug-in to export CPC binary data
Post by: lightforce6128 on 17:42, 30 May 25
After a brief digression on the topic of PSG control, I've gotten around to revising the Gimp plug-in and incorporating the changes discussed above. It's available at https://codeberg.org/lightforce6128/gimp-file-cpp-bin-save (https://codeberg.org/lightforce6128/gimp-file-cpp-bin-save). I've been considering adding this to the relevant page of our wiki, too.

I also found a good tutorial for updating plug-ins from version 2.x to version 3.x. I'll check that out next... unless something else comes up  ;D
Powered by SMFPacks Menu Editor Mod