Skip to content

Commit

Permalink
Split up source files
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Jun 5, 2024
1 parent 472095a commit 432cef5
Show file tree
Hide file tree
Showing 17 changed files with 591 additions and 319 deletions.
298 changes: 0 additions & 298 deletions src/core/conversions.scala

This file was deleted.

44 changes: 44 additions & 0 deletions src/core/iridescence.Cielab.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Iridescence, version [unreleased]. Copyright 2024 Jon Pretty, Propensive OÜ.
The primary distribution site is: https://propensive.com/
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied. See the License for the specific language governing permissions
and limitations under the License.
*/

package iridescence

import language.experimental.captureChecking

import scala.util.chaining.*

import anticipation.*
import hypotenuse.*

object Cielab:
given (using ColorProfile) => Cielab is RgbColor = _.srgb.rgb24.asInt

case class Cielab(l: Double, a: Double, b: Double):
def srgb(using ColorProfile): Srgb = xyz.srgb

def xyz(using profile: ColorProfile): Xyz =
def limit(v: Double): Double = if v*v*v > 0.008856 then v*v*v else (v - 16.0/116)/7.787

val y = limit((l + 16)/116)*profile.y2
val x = limit(a/500 + (l + 16)/116)*profile.x2
val z = limit((l + 16)/116 - b/200)*profile.z2

Xyz(x, y, z)

def mix(that: Cielab, ratio: Double = 0.5): Cielab =
Cielab(l*(1 - ratio) + ratio*that.l, a*(1 - ratio) + ratio*that.a, b*(1 - ratio) + ratio*that.b)

def delta(that: Cielab): Double = (hyp(F64(that.a), F64(that.b)) - hyp(F64(a), F64(b))).double
35 changes: 35 additions & 0 deletions src/core/iridescence.Cmy.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Iridescence, version [unreleased]. Copyright 2024 Jon Pretty, Propensive OÜ.
The primary distribution site is: https://propensive.com/
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied. See the License for the specific language governing permissions
and limitations under the License.
*/

package iridescence

import language.experimental.captureChecking

import scala.util.chaining.*

import anticipation.*

object Cmy:
given Cmy is RgbColor = _.srgb.rgb24.asInt

case class Cmy(cyan: Double, magenta: Double, yellow: Double):
def srgb: Srgb = Srgb((1 - cyan), (1 - magenta), (1 - yellow))

def cmyk: Cmyk =
val key = List(1, cyan, magenta, yellow).min

if key == 1 then Cmyk(0, 0, 0, 1)
else Cmyk((cyan - key)/(1 - key), (magenta - key)/(1 - key), (yellow - key)/(1 - key), key)
Loading

0 comments on commit 432cef5

Please sign in to comment.