Skip to content

Commit

Permalink
Adjust brightness by re-setting colors.
Browse files Browse the repository at this point in the history
Fixes #2 by simply just resetting things instead of trying to clone the OG code and being fancy-schmancy.
  • Loading branch information
EAGrahamJr committed May 19, 2024
1 parent 14abafa commit d2fee27
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {
api("com.diozero:diozero-core:$DIOZERO_VER")

// for adhoc testing
testImplementation("com.diozero:diozero-provider-remote:$DIOZERO_VER")
implementation("com.diozero:diozero-provider-remote:$DIOZERO_VER")
testImplementation("com.diozero:diozero-provider-mock:$DIOZERO_VER")

testImplementation("io.kotest:kotest-runner-junit5:5.5.5")
Expand Down
15 changes: 4 additions & 11 deletions src/main/kotlin/crackers/kobots/devices/lighting/PixelBuf.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,10 @@ abstract class PixelBuf(
get() = _brightness
set(b) {
if (b < 0f || b > 1f) throw IllegalArgumentException("'brightness' is out of range (0.0-1.0)")
val delta = b - _brightness
_brightness = b

// adjust brightness of existing values
for (i in 0 until effectiveSize) {
if (dotstarMode && (i + 1) % 4 == 0) continue
val index = i + bufferOffset
val item = pixelBuffer[index].toUByte().toFloat()
val adjusted = (item * delta).roundToInt()
pixelBuffer[index] = (item + adjusted).toInt().toByte()
}
val currentAutoWrite = _autoWrite
_autoWrite = false
currentColors.clone().forEachIndexed { i, c -> set(i, PixelColor(c.color, c.white, b)) }
_autoWrite = currentAutoWrite
if (_autoWrite) show()
}

Expand Down

0 comments on commit d2fee27

Please sign in to comment.