From 384df9a9ec64c9f95c2e6ae731279411578777d0 Mon Sep 17 00:00:00 2001 From: Material Eng Date: Thu, 19 Sep 2024 16:17:23 -0700 Subject: [PATCH] Split out logic to get a source color from image bytes into its own function to allow the code to be used seperately. PiperOrigin-RevId: 676602878 --- typescript/utils/image_utils.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/typescript/utils/image_utils.ts b/typescript/utils/image_utils.ts index c02c0db6..5dbc8e79 100644 --- a/typescript/utils/image_utils.ts +++ b/typescript/utils/image_utils.ts @@ -61,6 +61,16 @@ export async function sourceColorFromImage(image: HTMLImageElement) { } }); + return sourceColorFromImageBytes(imageBytes); +} + +/** + * Get the source color from image bytes. + * + * @param imageBytes The image bytes + * @return Source color - the color most suitable for creating a UI theme + */ +export function sourceColorFromImageBytes(imageBytes: Uint8ClampedArray) { // Convert Image data to Pixel Array const pixels: number[] = []; for (let i = 0; i < imageBytes.length; i += 4) {