Modding Help Check a pixel's color?

Discussion in 'Starbound Modding' started by Drakarus, Jul 3, 2018.

  1. Drakarus

    Drakarus Scruffy Nerf-Herder

    I'm tinkering with color options, and while starbound has what's probably the most powerful asset tweaking system in any game ever, one thing I can't seem to figure out how to do is see what color a certain pixel of a certain image is. Like, extract the hex code for that pixel's color, to use to color other things with automatically. Like, basing the color of a character's tattoo off the complimentary color to their skin, or making a hat that's actually hair automatically match the character's hair color, or even re-coloring the morph ball to match the colors of the character's cosmetic armor.

    TL;DR:

    Is it possible to test the color of a sprite pixel and get it's hex code?
     
  2. projectmayhem

    projectmayhem Ketchup Robot

    I use paint.net program. it has a color picker, so you can open the image, pick the color and then you expand the color window and it will show RGB and Hex


    Edit
    I think i may have misunderstood the question. Are you looking for code to check a pixels color, then use that color to change things? Like have your morph tech, check to see your primary hair color, then recolor your ball to match, all via code?
     
  3. NexusTheBrony

    NexusTheBrony Parsec Taste Tester

    projectmayhem, yes
    Drakarus, I think you can match hair color using the hair color pallete, but I'm not sure on that. That is all ik of, but there's a lot of possibilities with lua
     
  4. Errors4l

    Errors4l Spaceman Spiff

    You'd probably want to use world.entityPortrait in Lua to accomplish that. I'm not going to write code because there's quite a lot to consider when doing this, but hopefully the below information will help you get started.

    If you haven't worked with Lua yet, this is going to be quite the challenge. If you have worked with Lua before, this is probably still quite a challenge.

    Obtaining the player entity id
    Depending on where your code is running there are different ways to getting the player entity id.

    interface: player.id()
    active item: activeitem.ownerEntityId()
    tech: entity.id()

    Using world.entityPortrait
    Usage of the function is world.entityPortrait(playerId, "full") and this returns a table with the different textures that build the visible player portrait (full body instead of just the head thanks to the "full" argument).

    PHP:
    portrait world.entityPortrait(entity.id(), "full")
    Parsing the portrait
    Parsing the returned table is a bit tricky, but it should definitely be possible to filter the data to find just what you're looking for (at least for vanilla items and species). Basically, you'll first want to find the correct index for the layer you're looking for and then you'll want to parse this string (texture + directives) to find the correct hex color code.

    An example string:
    PHP:
    portrait[1] = "/humanoid/human/backarm.png:idle.1?replace;FFC181=AAAAAA;D39C6C=BBBBBB;C7815B=CCCCCC"
    Finding the correct layer
    A detail to keep in mind is that the portrait is an ordered list. This means that if a layer doesn't exist it will not be present in the list and all subsequent layers will be in a different location in the list. Here's all possible layers for each vanilla species:
    Code:
      Human: backarm [backsleeve] [backitem] head emote hair body [pants] [shirt] head frontarm [frontsleeve]
      Avian: backarm [backsleeve] [backitem] head emote hair body [pants] [shirt] fluff beaks head frontarm [frontsleeve]
     Hylotl: backarm [backsleeve] [backitem] head emote hair body [pants] [shirt] head frontarm [frontsleeve]
     Glitch: backarm [backsleeve] [backitem] head emote hair body [pants] [shirt] head frontarm [frontsleeve]
    Novakid: backarm [backsleeve] [backitem] head emote hair body [pants] [shirt] brand head frontarm [frontsleeve]
       Apex: backarm [backsleeve] [backitem] head emote hair body [pants] [shirt] beard head frontarm [frontsleeve]
    Layers marked with [] are not present with no matching items equipped (backsleeve, shirt and frontsleeve go together).

    The texture of most humanoid layers will start with /humanoid, and most item textures will start with /items. This makes finding the correct layer a bit easier.

    Parsing the string

    With the correct layer found you now have a string you can parse (string.gmatch / gsub). With some code you could find the right original color code (i.e. the main skin / hair / clothing color). The original skin tone (at least for humans) is #FFC181, so in this example you'd want to parse the string to find ffc181, and then see what that color is turned into.

    When parsing the string for directives, keep in mind that:
    • the ; and = separators do the same. In most directives you'll see ?replace;aaaaaa=bbbbbb but ?replace;aaaaaa;bbbbbb or ?replace=aaaaaa=bbbbbb are also valid. This makes finding the color codes a bit trickier.
    • the hexadecimal color codes can come in 3 (rgb), 4 (rgba), 6 (rrggbb) or 8 (rrggbbaa) hexadecimal digits.
      • In the case of 3/4 characters each character is duplicated (1234 becomes 11223344, not 01020304).
    • the hexadecimal color codes are case-insensitive. Some directives are in uppercase (FF00FF) and some are in lowercase (ff00ff). I have never seen mixed usage in the same color code (ff00FF), but I have seen mixed usage in the same directives string (ff00ff=00FF00).
    • in rare occassions (custom items), directives other than ?replace are used. These modify the resulting color, but it will be hard to find the resulting color without simulating all directives.
    If anything is unclear please let me know. I know this is quite a bit to take in but I hope you can understand most of it.
     
    Last edited: Jul 4, 2018

Share This Page