Skip to content

Commit

Permalink
Split out logic to get a source color from image bytes into its own f…
Browse files Browse the repository at this point in the history
…unction to allow the code to be used seperately.

PiperOrigin-RevId: 676602878
  • Loading branch information
Material Eng authored and copybara-github committed Sep 19, 2024
1 parent 29e15b3 commit 384df9a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions typescript/utils/image_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 384df9a

Please sign in to comment.