Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RGBA utility #38

Open
SebHex opened this issue Apr 19, 2022 · 1 comment
Open

Add RGBA utility #38

SebHex opened this issue Apr 19, 2022 · 1 comment
Labels
enhancement New feature or request quick (Label used internally)

Comments

@SebHex
Copy link

SebHex commented Apr 19, 2022

We have hex conversion utilities (hexFromArgb and argbFromHex) already, RGBA conversion utilites would also be a nice quality of life addition!

I'd offer a pull request, but #11 (comment)

TypeScript implementation:

import * as colorUtils from './color_utils';

interface Rgba {
  r: number
  g: number
  b: number
  a: number
}

/**
 * @param argb ARGB representation of a color.
 * @return RGBA representation of a color.
 */
const rbgaFromArgb = (argb: number): Rgba => {
  const r = colorUtils.redFromArgb(argb)
  const g = colorUtils.greenFromArgb(argb)
  const b = colorUtils.blueFromArgb(argb)
  const a = colorUtils.alphaFromArgb(argb)

  return { r, g, b, a }
}

/**
 * @param rgba RGBA representation of a color.
 * @returns ARGB representation of a color.
 */
const argbFromRgba = (rgba: Rgba): number => {
  return (rgba.a << 24) | (rgba.r << 16) | (rgba.g << 8) | rgba.b
}
@guidezpl guidezpl added the enhancement New feature or request label Feb 9, 2023
@rodydavis
Copy link
Member

Adding this internally and should be on a future update!

@pennzht pennzht added the quick (Label used internally) label Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request quick (Label used internally)
Projects
None yet
Development

No branches or pull requests

4 participants