Dyeing/Colorizing Unit Images


  • Admin

    So one of the major challenges for new map makers is creating unit sets in all the colors that they need. I decided to test some things out around being able to take a base gray scale image (think Germany's base units) and specifying a color or hue/saturation/brightness then having TripleA apply it. Interesting if folks think this could be useful?

    So here is an example of turning Germany's revised units red or more specifically applying hue=0 (red) and saturation=100 (full saturation):
    834d3ddf-b0ba-444b-84cc-48ff61610bcb-image.png

    Here is going for dark green-gray with hue=120 (green), saturation=50 (half), and brightness=-25 (darker):
    d2d86657-9252-4e8c-a9fc-c17cafb3361f-image.png

    Here is a brown-gray (close to revised UK color) with hue=40 and saturation=40:
    cab38be2-d166-43b7-b80b-060a48e64a3f-image.png

    Overview

    • Add ability for engine to colorize images. This will take a color code (only apply its hue and saturation) and an optional brightness value (apply all 3 values, increasing brightness is often not ideal so kind of an advanced use at your own risk). It also ignores any pixels that are close to black (brightness < 10%) as especially if increasing brightness these get faded and make images look less sharp.
    • Add ability to flip colorized unit images
    • Add ability to place unit images in unit folder directly which are then shared across all nations (it will first check for an image in the nation folder and if not found then check the unit folder and then check the images included with TripleA). This will allow flexibility if not all units can be shared or aren't monocolored.
    • Add new properties to map.properties:
      • A color and brightness value - apply to unit images for each nation (this will be applied to ALL units of that nation unless exempt). This will allow map makers to potentially use a single set of unit images and specify colors for each nation. Also allow users to override the default unit image color just like they can for territory colors.
      • Flip unit - flip colorized unit images for each nation (this will be applied to ALL units of that nation unless exempt)
      • A list of units exempt from transformation - this could include things like factories that are the same color for all nations or units that were already colorized by hand for each nation like AA radar or damaged battleships

    Properties Description

    # Unit transform settings (apply effects similar to colorize functions of image editing tools)
    #units.transform.color.<player> applies the given color's hue and saturation to the player's units
    #units.transform.color.Russians=00BBBB
    #units.transform.brightness.<player> allows the brightness (-100 to 100) to be adjusted when above unit color is set 
    #units.transform.brightness.Russians=25
    #units.transform.flip.<player> flips the player's units horizontally
    #units.transform.flip.Russians=true
    #units.transform.ignore provides a comma delimited list of units that aren't impacted by the above units.transform properties
    #units.transform.ignore=factory,fighter
    

    Properties Examples

    units.transform.color.Germans=FF0000
    units.transform.flip.Germans=true
    units.transform.color.Russians=00BBBB
    units.transform.brightness.Russians=25
    units.transform.color.British=00FF00
    units.transform.ignore=factory,fighter
    

    Result
    311a4a2b-7b46-404b-afad-18804f151b28-image.png

    References: https://en.wikipedia.org/wiki/Relative_luminance
    PR: https://github.com/triplea-game/triplea/pull/5192
    POS2 PR: https://github.com/triplea-maps/the_pact_of_steel/pull/33



  • That is the coolest little thing I've seen in a while!

    The options are almostly endless hehe.

    Recalls to mind the Lime Green Brits and Blue Gray Germans of revised. Or the red Japanese of the first pacific board. I think its rad. Nice work

    Ps. I think it should be the default handling for the World War II games (actually seems fine to me if it colorizes things like factories or bases in the process.) Using this method you could change the core look of the maps aesthetic via editing the Hex colors in map properties and the unit dye to capture anything you like. Do we have a way to hex color the ocean tiles? I guess that would be the last piece to making a basic map totally custom. You know how some prefer the dark blue of revised, or maybe something lighter. That along with the unit dye thing would be a total coup hehe


  • Admin

    @redrum Looks good! I'm curious how you coded it, my attempts had all the detail washed out. Regardless, this is a killer feature. On maps with many nations, the number of unit images needed is pretty astounding.


  • Moderators

    @redrum I'd pass on this feature: I don't think it is a worthwhile addition.

    I'm not a fan of this. This feels really strange, in the moment you have already coloured units that you recolour. It seems to me more like a maker friendly hack for really seriously limited or lazy mapmakers (learning how to recolourize units is really not hard), than a solid feature for properly made maps, and, of course, there are very few maps that are really 100% monocolour (for example, the AA radar for v1 onwards and the battleship damage for v6 backwards imply that this feature would not be good even for a single one of all basic games).

    It is also fairly simple making a batch recolourizing of a lot of units, by downloading add-on with GIMP, for example.

    Still just advising skipping this feature entirely, but, if this feature is really wanted, I think it should be at least sided by the ability of having units images directly in the "units" folder, so that you can provide only one image for a unit, that you would, then, recolourize for any relevant players. This feature would be actually already good on its own, for the shared units (traditinally, the "factory" images), that you could add only once for everyone, then, instead of adding the same image in each sub folder (if you look at the Americans subfolder in units assets, there are 13 units that could be moved to main folder, as they are currently just multiplicated the same in all subfolders).

    On a more advanced level, the program should be reconfigured as having those non-monocolour items, like the radar for the "aaGun_r" or the flames for the "factory_hit" getting not colourized. This could only be done by having a separate image for the "hit" (or tech) changes that you would, then, apply on the "factory" image (or whatever), only the "factory" being possibly recolourized. This would be a feature to add to the engine as an alternative option beside having just a different image for such units in such cases, then rework all TripleA assets as working that way for all cases like "battleship_hit" or "aaGun_r".

    Anyhow, this should be at least made in a way that you don't recolourize what is white, but only what is coloured, so you don't see those coloured factories and you keep consistency with the originals, but just with a different hue (this is not what you are doing there, as I see you are just colourizing the image straight on).

    Using GIMP to clarify what I mean (please download it, if you want to be sure on what I'm saying here), what you are doing looks to me like it is this function:
    Colours/Colorize: change Hue and Saturation

    What you should rather do is this function:
    Colours/Hue-Saturation: change Hue and Saturation (only)

    This is a much cleaner way of armonizing the Hue amongst images, and it will keep thing like the regular white-and-black factories the same (for everyone).

    You could also add the ability of changing the lightness, but I really thing that should be done in the units themeselves, as it would not keep white-and-black units, like the factories, the same amongst players. So, as said, I would have the ability of changing Hue and Saturation only.


  • Donators Moderators Admin

    @redrum Red this would be a very valuable tool for a map maker who may not be a superior graphics manipulator...

    The only thing I would suggest (having just a wee little bit of experience making a couple units) is that would it not be better to have all units start with a sepia finsh rather than grayscale?



  • I like this idea. Like @Cernel says, it might not be that difficult to make copies of each, it still takes time that I would rather use figuring out my map. At least early on.

    Even if all it does is make it the same as the map fill in color for a country, it will work for testing purposes, but then I can make good colors for them later on.


  • Moderators

    @Hepps said in Dyeing/Colorizing Grayscale Unit Images:

    The only thing I would suggest (having just a wee little bit of experience making a couple units) is that would it not be better to have all units start with a sepia finsh rather than grayscale?

    @redrum Correct. I overlooked you are using the Germans, that is grey, units. What I said at my previous post, about using "Hue-Saturation" changes instead of colourizing, assumes that you, instead, use actually coloured units as basis. So, don't use the Germans or the Neutral, as grey units are just pictures having no saturation at all (actually, I checked the Germans infantry in assets, and that is not actually grey, but an almost totally desaturated sky blue, that looks like grey), but use anything else, instead (it doesn't matter the starting colour). Rather than sepia (that is British, I guess), I'd use pure red (that is Russians), as that is conventionally the hue 0 on the colour scale.

    Still advising not making this at all, by the way, but looks like I'm the only one having problems with this feature.


  • Moderators

    Also, since this is going to be something for more than basic maps, maybe this can be made as a single map.properties Boolean switch that applies the hue and saturation of the ownership colours to the units too (this way, it would not only assure all units having the same hue, for the same player, but also being exactly the same as the ownership colourization).


  • Admin

    Thanks for all the feedback. I'm going to lay out the high level design and things I'm planning to include along with this feature.

    @Black_Elk I will mostly likely update some existing maps to take advantage of various parts of this feature especially any maps that truly have all monocolored units. I believe it would be possible to grab all sea zones and apply some sort of colorization but would have to think a bit about it and how it works with reliefs.

    @LaFayette I'm sure you'll see the code soon 🙂 I'm mostly doing something similar to what GIMP and other image tools do around a colorize function. It essentially finds the luminance of each pixel of the base image then sets the pixels of the new image based on the specified hue/saturation/brightness and that calculated luminance value.

    @Hepps I believe it should work fine with any base image color that is far from white/black.

    @Cernel This feature will mostly be geared towards map makers that have limited graphical ability or as a shortcut to get started not for complex/advanced map makers that already are comfortable colorizing images. And yes, this will only work well for units that are monocolor so you'll have to live with that or colorize some of the images yourself if you want a perfect map. Generally, you don't want unit images to be the exact same color as territory color so I think its better to have a separate color value for each nation for their units. I think the rest of your comments will be addressed below.

    Overview

    • Add ability for engine to colorize images. This will take a color code (only apply its hue and saturation) or take a HSB value (apply all 3 values, increasing brightness is often not ideal so kind of an advanced use at your own risk). It also ignores any pixels that are close to black (brightness < 10%) as especially if increasing brightness these get faded and make images look less sharp.
    • Add ability to place unit images in unit folder directly which are then shared across all nations (it will first check for an image in the nation folder and if not found then check the unit folder and then check the images included with TripleA). This will allow flexibility if not all units can be shared or aren't monocolored.
    • Add new properties to map.properties:
      • A color or HSB value - apply to unit images for each nation (this will be applied to ALL units of that nation unless exempt). This will allow map makers to potentially use a single set of unit images and specify colors for each nation. Also allow users to override the default unit image color just like they can for territory colors.
      • A list of units exempt from colorization - this could include things like factories that are the same color for all nations or units that were already colorized by hand for each nation like AA radar or damaged battleships

  • Moderators

    @redrum said in Dyeing/Colorizing Grayscale Unit Images:

    @Black_Elk I will mostly likely update some existing maps to take advantage of various parts of this feature especially any maps that truly have all monocolored units.

    I'm not sure what you intend to do here. Most maps with monocoloured units (if we forget about the hit and aa radar images) have units differing only for colourization and unit that are actually different. For example, in assets, there is the same battleship image, with different colourization, for all players, but each player has its own submarine image. I'm curious what you intend to do and on which maps, as the only map I can think of that have colourization only differentiation of same units ownerships is Feudal Japan (and its variants).

    I actually believe it is lame having the same units for different players, aside from units that don't need to be set apart (factories...), and all units should be actually different beyond colourization, but, of course, someone would need to work on achieving that, and I can see it would be very challenging providing different images for destroyers, cruisers and battleships, one for each player in assets, while keeping them well distinct.

    p.s.: I overlooked the off topic about having a sea zones colour. I agree to that, and I already said so in the past; it's not important, but tiles should not be required for basic display, and indeed they are not required in all cases but for sea zones (as now, otherwise, all the sea will be black like the zones' borders). The two items to add here would be the ability to assign a colour for sea zones and the ability to set any such items has having no colours (fully transparent) (I suggest doing it but having the entry and leaving it empty), the sea zones having no colour if not defined. A third item may be being able to define a colour for unassigned zones (which means mostly the borders), pure black if not defined (this one should be the only item that you cannot set transparent).


  • Admin

    @Cernel Yes, Feudal Japan is a good example where units are truly monocolor and the same minus colorization across all players so would be a good candidate for this.


  • Moderators

    @redrum Was that thing of making the new political notifications different from targets and others ever implemented in Feudal Japan? If not, is it available at the engine level? I'm thinking Feudal Japan may have a number of tweaks on hold, and we could push them all at the same time on a new version. I would also much benefit from upping the starting castles in each capital to 3, for gameplay purposes (I always edit that, when I play the game).


  • Admin

    @Cernel Do you mean this change: https://github.com/triplea-game/triplea/issues/3558

    I'm focusing first on just implementing the change in the engine and will document it in POS2. But we can discuss updating Feudal Japan if you want but probably better to create a separate thread if you do.


  • Moderators

    @redrum Yeah. Has that been added to Feudal Japan. If not, is that currently supported by the program (so we can add it to Feudal Japan).


  • Admin

    @Cernel It is supported in TripleA and I added an example to POS2: https://github.com/triplea-maps/the_pact_of_steel/pull/20/files. I don't believe Feudal Japan was ever updated to use it.


  • Admin

    Just to mention, two more really great uses for this:

    • help people that are colorblind. If the unit colors look similar, an option to adjust per-country hue so they can be visible would be excellent. Flags would help this, I'm sure using colors that look physically different would be even better.
    • building on maps that have many nations. If for example someone wanted to mod a map that has many nations, like NWO, or anything with 10 nations+, adding a new unit is a bit of a nightmare. You have to use color-picker very well to match the existing hue and it's hard to say if the new units will still look cohesive. For example, add cavalry and heavy cavalry, that is perhaps 20 units images and for each you need to do a really great match of existing hue for it not to look just hacked on.

    @Cernel I suspect the usage of this feature would be opt-in per map, or could be used as a fallback when unit images are missing. It wouldn't be the case that we'd go through all existing maps an delete units images to leave just the auto-colorized ones.


  • Moderators

    In the moment a unit that is in a units subfolder (a folder inside "units" having a player's name) can be used only by 1 player, I really feel it is making little sense to colorize it in any ways, as the unit can be, or rather should, be just already made as it is supposed to look. So, on the "fallback" matter, I think it would be better to apply any of this recolourization only on the units directly inside the units folder (shared by all players not having them in their subfolders), but possibly with the ability to define in map.properties units that must not be recolourized, but never on units inside any units subfolders.


  • Admin

    @Cernel The issue with that is it limits players being able to change unit colors (see color blind example above). So I think its better to colorize all of a nations units unless they are in the exemption list. This makes the feature more useful to existing maps.

    You can also imagine modding an existing map where you want to create say a new Axis and a new Allies player. Each side has unique images so you want to copy say all germany's units to the new Axis player then colorize them and copy all UK's units to new Allies player and colorize. This would make it so you want the units in the nations folder not in the units folder directly.


  • Moderators

    @redrum Ok, well, if by that you mean that there would be a user option to change units colours while you play, that would give some reasons about recolourizing an already coloured unit used by only one player. I was not considering that, as I assumed that was just a proposal. However, I would not advise giving players the ability to recolourize units colours, at least at the present state. Almost no one plays Feudal Japan, and even if you are playing something like Revised, that is not really good, as it would be unpolished to monocolourize multicolour images, like aa radars and damaged battleships (I know, these are rather small details, but still unpolished).


  • Moderators

    @redrum said in Dyeing/Colorizing Unit Images:

    You can also imagine modding an existing map where you want to create say a new Axis and a new Allies player. Each side has unique images so you want to copy say all germany's units to the new Axis player then colorize them and copy all UK's units to new Allies player and colorize. This would make it so you want the units in the nations folder not in the units folder directly.

    It is really not hard to learn to colourize images with a program like GIMP. Also you can find addons for GIMP that allow you to easily recolourize a whole batch of units in a folder. So, in this case, what the mapmaker needs to do is just pasting the folder it wants, then running a batch recolourization of all, or some, of the images inside it.


Log in to reply
 

27480
1435
1666
Who's Online
Visitors Today