Skip to content

Commit

Permalink
fix: code cleanup. prevent further execution if bitmap is null
Browse files Browse the repository at this point in the history
  • Loading branch information
jahirfiquitiva committed Jan 2, 2025
1 parent b55bb9a commit 6ffe650
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions library/src/main/kotlin/dev/jahir/kuper/data/models/Component.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,19 @@ data class Component(

val width = bitmap.width
val height = bitmap.height
val pixels = IntArray(width * height)
bitmap.getPixels(pixels, 0, width, 0, 0, width, height)

val newBitmap = bitmap.config?.let { Bitmap.createBitmap(width, height, it) }
newBitmap ?: return bitmap

var minX = width
var minY = height
var maxX = -1
var maxY = -1

val newBitmap = bitmap.config?.let { Bitmap.createBitmap(width, height, it) }
var pixel: Int
val pixels = IntArray(width * height)
bitmap.getPixels(pixels, 0, width, 0, 0, width, height)

var pixel: Int
for (y in 0 until height) {
for (x in 0 until width) {
val index = y * width + x
Expand All @@ -120,8 +122,8 @@ data class Component(
}
}

newBitmap?.setPixels(pixels, 0, width, 0, 0, width, height)
return newBitmap?.let { Bitmap.createBitmap(it, minX, minY, maxX - minX + 1, maxY - minY + 1) } ?: bitmap
newBitmap.setPixels(pixels, 0, width, 0, 0, width, height)
return Bitmap.createBitmap(newBitmap, minX, minY, maxX - minX + 1, maxY - minY + 1)
}
}
}

0 comments on commit 6ffe650

Please sign in to comment.