MCPcopy
hub / github.com/jimp-dev/jimp / intToRGBA

Function intToRGBA

packages/utils/src/index.ts:115–142  ·  view source on GitHub ↗
(i: number)

Source from the content-addressed store, hash-verified

113 * ```
114 */
115export function intToRGBA(i: number) {
116 if (typeof i !== "number") {
117 throw new Error("i must be a number");
118 }
119
120 const rgba: RGBAColor = {
121 r: 0,
122 g: 0,
123 b: 0,
124 a: 0,
125 };
126
127 rgba.r = Math.floor(i / Math.pow(256, 3));
128 rgba.g = Math.floor((i - rgba.r * Math.pow(256, 3)) / Math.pow(256, 2));
129 rgba.b = Math.floor(
130 (i - rgba.r * Math.pow(256, 3) - rgba.g * Math.pow(256, 2)) /
131 Math.pow(256, 1)
132 );
133 rgba.a = Math.floor(
134 (i -
135 rgba.r * Math.pow(256, 3) -
136 rgba.g * Math.pow(256, 2) -
137 rgba.b * Math.pow(256, 1)) /
138 Math.pow(256, 0)
139 );
140
141 return rgba;
142}
143
144/**
145 * A static helper method that converts RGBA values to a single integer value

Callers 2

autocropFunction · 0.90
scan.test.tsFile · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…