Skip to content

Commit

Permalink
Optimized the recoloring
Browse files Browse the repository at this point in the history
Doesn't differenciate between colors of same RGB but different talpha
  • Loading branch information
MaxBuster380 committed Aug 23, 2023
1 parent a5e5a89 commit c77168a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/main/kotlin/model/applicationfunctions/ColorFilterApplier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ class ColorFilterApplier {
for (y in 0..<imageHeight) {
val currentPixelCoordinates = TwoDVector(x,y)
val inputColor = inputImage.colorOf(currentPixelCoordinates)
//val hashMapKeyColor = copyTransparency(0, inputColor)
if (!computedColors.containsKey(inputColor)) {
val newColor = calculateColor(inputColor, rGBCube)
computedColors[inputColor] = newColor
val hashMapKeyColor = copyTransparency(0, inputColor)
if (!computedColors.containsKey(hashMapKeyColor)) {
val newColor = calculateColor(hashMapKeyColor, rGBCube)
computedColors[hashMapKeyColor] = newColor
}
var outputColor = computedColors[inputColor]!!
var outputColor = computedColors[hashMapKeyColor]!!

outputColor = copyTransparency(inputColor, outputColor)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import model.classes.ThreeDVector

class ColorIntegerConverter {
companion object {
private const val TRANSPARENCY_MASK = 255 shl 24
private const val RGB_MASK = 0.inv() xor TRANSPARENCY_MASK

fun vectorToIntColor(vector : ThreeDVector):Int {
val comps = vector.getAllComp()
var res = 255
Expand All @@ -18,5 +21,17 @@ class ColorIntegerConverter {
val blue = (color and 255)
return ThreeDVector(red, green, blue)
}



/**
* Adds one color's transparency to another.
* @param donorColor Color to take the transparency from.
* @param recipientColor to apply the transparency onto.
* @return The recipient color with the donor color's transparency.
*/
fun copyTransparency(donorColor : Int, recipientColor : Int) : Int {
return (TRANSPARENCY_MASK and donorColor) or (RGB_MASK and recipientColor)
}
}
}

0 comments on commit c77168a

Please sign in to comment.