MCPcopy Index your code
hub / github.com/jimp-dev/jimp / rgbaToInt

Function rgbaToInt

packages/utils/src/index.ts:157–195  ·  view source on GitHub ↗
(r: number, g: number, b: number, a: number)

Source from the content-addressed store, hash-verified

155 * ```
156 */
157export function rgbaToInt(r: number, g: number, b: number, a: number) {
158 if (
159 typeof r !== "number" ||
160 typeof g !== "number" ||
161 typeof b !== "number" ||
162 typeof a !== "number"
163 ) {
164 throw new Error("r, g, b and a must be numbers");
165 }
166
167 if (r < 0 || r > 255) {
168 throw new Error("r must be between 0 and 255");
169 }
170
171 if (g < 0 || g > 255) {
172 throw new Error("g must be between 0 and 255");
173 }
174
175 if (b < 0 || b > 255) {
176 throw new Error("b must be between 0 and 255");
177 }
178
179 if (a < 0 || a > 255) {
180 throw new Error("a must be between 0 and 255");
181 }
182
183 let i = r & 0xff;
184 i <<= 8;
185 i |= g & 0xff;
186 i <<= 8;
187 i |= b & 0xff;
188 i <<= 8;
189 i |= a & 0xff;
190
191 // Ensure sign is correct
192 i >>>= 0;
193
194 return i;
195}
196
197/**
198 * Compute color difference

Callers 1

scan.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…