The International Simutrans Forum

PakSets and Customization => General Resources and Tools => Tools => Topic started by: Fabio on March 08, 2012, 06:46:59 PM

Title: Simutrans Tools for GIMP ver. 0.7
Post by: Fabio on March 08, 2012, 06:46:59 PM
Hello,

I've been busy these days creating a Script-FU for GIMP.

Shades is great, but it processes PNGs, so I can only use it for post-processing the exports from GIMP.
I really missed a tool to deal with special colors directly within my XCF file. This is how this script was thought.

It offers several functions, among which:
- Select special special colors
- Remove special special colors
- Repair special special colors
- Lighten/Darken special colors
- Convert (lookup) special colors
- Isometric surfaces helper

Select special colors does as it says.
Remove special colors replaces special colors with very similar ones.
Repair special colors looks for colors similar to the special ones within a threshold (default 15%) and replaces them with the special colors.

You can chose to work on 6 different groups:
- Non-darkening greys
- Windows
- Primary player colors
- Secondary player colors
- Lights
- Transparency (E7FFFF)

You can work on current layer or recursively on all layers. There is a current limitation that it doesn't work (yet) on special colors (accidentally) resulting from combining two different layers (typically a shadow). I'll work on this next.
Special colors (accidentally) resulting from combining two different layers (typically a shadow) can be selected but not (yet?) automatically removed.




Screenshots:

