How to use 5 digit RGB value in HTML Photoshop API color code

I am using adobe photoshop API to get layers information and want to manipulate the layers on html canvas. Everything is working just fine but the color code.

I am getting color code in 4-5 digit RBG values which is not working in HTML canvas.

Below is a part of the Adobe API output data-

"characterStyles": [
          {
            "to": 0,
            "from": 0,
            "fontName": "RupeeForadian",
            "fontSize": 45.92,
            "fontColor": {
              "rgb": {
                "red": 32768,
                "blue": 32768,
                "green": 32768
              }
            },
            "orientation": "horizontal",
            "fontAvailable": false
          },
          {
            "to": 7,
            "from": 1,
            "fontName": "FiraSans-Bold",
            "fontSize": 45.92,
            "fontColor": {
              "rgb": {
                "red": 32768,
                "blue": 32768,
                "green": 32768
              }
            },
            "orientation": "horizontal",
            "fontAvailable": false
          }
        ],

Is there any other way to use these 5 Digit RBG values in HTML/CSS ?

Thanks!

Answer

Looking at the value 32768, it’s most probably returning signed 16-bit values as the colors. You can just re-map the value from 0-32768 to 0-255:

const characterStyles = [
  {
    to: 0,
    from: 0,
    fontName: "RupeeForadian",
    fontSize: 45.92,
    fontColor: {
      rgb: {
        red: 32768,
        blue: 32768,
        green: 32768,
      },
    },
    orientation: "horizontal",
    fontAvailable: false,
  },
  {
    to: 7,
    from: 1,
    fontName: "FiraSans-Bold",
    fontSize: 45.92,
    fontColor: {
      rgb: {
        red: 15000,
        blue: 13423,
        green: 32768,
      },
    },
    orientation: "horizontal",
    fontAvailable: false,
  },
];

function rgb16ToRgb8(r, g, b) {
  return {
    r: Math.round((r / 32768) * 255),
    g: Math.round((g / 32768) * 255),
    b: Math.round((b / 32768) * 255),
  };
}

for (const style of characterStyles) {
  const { red, green, blue } = style.fontColor.rgb;
  const outputColor = rgb16ToRgb8(red, green, blue);
  const cssColor = `rgb(${outputColor.r}, ${outputColor.g}, ${outputColor.b})`
  
  console.log("In: ", style.fontColor.rgb);     
  console.log("Out: ", cssColor );
}