News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_lightforce6128

GIMP plug-in to export CPC binary data

Started by lightforce6128, 01:54, 11 April 25

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

lightforce6128

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.

lightforce6128

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?

McArti0

CPC 6128, Whole 6128 and Only 6128, with .....
NewPAL v3 for use all 128kB RAM by CRTC as VRAM
One chip drver for 512kB extRAM 6128
TYPICAL :) TV Funai 22FL532/10 with VGA-RGB-in.

eto

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.

robcfg


lightforce6128

#5
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.)

lightforce6128

#6
@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:

  • If not there, install GIMP 2.10. The plug-in was tested for versions 2.10.6 and 2.10.38. Other versions might work, too, but I cannot guarantee this. For newer Gimp 3 there were problems reported for plug-ins. The plug-in is written in Python, so Python support needs to be installed for GIMP (I think this is part of the default installation, but maybe you have to select it manually).
  • Open GIMP and check, where the plug-in folder is located. For this, have a look at 'Edit/Preferences' and there in 'Folders/Plug-ins'.
  • Also check the Python installation. For this, open 'Filters/Python-Fu/Console' and enter the command 'gimp.directory'. This should output the parent folder of the folder found above.
  • Now place the plug-in file into the plug-in folder (not into its parent). Rename the file from '*.py.txt' to '*.py'.
  • Consider to activate output of warnings and errors with 'Windows/Dockable Dialogs/Error Console'. This will help to debug problems.
  • Restart GIMP.


To create an image with GIMP, follow these steps:

  • Select 'File/New' and enter the width and height in CPC pixels (e.g. 320x200 for mode 1, but you can also create smaller tiles). Show the 'Advanced Options' and set the X/Y resolution to 32 x 32 dpi. Here, leave the color space at "RGB color". This will be changed later. For mode 0 use resolution 16 x 32 dpi, for mode 2 use 64 x 32 dpi. Alternatively load any image with 'File/Open' and use 'Image/Scale Image' to bring it to the right width/height. You should set the resolution there as well.
  • Disable 'View/Dot for Dot' to make use of the set resolution. E.g. pixels for mode 0 or mode 2 will no longer be square. For mode 1 it does not matter.
  • Now you can decide if you want to start your work with full 24 bit RGB colors or if you directly want to switch to indexed colors. You can switch forth and back with 'Image/Mode'. A helper for dithering can be found at 'Colors/Dither'. With settings of 2 or 3 (color level gaps or color levels, depends on the GIMP version) the 27 colors of the CPC are used.
  • For export, your image needs to be in indexed mode. Select 'Image/Mode/Indexed' and set 'Generate optimum palette' to 4 colors (for mode 1). Alternatively you can select a prepared palette, what is of help if several images (e.g. sprites) should use the same palette.
  • Open dialog 'Windows/Dockable Dialogs/Colormap' and check the number of colors for the image. If less colors were used than allowed (e.g. only 3 instead of 4), add arbitrary colors at the end of the map. The number of colors is used to distinguish between modes and needs to be 2, 4, or 16.
  • Finally you can export the image with 'File/Export' (or 'File/Export As'). Either name the image '*.bin' or select the file type 'Amstrad CPC' from the menu below (click on the plus sign). As soon as the image name and type has been set once, you can export again with 'File/Export' or Ctrl+E without a dialog pops up again.


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.

robcfg

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

mahlemiut

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.
- Barry Rodewald

lightforce6128

@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.

mahlemiut

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
- Barry Rodewald

lightforce6128

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 and the new registration of plug-ins. 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:
  • from : pdb.gimp_progress_init('Preparation ...', None)
  • to   : Gimp.progress_init("Preparation ...")

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.

Powered by SMFPacks Menu Editor Mod