(http://public.gonella.eu/simutrans/gimp/scr1.png) (http://public.gonella.eu/simutrans/gimp/scr1.png)

(http://public.gonella.eu/simutrans/gimp/scr2.png) (http://public.gonella.eu/simutrans/gimp/scr2.png)

(http://public.gonella.eu/simutrans/gimp/scr3.png) (http://public.gonella.eu/simutrans/gimp/scr3.png)

(http://public.gonella.eu/simutrans/gimp/scr4.png) (http://public.gonella.eu/simutrans/gimp/scr4.png)




Download:

simutrans-tools-for-gimp-0_7.zip (http://public.gonella.eu/simutrans/gimp/simutrans-tools-for-gimp-0_7.zip) (ver. 0.7)




How to install:

Just unzip and copy in
C:\Program Files\GIMP-2.0\share\gimp\2.0\scripts
or in
~\.gimp-2.6\scripts (e.g. C:\Documents and Settings\Administrator\.gimp-2.6\scripts)
Then start GIMP or refresh Script-Fu's.
Title: Re: Simutrans Special Colors Helper for GIMP
Post by: Carl on March 08, 2012, 07:13:33 PM
This looks great, thanks Fabio! Looking forward to trying it out!
Title: Re: Simutrans Special Colors Helper for GIMP
Post by: wlindley on March 09, 2012, 04:18:28 PM
YAY!   Excellent...

How hard would it be, for makeobj to regard png transparency, that would make painting so much easier, wouldn't it?
Title: Re: Simutrans Special Colors Helper for GIMP
Post by: Fabio on March 09, 2012, 05:23:26 PM
Thank you!

I updated the first post with the link to new release 0.2

FIX it painted all screen if the color was not found
CHG some optimization
CHG progress bar now working
Title: Re: Simutrans Special Colors Helper for GIMP
Post by: prissi on March 09, 2012, 11:16:35 PM
Transparency would not help; only if you use 100% and 0% transparency. But usually render program generate anything but that. (You can do masks in Gimp from transparency, then set thm to black/white for background generation.)
Title: Re: Simutrans Special Colors Helper for GIMP
Post by: Packer on March 12, 2012, 03:10:48 PM
Neat tool for GIMP. Might give it another go-around

I saw this thread and am curious if modifying the tool could result in something that would aid me greatly with the vehicles I'm working on (see F45 thread). I was wondering if it would it be possible to modify or tweak it to change colors from the TTD template to the Simutrans template? I've been doing it manually using a template I made; but having a tool to do it would speed up my work on pakUSA (my unofficial pet project) greatly.
Title: Re: Simutrans Tools for GIMP 0.4
Post by: Fabio on March 13, 2012, 12:06:35 PM
New release.

Renamed the project to Simutrans Tools for GIMP, as it is now intended to have more functions (you can also suggest a better name).

Added a new tool: Export with transparency. This will allow you to work on transparent images forgetting the special color E7FFFF. Just export with this tool to have a special color background added and half transparent colors removed or opaque (you can set a threshold).

Fixed an ugly bug which made the script only work on the first image open in GIMP.

Made some more changes in the code, as I'm learning Scheme better ;)




Changelog:

;; SIMUTRANS TOOLS FOR GIMP 0.4
;;
;; ver. 0.4 - 13/03/2012
;; ADD PNG Export tool
;; FIX Remove and Repair only worked on first open image (image id=1)
;;
;; ver. 0.2 - 09/03/2012
;; FIX it painted all screen if the color was not found
;; CHG some optimization
;; CHG progress bar now working
;;
;; ver. 0.1 - 08/03/2012
;; initial release





@wlindley: you can test the new tool! Just make a backup copy of your file before if you use PNG, no risk if you're using XCF format.

@packer: interesting idea, and easy to implement. I would like to make a more general purpose tool, though, than a simple TTD importer... I will think about something, but I'm open to suggestion.
Title: Re: Simutrans Tools for GIMP 0.4
Post by: Packer on March 13, 2012, 12:35:16 PM
Quote from: fabio on March 13, 2012, 12:06:35 PM
...
@packer: interesting idea, and easy to implement. I would like to make a more general purpose tool, though, than a simple TTD importer... I will think about something, but I'm open to suggestion.

Hearing that it'd be easy to implent is good. A color general converison tool would work just as well.

A tool that could allow converting any x-amount of colors to any x-amount of other colors withing a specified area would be a big help. If you look at my conversion template; I usually use 8 colors to represent the shades of a particular color. (I use it for player colors, gray, black, yellow,and special colors. I sometimes have difficulty telling some of the colors apart (hence I have a gray, black, and yellow template). As a result and on some occasion if I'm starting something from scratch; I'll use wildly contrasting colors the convert them manually afterwards.
Title: Re: Simutrans Tools for GIMP ver. 0.4
Post by: colonyan on March 14, 2012, 04:03:23 AM
Thank you very much for making this tool! I can not wait to use this tool.
Title: Simutrans Tools for GIMP ver. 0.5
Post by: Fabio on March 15, 2012, 06:26:41 PM
New release, many new features here!

Special Color Helper has now more choices.

- Convert to special colors:
as requested by Packer, it looks up special colors in a user-specified image file and replaces accordingly.
The lookup image must have one or more pair(s) of rows (or columns), the top (or left) row of the pair must contain a Simutrans special color sample, the bottom (or right) the color to be replaced (e.g. TTD's special color). The samples can have any size, but strictly all the same. The cells can be divided by a thin border, but they must be aligned. The script recognizes the orientation: default is rows, but if image height is greater than width, it assumes it's columns. See also the png in the release zip.

- Lighten / Darken:
except transparency and lights (split from windows), you can lighten or darken any set of special colors. All colors are shifted one position towards light or dark (except obviously the lightest or the darkest, respectively).

- Sample merged selection:
now you can choose to sample merged (limited to selection operation) from Layers combo. Thus you can see (but not fix automatically) which pixels will be exported as special colors, e.g. due to shadows.

Other significant changes:

- Export tool has now the option to apply a threshold to half-transparent pixels. It used to do it by default, but it slows down excessively on huge images.

- New tool to swap 2 arbitrary colors.

- New tool to set grid to tilesize and optionally resize the image to be read by makeobj.

Download link and screenshots are in the first post.




Changelog:

;; SIMUTRANS TOOLS FOR GIMP 0.5
;;
;; ver. 0.5 - 15/03/2012
;; ADD Lookup (convert) operation in Special Color Helper
;; ADD Lighten/Darken operation in Special Color Helper
;; ADD Special Color Helper sample merged select
;; ADD Set grid tool (optional resize)
;; ADD Swap colors tool
;; ADD internal stats, selection-save, selection-by-color, selection-fill
;;     and color-lookup functions
;; CHG Export flatten now optional (saves time for large images if not needed)
;; CHG code optimization
Title: Re: Simutrans Tools for GIMP ver. 0.5
Post by: Packer on March 26, 2012, 03:09:29 PM
Thanks a bunch for the color converter Fabio! This will be a great help to me in creating Pak.USA
Title: Re: Simutrans Tools for GIMP ver. 0.5
Post by: mEGa on March 27, 2012, 04:07:39 PM
Hi Fabio and community

I 'm just going to test your gimp converter tools. Thank you, it is great... And I 'll win more time now :-), specially for repairing special colors !

If you want, one very very modest contribution : a palette of simutrans color base
put it on ~/gimpxxx/palettes
Title: Re: Simutrans Tools for GIMP ver. 0.5
Post by: Fabio on March 27, 2012, 04:16:34 PM
Thank you all for your feedback.

The tools were born mainly for my convenience, but then I tried to develop it to something useful for the whole community.

My favourite tools are Remove (for all the glowing at night!), Repair (used few, but saves a lot of hassle), Color swap and Darken/lighten.

Do you have any extension requests? Maybe some could be easily added to the existing code. I wish I could make this tools as more general-purposed as possible...
Title: Re: Simutrans Tools for GIMP ver. 0.5
Post by: ӔO on May 14, 2012, 10:52:30 AM
I thought it was pretty good.
It made my life much easier modifying something to use player colours.

If I have any qualms, it's that the pallet from mEGa does not have labels as which special colour it is.
Title: Re: Simutrans Tools for GIMP ver. 0.5
Post by: mEGa on May 14, 2012, 12:31:57 PM
Quote from: ӔO on May 14, 2012, 10:52:30 AM
If I have any qualms, it's that the pallet from mEGa does not have labels as which special colour it is.

Oh yes, could you help me to create them ?
Title: Simutrans Tools for GIMP ver. 0.6
Post by: Fabio on June 19, 2012, 11:42:25 AM
Many new tools in this release 0.6.

- Multilayer tools
These tools are not only Simutrans related, but address what IMHO is a serious flaw in Gimp, which lacks a way to operate on different layers simultaneously.
Move multilayer: giving an x and y offset it moves the selection in all chosen layers. Useful when realigning a multilayer image.
Copy/Cut multilayer and Paste multilayer: copy/cuts and paste the selection in all chosen layers. Useful when you need to duplicate a tile based on several layers. Being based on layer names, pasting on a different image is restricted. These tools don't interact with normal copy/cut/paste functions.
All these tools accept a layers selection using a Regular Expressions field, so if you write ^01 you'll only copy (or move) from the layers which name starts with 01.

- Isometric surface
You can transform any front view surface into an isometric wall (south/left or east/right) or floor (south-north direction at the moment).
Useful for textures or even objects like arches and so on. It doesn't have any interpolation or antialiasing, so the result is likely to need to be manually edited. It's inspired by these scripts by froGgy factory (http://registry.gimp.org/node/25043 and http://registry.gimp.org/node/25040) but the code was written independently.

- Other updates
Switch colors can now use the current foreground/background colors instead of the two arbitrarily picked ones.
Set grid tool now supports Pak160 as well (for AEO's PakBox) and resizes all image sized layers as well as the canvas.
Menu was rearranged, but still it's not the final one.

- Future goals
The huge Special Colors Helper tool will likely be split in more specialized tools with easier UI and enhaced performance.
I'm glad to receive any extension request for this tools collection.



Download here:
simutrans-tools-for-gimp-0_6.zip (http://public.gonella.eu/simutrans/gimp/simutrans-tools-for-gimp-0_6.zip) (ver. 0.6)
or in the first post (updated).



Changelog:
;; SIMUTRANS TOOLS FOR GIMP 0.6
;; ============================================================================================
;;
;; ver. 0.6 - 27/04..19/06/2012
;; CHG Menu reordering
;; ADD New Isometric surface tool
;; CHG Set grid also for Pak160 and (optional) resizes image sized layers
;; CHG Swap colors can also use active front/back colors
;; ADD Copy/Cut and Paste multilayer tools
;; ADD Move multilayer tool
;;

Title: Re: Simutrans Tools for GIMP ver. 0.6
Post by: ӔO on June 19, 2012, 12:03:32 PM
woohoo, thanks fabio.
I'll try it out this week.
Title: Re: Simutrans Tools for GIMP ver. 0.6
Post by: kierongreen on June 19, 2012, 12:26:22 PM
Just to say this tool has been very useful over the last few weeks :)
Title: Re: Simutrans Tools for GIMP ver. 0.6
Post by: mEGa on June 19, 2012, 03:08:30 PM
I began to test. Great  ! Major distinction for isometric surface tool. It will be really useful for me.
I'll try more this week end.
Title: Re: Simutrans Tools for GIMP ver. 0.6
Post by: VS on June 21, 2012, 06:39:39 PM
Just out of curiosity, what functionality is this still missing, compared to Shades? Of course, the workflows are really different, but the end result is what I'm after...

I am contemplating just stopping development of Shades (Or rather not picking it up ever again). It was nice, and mine, but it has also come to an end, it seems.
Title: Re: Simutrans Tools for GIMP ver. 0.6
Post by: Fabio on June 21, 2012, 07:34:02 PM
VS, you're far too kind.

What this tool lacks is an important feedback I would like to receive, too.

What I know it's missing is:

1) night preview. here I would really appreciate hints how much regular colours are darkened at night. I could make a night preview of visible layers in a new temporary image.

2) highlighting special colours. It could be done as above.

3) localization. I'm not a fan of it, but it could be done, as gimp has a standard way to localize scripts and plugins.

4) a better way to deal with special colours resulting from combined semi-transparent layers. I'm pondering how to do it without too long processing time.

I would like to add also some tilecutter tools, but this is a goal far in time.
I would also like to split big images in a Makeobj friendly way (one object per file), but I'm stuck at parsing the dat file.

Latest improvement which I'll release soon is better creation of isometric floor.
Title: Re: Simutrans Tools for GIMP ver. 0.6
Post by: VS on June 21, 2012, 07:58:34 PM
Kind? More like lazy :) Anyway, apart from the (obviously unavoidable) lack of performance, it works really well...
Title: Re: Simutrans Tools for GIMP ver. 0.6
Post by: Fabio on June 21, 2012, 09:20:44 PM
Thanks! The code could still be optimized, especially all colour tools which I coded first.
Later tools work on a temporary image without undo memory and are pasted back in the main image saving a lot of memory footprint and hence time. I'll extend this method to colour tools as well.
I learnt scheme language for this project, so obviously code quality and performance improves as I code more.
Also at first I planned few tools with more functions, and UI was cumbersome, now I'm planning to split some of them in faster, more intuitive and easier to maintain tools.
Title: Re: Simutrans Tools for GIMP ver. 0.7
Post by: Fabio on July 03, 2012, 07:22:21 PM
New update: version 0.7 is out!

This updates the isometric surface tool.

You can convert any surface type (front image, floor tile, wall, normal slope) into any other, or into itself. These transformation can apply rotation or flipping.
Conversion has 3 detail levels: true to pixel (level 0) or with interpolation, which till now distorts a bit the borders.
Source image can be autodetected in a canny way, so you can only specify the destination surface.
I appreciate any feedback, in order to improve the tool.

simutrans-tools-for-gimp-0_7.zip (http://public.gonella.eu/simutrans/gimp/simutrans-tools-for-gimp-0_7.zip) (ver. 0.7)
Title: Re: Simutrans Tools for GIMP ver. 0.7
Post by: Markohs on May 21, 2013, 09:25:35 AM
Thx for writing this tool Fabio, it has been very useful to me. ;)
Title: Re: Simutrans Tools for GIMP ver. 0.7
Post by: mEGa on May 21, 2013, 05:56:48 PM
yes indeed. I use it too with many enjoy. Thank you Fabio ;-)
Title: Re: Simutrans Tools for GIMP ver. 0.7
Post by: Raiser on May 28, 2013, 08:53:32 PM
Hi Fabio, thanks for writing this tool also from my side.

Two ideas for improving the isometric surface tool: convert textures/images to half-tile slopes and convert textures to isometric roof with freely adjustable angle.

Also a possibility to shade front view textures into simutrans s/w/n/e and "top tile view" lightening would be interesting.
Title: Re: Simutrans Tools for GIMP ver. 0.7
Post by: Mariculous on October 28, 2016, 06:47:19 PM
Hi Fabio
these scripts are really useful!
I don't know if it's possible but it would be nice if this script could automatically create a Palette including all of the Simutrans special colors.