map_color discrepancies?

Place to get help with not working mods / modding interface.
owl91
Burner Inserter
Burner Inserter
Posts: 8
Joined: Tue Aug 01, 2017 10:27 pm
Contact:

map_color discrepancies?

Post by owl91 »

Could anyone help me understand why the values for "map_color" that I see in the data files at places like:

https://github.com/wube/factorio-data/b ... .lua#L1685

are different from the map colors I actually see in the game?

When I look at the map in version 0.18.31, the terrain colors I see (in screenshots, ignoring trees/buildings/etc.) are:

r 33 g 65 b 74
r 49 g 53 b 8
r 49 g 81 b 90
r 58 g 40 b 16
r 66 g 53 b 25
r 66 g 57 b 8
r 82 g 53 b 25
r 90 g 61 b 33
r 90 g 65 b 33
r 99 g 69 b 33
r 99 g 73 b 41
r 115 g 81 b 33
r 115 g 81 b 41
r 115 g 85 b 41
r 132 g 93 b 49
r 140 g 97 b 58
r 140 g 101 b 58
r 140 g 105 b 58

and I'm trying to figure out how to map these to what's in the game data.

I know for sure that where the game files have:

name "deepwater" map_color r 38 g 64 b 73

what I see in screenshots is:

r 33 g 65 b 74

Likewise for "water":

name "water" map_color r 51 g 83 b 95

I actually see:

r 49 g 81 b 90

I'm just wondering why the numbers are a little bit off of what I expect them to be?

Thanks!
owl91
Burner Inserter
Burner Inserter
Posts: 8
Joined: Tue Aug 01, 2017 10:27 pm
Contact:

Re: map_color discrepancies?

Post by owl91 »

Just to confirm, the colors I listed are the same ones you see in the screenshots at:

https://www.factorio.com/blog/post/fff-320
https://cdn.factorio.com/assets/img/blo ... rected.png

There the terrain the player is standing on is:

r 58 g 40 b 16

which I guess is pretty close to grass-4 in the game files:

map_color={r=59, g=40, b=18},

https://github.com/wube/factorio-data/b ... .lua#L2268
Bilka
Factorio Staff
Factorio Staff
Posts: 3314
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: map_color discrepancies?

Post by Bilka »

Chart uses rgb565 instead of rgb888, so only 5 bits for red and blue and 6 for green instead of using 8 bits for each. That means the color loses some "precision". I use https://github.com/Bilka2/Wiki-scripts/ ... #L184-L186 to remove those precision bits while staying in rgb888 space. (Input and output is a string of a hexadecimal number, the kind you use for html color tags).

Note: The mask is wrong, it should be 0xF8FCF8, not 0xF8FAF8. I only just noticed this, but I don't think I will be fixing it urgently, since the conversion is a bit wrong anyway. The game seems to do some rounding somewhere that I am not doing/the java program formatting the original colors is doing some rounding that the game isn't doing, example with the accumulator:

Code: Select all

>>> format((int("7a7a7a", 16) & 0xF8FCF8), '06x') # right mask
'787878'
>>> format((int("7a7a7a", 16) & 0xF8FAF8), '06x') # wrong mask
'787a78'
The actual colorpicked map color is 7b797b.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
owl91
Burner Inserter
Burner Inserter
Posts: 8
Joined: Tue Aug 01, 2017 10:27 pm
Contact:

Re: map_color discrepancies?

Post by owl91 »

Awesome! Thank you, that was it.

Looks like if I do a round trip from rgb888 to rgb565 to rgb888 with this code it recovers the colors I actually see in the game.

Code: Select all

RGB = collections.namedtuple("RGB", ["red", "green", "blue"])

def tuple_to_rgb565(val):
    return (((val.red & 0b11111000) << 8) + ((val.green & 0b11111100) << 3) +
            (val.blue >> 3))


def rgb565_to_tuple(val):
    red = ((((val >> 11) & 0x1F) * 527) + 23) >> 6
    green = ((((val >> 5) & 0x3F) * 259) + 33) >> 6
    blue = (((val & 0x1F) * 527) + 23) >> 6

    return RGB(red=red, green=green, blue=blue)


def data_to_game(rgb):
    return rgb565_to_tuple(tuple_to_rgb565(rgb))
owl91
Burner Inserter
Burner Inserter
Posts: 8
Joined: Tue Aug 01, 2017 10:27 pm
Contact:

Re: map_color discrepancies?

Post by owl91 »

Code: Select all

r 33 g 65 b 74 = deepwater (38, 64, 73)
r 49 g 53 b 8 = grass_1 (55, 53, 11)
r 49 g 81 b 90 = water (51, 83, 95)
r 58 g 40 b 16 = grass_4 (59, 40, 18)
r 66 g 53 b 25 = grass_3 (65, 52, 28)
r 66 g 57 b 8 = grass_2 (66, 57, 15)
r 82 g 53 b 25 = dirt_6 (80, 55, 31) or dirt_7 (80, 54, 28)
r 90 g 61 b 33 = dirt_5 (91, 63, 38)
r 90 g 65 b 33 = dry_dirt (94, 66, 37)
r 99 g 69 b 33 = red_desert_0 (103, 70, 32)
r 99 g 73 b 41 = dirt_4 (103, 72, 43)
r 115 g 81 b 33 = red_desert_1 (116, 81, 39)
r 115 g 81 b 41 = sand_3 (115, 83, 47)
r 115 g 85 b 41 = red_desert_2 (116, 84, 43)
r 132 g 93 b 49 = sand_2 (128, 93, 52) or red_desert_3 (128, 93, 52) or dirt_3 (133, 92, 53)
r 140 g 97 b 58 = dirt_2 (136, 96, 59)
r 140 g 101 b 58 = sand_1 (138, 103, 58)
r 140 g 105 b 58 = dirt_1 (141, 104, 60)
Bilka
Factorio Staff
Factorio Staff
Posts: 3314
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: map_color discrepancies?

Post by Bilka »

Where do the magic numbers in rgb565_to_tuple(val) come from? If I could understand those, I might adapt your code for my script.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
owl91
Burner Inserter
Burner Inserter
Posts: 8
Joined: Tue Aug 01, 2017 10:27 pm
Contact:

Re: map_color discrepancies?

Post by owl91 »

I ripped off the code from another forum, but this implementation seems a little less magical and gives identical results:

Pixel8 red = (5bitRedChannel * 255 + 15) / 31
Pixel8 green = (6bitGreenChannel * 255 + 31) / 63
Pixel8 blue = (5bitBlueChannel * 255 + 15) / 31

https://developer.apple.com/documentati ... toargb8888

Code: Select all

def rgb565_to_tuple(val):
    red = (((val >> 11) & 0b11111) * 255 + 15) / 31
    green = (((val >> 5) & 0b111111) * 255 + 31) / 63
    blue = ((val & 0b11111) * 255 + 15) / 31

    return RGB(red=red, green=green, blue=blue)
Found this link in the stack overflow discussion on converting rgb565 to rgb888 at:

https://stackoverflow.com/questions/244 ... bit-rgb888
owl91
Burner Inserter
Burner Inserter
Posts: 8
Joined: Tue Aug 01, 2017 10:27 pm
Contact:

Re: map_color discrepancies?

Post by owl91 »

FYI, the code above is incorrect for cliffs:

input: RGB(144, 119, 87)

incorrect: RGB(148, 117, 82)
correct: RGB(140, 117, 82)
Post Reply

Return to “Modding help”