Skip to content

Commit

Permalink
🐛 Fix composite rgb for negative values
Browse files Browse the repository at this point in the history
They no longer result in white
  • Loading branch information
misode committed Nov 23, 2024
1 parent cad58b2 commit 0c1d51a
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions packages/core/src/processor/ColorInfoProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,31 +88,25 @@ export namespace Color {
}

/**
* @param value `R << 16 + G << 8 + B`. Negative values result in white.
* @param value `R << 16 + G << 8 + B`.
*/
export function fromCompositeRGB(value: number): Color {
if (value < 0) {
return fromDecRGB(1.0, 1.0, 1.0)
}
const b = value % 256
value >>>= 8
const g = value % 256
value >>>= 8
const r = value % 256
const r = value >> 16 & 0xff
const g = value >> 8 & 0xff
const b = value & 0xff
return fromIntRGB(r, g, b)
}

/**
* @param value `A << 24 + R << 16 + G << 8 + B`.
*/
export function fromCompositeARGB(value: number): Color {
value |= 0 // Cast to signed 32-bit integer

// Cast to signed 32-bit integer
value |= 0
const a = (value >>> 24) & 0xff
const r = (value >>> 16) & 0xff
const g = (value >>> 8) & 0xff
const b = value & 0xff

return fromIntRGBA(r, g, b, a)
}
}
Expand Down

0 comments on commit 0c1d51a

Please sign in to comment.