Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Feb 27, 2024
1 parent 9f4f7d6 commit 8206041
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
16 changes: 7 additions & 9 deletions src/core/conversions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ case class Xyz(x: Double, y: Double, z: Double):

object RgbHex extends Interpolator[Nothing, Option[Rgb24], Rgb24]:
def initial: Option[Rgb24] = None

def parse(state: Option[Rgb24], next: Text): Option[Rgb24] =
if next.s.length == 7 && next.s.startsWith("#") then parse(state, Text(next.s.substring(1).nn))
else if next.s.length == 6 && next.s.all: char =>
Expand All @@ -83,10 +84,8 @@ object Rgb24Opaque:
object Rgb24:
given underlying: Underlying[Rgb24, Int] = ###
given RgbColor[Rgb24] = _.asInt

def apply(red: Int, green: Int, blue: Int): Rgb24 =
((red&255) << 16) + ((green&255) << 8) + (blue&255)


def apply(red: Int, green: Int, blue: Int): Rgb24 = ((red&255) << 16) + ((green&255) << 8) + (blue&255)
def apply(packedInt: Int): Rgb24 = packedInt & 0x00ffffff

extension (color: Rgb24)
Expand All @@ -97,9 +96,10 @@ object Rgb24Opaque:
def srgb: Srgb = Srgb(red/255.0, green/255.0, blue/255.0)
def asInt: Int = color

def hex: Text = Text:
def hex: Text =
List(red, green, blue).foldLeft("#"): (acc, c) =>
acc+(c.hex.pipe { s => if s.s.length < 2 then "0"+s else s })
.tt

object Rgb32Opaque:
opaque type Rgb32 = Int
Expand All @@ -108,8 +108,7 @@ object Rgb32Opaque:
given underlying: Underlying[Rgb32, Int] = ###
given RgbColor[Rgb32] = _.srgb.rgb24.asInt

def apply(red: Int, green: Int, blue: Int): Rgb32 =
((red&1023) << 22) + ((green&4095) << 10) + (blue&1023)
def apply(red: Int, green: Int, blue: Int): Rgb32 = ((red&1023) << 22) + ((green&4095) << 10) + (blue&1023)

extension (color: Rgb32)
def red: Int = (color >> 22)&1023
Expand All @@ -124,8 +123,7 @@ object Rgb12Opaque:
given underlying: Underlying[Rgb12, Int] = ###
given RgbColor[Rgb12] = _.srgb.rgb24.asInt

def apply(red: Int, green: Int, blue: Int): Rgb12 =
((red&15) << 8) + ((green&15) << 4) + (blue&15)
def apply(red: Int, green: Int, blue: Int): Rgb12 = ((red&15) << 8) + ((green&15) << 4) + (blue&15)

extension (color: Rgb12)
def red: Int = (color >> 8)&15
Expand Down
25 changes: 5 additions & 20 deletions src/core/profile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ import language.experimental.captureChecking

object colorProfiles:
given incandescentTungsten: ColorProfile = ColorProfile(109.850, 100, 35.585, 111.144, 100, 35.2)

given oldDirectSunlightAtNoon: ColorProfile = ColorProfile(99.0927, 100, 85.313, 99.178, 100,
84.3493)

given oldDirectSunlightAtNoon: ColorProfile = ColorProfile(99.0927, 100, 85.313, 99.178, 100, 84.3493)
given oldDaylight: ColorProfile = ColorProfile(98.074, 100, 118.232, 97.285, 100, 116.145)
given iccProfilePcs: ColorProfile = ColorProfile(96.422, 100, 82.521, 96.720, 100, 81.427)
given midMorningDaylight: ColorProfile = ColorProfile(95.682, 100, 92.149, 95.799, 100, 90.926)
Expand All @@ -32,29 +29,17 @@ object colorProfiles:
given adobeRgb: ColorProfile = daylight
given northSkyDaylight: ColorProfile = ColorProfile(94.972, 100, 122.638, 94.416, 100, 120.641)
given equalEnergy: ColorProfile = ColorProfile(100, 100, 100, 100, 100, 100)

given daylightFluorescentF1: ColorProfile = ColorProfile(92.834, 100, 103.665, 94.791, 100,
103.191)

given daylightFluorescentF1: ColorProfile = ColorProfile(92.834, 100, 103.665, 94.791, 100, 103.191)
given coolFluorescent: ColorProfile = ColorProfile(99.187, 100, 67.395, 103.280, 100, 69.026)
given whiteFluorescent: ColorProfile = ColorProfile(103.754, 100, 49.861, 108.968, 100, 51.965)

given warmWhiteFluorescent: ColorProfile = ColorProfile(109.147, 100, 38.813, 114.961, 100,
40.963)

given warmWhiteFluorescent: ColorProfile = ColorProfile(109.147, 100, 38.813, 114.961, 100, 40.963)
given daylightFluorescentF5: ColorProfile = ColorProfile(90.872, 100, 98.723, 93.369, 100, 98.636)
given liteWhiteFluorescent: ColorProfile = ColorProfile(97.309, 100, 60.191, 102.148, 100, 62.074)

given daylightFluorescentF7: ColorProfile = ColorProfile(95.044, 100, 108.755, 95.792, 100,
107.687)

given daylightFluorescentF7: ColorProfile = ColorProfile(95.044, 100, 108.755, 95.792, 100, 107.687)
given d65Simulator: ColorProfile = daylightFluorescentF7
given sylvaniaF40: ColorProfile = ColorProfile(96.413, 100, 82.333, 97.115, 100, 81.135)
given d50Simulator: ColorProfile = sylvaniaF40

given coolWhiteFluorescent: ColorProfile = ColorProfile(100.365, 100, 67.868, 102.116, 100,
67.826)

given coolWhiteFluorescent: ColorProfile = ColorProfile(100.365, 100, 67.868, 102.116, 100, 67.826)
given philipsTl85: ColorProfile = ColorProfile(96.174, 100, 81.712, 99.001, 100, 83.134)
given ultralume50: ColorProfile = philipsTl85
given philipsTl84: ColorProfile = ColorProfile(100.966, 100, 64.370, 103.866, 100, 65.627)
Expand Down

0 comments on commit 8206041

Please sign in to comment.