Skip to content

Commit

Permalink
Merge pull request #168 from hanubeki/modify-hct
Browse files Browse the repository at this point in the history
Change color modification to HCT-based
  • Loading branch information
Mahmud0808 authored Jan 1, 2025
2 parents 2c8329f + 22a1632 commit 93c7882
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ object ColorModifiers {
}
}
} else {
if (backgroundSaturation && style != MONET.MONOCHROMATIC) {
if (backgroundSaturation && style != MONET.MONOCHROMATIC && style != MONET.RAINBOW) {
// Set background saturation
palette.replaceAll { o: Int ->
ColorUtil.modifySaturation(
Expand Down
20 changes: 10 additions & 10 deletions app/src/main/java/com/drdisagree/colorblendr/utils/ColorUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.drdisagree.colorblendr.config.RPrefs.getInt
import com.drdisagree.colorblendr.utils.ColorSchemeUtil.MONET
import com.drdisagree.colorblendr.utils.ColorSchemeUtil.generateColorPalette
import com.drdisagree.colorblendr.utils.cam.Cam
import com.drdisagree.colorblendr.utils.cam.CamUtils
import com.google.gson.reflect.TypeToken
import java.util.concurrent.atomic.AtomicInteger
import kotlin.math.min
Expand Down Expand Up @@ -143,16 +144,17 @@ object ColorUtil {
fun modifySaturation(color: Int, saturation: Int): Int {
val saturationFloat = (saturation - 100) / 100f

val hsl = FloatArray(3)
ColorUtils.colorToHSL(color, hsl)
val cam = Cam.fromInt(color)
var chroma = cam.chroma
val lstar = CamUtils.lstarFromInt(color)

if (saturationFloat > 0) {
hsl[1] += ((1 - hsl[1]) * saturationFloat)
chroma = 100f * (chroma / (chroma * saturationFloat + 100f) + saturationFloat)
} else if (saturationFloat < 0) {
hsl[1] += (hsl[1] * saturationFloat)
chroma += (chroma * saturationFloat)
}

return ColorUtils.HSLToColor(hsl)
return Cam.getInt(cam.hue, chroma, lstar)
}

fun modifyLightness(color: Int, lightness: Int, idx: Int): Int {
Expand All @@ -173,12 +175,10 @@ object ColorUtil {
}
}

val hsl = FloatArray(3)
ColorUtils.colorToHSL(color, hsl)

hsl[2] = shade + lightnessFloat
val cam = Cam.fromInt(color)
val lstar = 100f * (shade + lightnessFloat)

return ColorUtils.HSLToColor(hsl)
return Cam.getInt(cam.hue, cam.chroma, lstar)
}

fun modifyBrightness(color: Int, brightnessPercentage: Int): Int {
Expand Down

0 comments on commit 93c7882

Please sign in to comment.